Browse Source

ComPDFKit.Tools/.Demo - 设置是否显示文本块/文本块移出屏幕后输入崩溃判空

liuaoran 7 months ago
parent
commit
495102cd0b

+ 12 - 2
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.TextEdit.cs

@@ -182,6 +182,11 @@ namespace ComPDFKit.Tool
             this.editHoverPen = editHoverPen;
         }
 
+        public Pen GetEditPen()
+        {
+            return editPen;
+        }
+
         /// <summary>
         /// Restore Crop Box
         /// </summary>
@@ -679,7 +684,7 @@ namespace ComPDFKit.Tool
             editArea.TryGetValue(selectedRect, out editAreaObject);
             return editAreaObject;
         }
-
+        
         public EditAreaObject GetEditAreaObjectListForRect(SelectedRect selectedRect)
         {
             if (selectedRect == null)
@@ -1322,7 +1327,7 @@ namespace ComPDFKit.Tool
         /// <param name="content"></param>
         private void DelaySetText(string content)
         {
-            if (content == string.Empty || currentEditAreaObject == null || currentEditAreaObject.cPDFEditPage == null || content == "\u001b")
+            if (content == string.Empty || currentEditAreaObject == null || currentEditAreaObject.cPDFEditPage == null || content == "\u001b" )
             {
                 return;
             }
@@ -1409,6 +1414,11 @@ namespace ComPDFKit.Tool
             paintRect = DpiHelper.StandardRectToPDFRect(zoomPDFPaintRect);
             oldRect.Intersect(paintRect);
 
+            if (oldRect == Rect.Empty)
+            {
+                return;
+            }
+
             keyValuePairs.Add(currentEditAreaObject.PageIndex, oldRect);
             DrawUpdateText(keyValuePairs, currentEditAreaObject.PageBound);
             UpdateSelectRect(newTextArea);

+ 6 - 2
Demo/Examples/Compdfkit.Controls/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml

@@ -94,9 +94,13 @@
                 <local:CPDFTextStyleUI x:Name="TextStyleUI" Grid.Row="3" FontSize="16" Margin="0,20,0,0"></local:CPDFTextStyleUI>
 
                 <local:CPDFTextAlignUI x:Name="TextAlignUI" Grid.Row="4" FontSize="16" Margin="0,20,0,0" Width="150" HorizontalAlignment="Left"></local:CPDFTextAlignUI>
+                <StackPanel Grid.Row="5">
+                    <CheckBox x:Name="chkMulti" IsChecked="{Binding IsMultiSelected}"  Content="Multi Selected" Margin="0,10,0,0" Click="chkMulti_Click"></CheckBox>
 
-                <CheckBox x:Name="chkMulti" IsChecked="{Binding IsMultiSelected}" Grid.Row="5" Content="Multi Selected" Margin="0,10,0,0" Click="chkMulti_Click"></CheckBox>
-            </Grid> 
+                    <CheckBox x:Name="chkEditPen" IsChecked="{Binding ShowBorder}" Content="Show Border" Margin="0,10,0,0" Click="chkEditPen_Click"></CheckBox>
+
+                </StackPanel>
+            </Grid>
         </Grid>
     </ScrollViewer>
 

+ 40 - 10
Demo/Examples/Compdfkit.Controls/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -23,22 +23,31 @@ namespace ComPDFKit.Controls.Edit
         public CPDFViewerTool ToolView { get; private set; }
         public TextEditParam EditEvent { get; set; }
 
-        private bool _isMultiSelected;
 
         public event PropertyChangedEventHandler PropertyChanged;
 
+        private bool _isMultiSelected;
         public bool IsMultiSelected
-        { 
-            get
+        {
+            get => _isMultiSelected;
+            set
             {
-                return _isMultiSelected;
+                if (UpdateProper(ref _isMultiSelected, value))
+                {
+                    ToolView.GetCPDFViewer().UpdateRenderFrame();
+                }
             }
+        }
+
+        private bool _showBorder;
+        public bool ShowBorder
+        {
+            get => _showBorder;
             set
             {
-                UpdateProper(ref _isMultiSelected, value);
+                UpdateProper(ref _showBorder, value); 
             }
         }
-
         #endregion 
 
         public PDFTextEditControl()
@@ -46,6 +55,7 @@ namespace ComPDFKit.Controls.Edit
             DataContext = this;
             InitializeComponent();
             Loaded += PDFTextEditControl_Loaded;
+
         }
 
         #region Init PDFView
@@ -58,7 +68,7 @@ namespace ComPDFKit.Controls.Edit
         #region UI
         public void SetPDFTextEditData(TextEditParam newEvent)
         {
-            if (newEvent.EditIndex<0)
+            if (newEvent.EditIndex < 0)
             {
                 EditEvent = null;
             }
@@ -277,6 +287,7 @@ namespace ComPDFKit.Controls.Edit
             FontColorUI.ColorChanged += FontColorUI_ColorChanged;
 
             IsMultiSelected = ToolView.GetIsMultiSelected();
+            ShowBorder = ToolView.GetEditPen() == null || ToolView.GetEditPen().Thickness != 0;
         }
 
         #endregion
@@ -303,7 +314,7 @@ namespace ComPDFKit.Controls.Edit
                 }
                 else
                 {
-                    result = textArea.SetCharsFontSize((float)e,true);
+                    result = textArea.SetCharsFontSize((float)e, true);
                 }
 
                 if (result)
@@ -361,7 +372,7 @@ namespace ComPDFKit.Controls.Edit
                     result = textArea.SetCharsFontColor(newBrush.Color.R, newBrush.Color.G, newBrush.Color.B);
                 }
 
-                if(result)
+                if (result)
                 {
                     PDFEditHistory editHistory = new PDFEditHistory();
                     editHistory.EditPage = editPage;
@@ -652,12 +663,31 @@ namespace ComPDFKit.Controls.Edit
             }
         }
         #endregion
-           
+
         private void chkMulti_Click(object sender, RoutedEventArgs e)
         {
             ToolView.SetIsMultiSelected((e.Source as CheckBox).IsChecked.GetValueOrDefault());
         }
 
+        private void chkEditPen_Click(object sender, RoutedEventArgs e)
+        {
+            if ((e.Source as CheckBox).IsChecked.GetValueOrDefault())
+            {
+                ToolView.SetEditPen(null);
+            }
+            else
+            {
+                ToolView.SetEditPen(new Pen()
+                {
+                    Brush = new SolidColorBrush(Colors.Black),
+                    Thickness = 0
+                });
+            }
+            ShowBorder = ToolView.GetEditPen() == null || ToolView.GetEditPen().Thickness != 0;
+
+            ToolView.GetCPDFViewer().UpdateRenderFrame();
+        }
+
         protected bool UpdateProper<T>(ref T properValue,
                                T newValue,
                                [CallerMemberName] string properName = "")