Browse Source

compdfkit demo windows - 文字编辑修改颜色设置;修改透明度转换精度问题

liyuxuan 1 year ago
parent
commit
dd25512290

+ 14 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -127,6 +127,20 @@ namespace compdfkit_tools.Edit
             TextStyleUI.TextBoldChanged += TextStyleUI_TextBoldChanged;
             TextStyleUI.TextItalicChanged += TextStyleUI_TextItalicChanged;
             TextAlignUI.TextAlignChanged += TextAlignUI_TextAlignChanged;
+            FontColorUI.ColorChanged += FontColorUI_ColorChanged;
+        }
+
+        private void FontColorUI_ColorChanged(object sender, EventArgs e)
+        {
+            if (EditEvent != null)
+            {
+                SolidColorBrush newBrush = FontColorUI.Brush as SolidColorBrush;
+                if (newBrush != null)
+                {
+                    EditEvent.FontColor = newBrush.Color;
+                    EditEvent.UpdatePDFEditByEventArgs();
+                }
+            }
         }
 
         private void TextAlignUI_TextAlignChanged(object sender,TextAlignType e)

+ 61 - 6
compdfkit_demo_windows/compdfkit/edit-ctrl-demo/MainWindow.xaml.cs

@@ -32,6 +32,9 @@ namespace edit_ctrl_demo
     /// </summary>
     public partial class MainWindow : Window,INotifyPropertyChanged
     {
+        /// <summary>
+        /// 是否能够撤销
+        /// </summary>
         public bool CanUndo
         {
             get
@@ -44,6 +47,9 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 是否能够重做
+        /// </summary>
         public bool CanRedo
         {
             get
@@ -56,6 +62,9 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 上一次的PDF编辑对象
+        /// </summary>
         private PDFEditEvent lastPDFEditEvent = null;
         public MainWindow()
         {
@@ -64,7 +73,15 @@ namespace edit_ctrl_demo
             DataContext = this;
         }
 
+        /// <summary>
+        /// 属性更改事件
+        /// </summary>
         public event PropertyChangedEventHandler PropertyChanged;
+
+        /// <summary>
+        ///触发属性更改事件通知
+        /// </summary>
+      
         protected void OnPropertyChanged([CallerMemberName] string name = null)
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
@@ -79,6 +96,9 @@ namespace edit_ctrl_demo
             PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
         }
 
+        /// <summary>
+        /// 文字编辑和图片编辑右键点击处理
+        /// </summary>
         private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
         {
             if (e == null)
@@ -99,6 +119,10 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 撤销重做状态更新事件通知
+        /// </summary>
+      
         private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             OnPropertyChanged(e.PropertyName);
@@ -110,16 +134,15 @@ namespace edit_ctrl_demo
         private void PDFView_PDFEditActiveHandler(object sender, PDFEditEvent e)
         {
             PDFEditEvent tempEvent = lastPDFEditEvent;
-            lastPDFEditEvent = null;
+            lastPDFEditEvent = e;
             if (e == null)
             {
                 PDFEditContainer.Child= null;
                 return;
             }
-
-            if(Mouse.RightButton==MouseButtonState.Pressed)
+           
+            if (Mouse.RightButton==MouseButtonState.Pressed)
             {
-                lastPDFEditEvent = e;
                 return;
             }
 
@@ -141,6 +164,9 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 工具栏选择文件对话框事件通知
+        /// </summary>
         private void TitleBarTool_OpenFileEvent(object sender, string filePath)
         {
             ClearPDFEditState();
@@ -150,6 +176,9 @@ namespace edit_ctrl_demo
             PDFView?.SetMouseMode(MouseModes.PanTool);
         }
 
+        /// <summary>
+        /// 加载显示默认文档
+        /// </summary>
         private void LoadDefaultDocument()
         {
             string defaultFilePath = "..\\..\\..\\..\\developer_guide_windows.pdf";
@@ -214,6 +243,9 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 清除编辑相关按钮选中状态
+        /// </summary>
         private void ClearPDFEditState(ToggleButton ignoreBtn=null)
         {
             List<ToggleButton> clearBtnList = new List<ToggleButton>()
@@ -235,16 +267,26 @@ namespace edit_ctrl_demo
             PDFEditContainer.Child = null;
         }
 
+        /// <summary>
+        /// 撤销操作
+        /// </summary>
         private void UndoBtn_Click(object sender, RoutedEventArgs e)
         {
             PDFView?.UndoManager?.Undo();
         }
 
+        /// <summary>
+        /// 重做操作
+        /// </summary>
         private void RedoBtn_Click(object sender, RoutedEventArgs e)
         {
             PDFView?.UndoManager?.Redo();
         }
 
+        /// <summary>
+        /// 文字编辑右键菜单
+        /// </summary>
+       
         private void PDFEditTextContextMenu(object sender,PDFEditCommand editCommand)
         {
             editCommand.PopupMenu = new ContextMenu();
@@ -277,6 +319,9 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 图片编辑右键菜单
+        /// </summary>
         private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
         {
             editCommand.PopupMenu = new ContextMenu();
@@ -410,10 +455,16 @@ namespace edit_ctrl_demo
             }
             else
             {
-                editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "粘贴", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                if(Clipboard.ContainsImage())
+                {
+                    editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "粘贴", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                }
             }
         }
 
+        /// <summary>
+        /// 图片编辑透明度二级菜单
+        /// </summary>
         private void AppendOpacityMenu(MenuItem parentMenu)
         {
             List<int> opacityList = new List<int>()
@@ -429,7 +480,7 @@ namespace edit_ctrl_demo
                 {
                     if(lastPDFEditEvent != null && lastPDFEditEvent.EditType==CPDFEditType.EditImage)
                     {
-                        lastPDFEditEvent.Transparency = (int)(opacity * 255 / 100);
+                        lastPDFEditEvent.Transparency = (int) Math.Ceiling(opacity * 255 / 100D);
                         lastPDFEditEvent.UpdatePDFEditByEventArgs();
                     }
                 };
@@ -437,6 +488,10 @@ namespace edit_ctrl_demo
             }
         }
 
+        /// <summary>
+        /// 进入文字和图片编辑
+        /// </summary>
+      
         private void PDFEditBtn_Click(object sender, RoutedEventArgs e)
         {
             ToggleButton senderBtn = sender as ToggleButton;