소스 검색

compdfkit(windows) - 增加文字编辑操作快捷键

liyuxuan 1 년 전
부모
커밋
6861a01a76

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Edit/PDFTextEdit/PDFTextEditUI/CPDFTextStyleUI.xaml.cs

@@ -76,7 +76,7 @@ namespace Compdfkit_Tools.Edit
 
             if (isBold == false && isItalic)
             {
-                FontStyleBox.SelectedIndex = 0;
+                FontStyleBox.SelectedIndex = 2;
                 return;
             }
 

+ 137 - 7
Demo/Examples/ContentEditor/MainWindow.xaml.cs

@@ -21,6 +21,7 @@ using System.Windows.Controls.Primitives;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
+using Point = System.Windows.Point;
 
 namespace ContentEditor
 {
@@ -87,7 +88,7 @@ namespace ContentEditor
 
         private PDFEditEvent pdfTextCreateParam;
 
-
+        private KeyEventHandler KeyDownHandler;
         #endregion
 
         public MainWindow()
@@ -146,6 +147,12 @@ namespace ContentEditor
             PropertyContainer.Visibility = Visibility.Collapsed;
 
             SetEditMode();
+            if (KeyDownHandler != null)
+            {
+                pdfViewControl.PDFView.RemoveHandler(KeyDownEvent, KeyDownHandler);
+            }
+            KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
+            pdfViewControl.PDFView.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
         }
 
         private void LoadDefaultDocument()
@@ -814,11 +821,6 @@ namespace ContentEditor
                 ClearPDFEditState(senderBtn);
                 if (senderBtn.IsChecked == true)
                 {
-                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
-                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
-                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
-                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
-                    pdfViewControl.PDFView?.ReloadDocument();
                     PDFEditEvent createParam = new PDFEditEvent();
                     createParam.EditType = CPDFEditType.EditText;
                     createParam.IsBold = false;
@@ -828,11 +830,32 @@ namespace ContentEditor
                     createParam.FontColor = Colors.Black;
                     createParam.TextAlign = TextAlignType.AlignLeft;
                     createParam.Transparency = 255;
+
+                    if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
+                    {
+                        CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
+                        if (pdfDoc.PageCount > 0)
+                        {
+                            CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
+                            CPDFEditPage editPage = pdfPage.GetEditPage();
+                            editPage.BeginEdit(CPDFEditType.EditText);
+                            createParam.SystemFontNameList.AddRange(editPage.GetFontList());
+                            editPage.EndEdit();
+                        }
+                    }
+
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
+                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
+                    pdfViewControl.PDFView?.ReloadDocument();
+                   
                     pdfViewControl.PDFView?.SetPDFEditParam(createParam);
                     if (textEditControl == null)
                     {
                         textEditControl = new PDFTextEditControl();
                     }
+                   
                     textEditControl.SetPDFTextEditData(createParam);
                     PropertyContainer.Child = textEditControl;
                     PropertyContainer.Visibility = Visibility.Visible;
@@ -1094,7 +1117,8 @@ namespace ContentEditor
                     pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
                     pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
                     pdfViewControl.PDFView?.ReloadDocument();
-                } 
+
+                }
                 if (ViewComboBox.SelectedIndex == 1)
                 {
                     PDFEditTool.Visibility = Visibility.Visible;
@@ -1113,6 +1137,112 @@ namespace ContentEditor
                 }
             }
         }
+
+        public void PDFView_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (pdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
+            {
+                return;
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.Control)
+            {
+                if (e.Key == Key.Left)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Right)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Up)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Down)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
+                    e.Handled = true;
+                }
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.Shift)
+            {
+                if (e.Key == Key.Left)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Right)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Up)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Down)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, false);
+                    e.Handled = true;
+                }
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.Alt)
+            {
+                if (e.SystemKey == Key.Up)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, false);
+                    e.Handled = true;
+                }
+
+                if (e.SystemKey == Key.Down)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, false);
+                    e.Handled = true;
+                }
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.None)
+            {
+                if (e.Key == Key.Left)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Right)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Up)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Down)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
+                    e.Handled = true;
+                }
+            }
+        }
+
+
         #endregion 
 
         #region Close window

+ 133 - 5
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -29,6 +29,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using Path = System.IO.Path;
+using Point = System.Windows.Point;
 
 namespace PDFViewer
 {
@@ -89,6 +90,8 @@ namespace PDFViewer
         public event EventHandler FileChangeEvent;
         private PDFEditEvent pdfTextCreateParam;
         private PDFTextEditControl textEditControl = new PDFTextEditControl();
+        private KeyEventHandler KeyDownHandler;
+
         #endregion
 
         public MainPage()
@@ -298,11 +301,6 @@ namespace PDFViewer
                 ClearPDFEditState(senderBtn);
                 if (senderBtn.IsChecked == true)
                 {
-                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
-                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
-                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
-                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
-                    pdfViewControl.PDFView?.ReloadDocument();
                     PDFEditEvent createParam = new PDFEditEvent();
                     createParam.EditType = CPDFEditType.EditText;
                     createParam.IsBold = false;
@@ -312,6 +310,26 @@ namespace PDFViewer
                     createParam.FontColor = Colors.Black;
                     createParam.TextAlign = TextAlignType.AlignLeft;
                     createParam.Transparency = 255;
+
+                    if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
+                    {
+                        CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
+                        if (pdfDoc.PageCount > 0)
+                        {
+                            CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
+                            CPDFEditPage editPage = pdfPage.GetEditPage();
+                            editPage.BeginEdit(CPDFEditType.EditText);
+                            createParam.SystemFontNameList.AddRange(editPage.GetFontList());
+                            editPage.EndEdit();
+                        }
+                    }
+
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
+                    pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
+                    pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
+                    pdfViewControl.PDFView?.ReloadDocument();
+                   
                     pdfViewControl.PDFView?.SetPDFEditParam(createParam);
                     if (textEditControl == null)
                     {
@@ -912,6 +930,12 @@ namespace PDFViewer
             PropertyContainer.Visibility = Visibility.Collapsed;
 
             ModeComboBox.SelectedIndex = 0;
+            if (KeyDownHandler != null)
+            {
+                pdfViewControl.PDFView.RemoveHandler(KeyDownEvent, KeyDownHandler);
+            }
+            KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
+            pdfViewControl.PDFView.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
 
         }
 
@@ -1334,6 +1358,110 @@ namespace PDFViewer
         {
             OpenFile();
         }
+
+        public void PDFView_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (pdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
+            {
+                return;
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.Control)
+            {
+                if (e.Key == Key.Left)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Right)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Up)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Down)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
+                    e.Handled = true;
+                }
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.Shift)
+            {
+                if (e.Key == Key.Left)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Right)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Up)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, false);
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Down)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, false);
+                    e.Handled = true;
+                }
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.Alt)
+            {
+                if (e.SystemKey == Key.Up)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, false);
+                    e.Handled = true;
+                }
+
+                if (e.SystemKey == Key.Down)
+                {
+                    pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, false);
+                    e.Handled = true;
+                }
+            }
+
+            if (Keyboard.Modifiers == ModifierKeys.None)
+            {
+                if (e.Key == Key.Left)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Right)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Up)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
+                    e.Handled = true;
+                }
+
+                if (e.Key == Key.Down)
+                {
+                    pdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
+                    e.Handled = true;
+                }
+            }
+        }
         #endregion
 
         #region Change mode

BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/build/x64/ComPDFKit.dll


BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/lib/ComPDFKit.Desk.dll


BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/lib/ComPDFKit.Viewer.dll