Browse Source

compdfkit(win) - 内容编辑部分代码整理

liuaoran 11 months ago
parent
commit
9a4ea5d4a0

+ 0 - 2
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -164,8 +164,6 @@ namespace Compdfkit_Tools.PDFControl
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
         {
-            //PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
-            //PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
             PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
         }
 

File diff suppressed because it is too large
+ 395 - 635
Demo/Examples/Compdfkit_Tools/Edit/ContentEditCOntrol/ContentEditControl.xaml.cs


+ 76 - 64
Demo/Examples/Compdfkit_Tools/Edit/PDFImageEdit/PDFImageEditControl/PDFImageEditControl.xaml.cs

@@ -27,9 +27,12 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class PDFImageEditControl : UserControl
     {
+        #region property
         public CPDFViewerTool ToolView { get; set; }
         public ImageEditParam EditEvent { get; set; }
+
         //public List<PDFEditEvent> EditMultiEvents { get; set; }
+        #endregion 
 
         public PDFImageEditControl()
         {
@@ -38,6 +41,8 @@ namespace Compdfkit_Tools.Edit
             Unloaded += PDFImageEditControl_Unloaded;
         }
 
+        #region Load unload custom control
+
         private void PDFImageEditControl_Loaded(object sender, RoutedEventArgs e)
         {
             RotateUI.RotationChanged -= RotateUI_RotationChanged;
@@ -48,6 +53,15 @@ namespace Compdfkit_Tools.Edit
             ToolView.SelectedDataChanged += ToolView_SelectedDataChanged;
         }
 
+        private void PDFImageEditControl_Unloaded(object sender, RoutedEventArgs e)
+        {
+            RotateUI.RotationChanged -= RotateUI_RotationChanged;
+            FlipUI.FlipChanged -= FlipUI_FlipChanged;
+        } 
+
+        #endregion
+
+        #region Property changed
         private void ToolView_SelectedDataChanged(object sender, SelectedAnnotData e)
         {
             if (ToolView.GetIsCropMode())
@@ -65,7 +79,7 @@ namespace Compdfkit_Tools.Edit
                     pdfRect = DpiHelper.StandardRectToPDFRect(pdfRect);
                     CRect newCRect = new CRect((float)pdfRect.Left, (float)pdfRect.Bottom, (float)pdfRect.Right, (float)pdfRect.Top);
                     imageArea.CutWithRect(newCRect);
-                    
+
                     SetImageThumb();
                     ToolView.UpdateRender(oldRect, imageArea);
                     editPage.EndEdit();
@@ -73,21 +87,61 @@ namespace Compdfkit_Tools.Edit
             }
         }
 
-        private void PDFImageEditControl_Unloaded(object sender, RoutedEventArgs e)
+
+        #endregion
+
+        #region Init PDFViewer
+        public void InitWithPDFViewer(CPDFViewerTool newPDFView)
         {
-            RotateUI.RotationChanged -= RotateUI_RotationChanged;
-            FlipUI.FlipChanged -= FlipUI_FlipChanged;
+            ToolView = newPDFView;
         }
+        #endregion
 
+        #region public method
 
         public void SetRotationText(float rotation)
         {
             RotationTxb.Text = rotation.ToString(CultureInfo.CurrentCulture);
         }
 
-        public void InitWithPDFViewer(CPDFViewerTool newPDFView)
+        #endregion
+
+        #region Image Edit
+
+        public void SetImageThumb()
         {
-            ToolView = newPDFView;
+            if (EditEvent != null)
+            {
+                try
+                {
+                    GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+
+                    string path = Path.GetTempPath();
+                    string uuid = Guid.NewGuid().ToString("N");
+                    string imagePath = Path.Combine(path, uuid + ".tmp");
+                    imageArea.ExtractImage(imagePath);
+
+                    Bitmap bitmapImage = new Bitmap(imagePath);
+                    MemoryStream memoryStream = new MemoryStream();
+
+                    bitmapImage.Save(memoryStream, bitmapImage.RawFormat);
+                    BitmapImage imageShow = new BitmapImage();
+                    imageShow.BeginInit();
+                    imageShow.StreamSource = memoryStream;
+                    imageShow.EndInit();
+                    ImageThumbUI.Source = imageShow;
+                }
+                catch (Exception ex)
+                {
+
+                }
+            }
+        }
+
+        public void SetImageTransparency(double transparency)
+        {
+            ImasgeOpacitySlider.Value = transparency / 255D;
+            OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Round(ImasgeOpacitySlider.Value * 100)));
         }
 
         public void SetPDFImageEditData(ImageEditParam newEvent)
@@ -104,15 +158,18 @@ namespace Compdfkit_Tools.Edit
             {
                 SetImageTransparency(newEvent.Transparency);
             }
-            
-            if(RotationTxb!=null && newEvent!=null && newEvent.EditType == CPDFEditType.EditImage)
+
+            if (RotationTxb != null && newEvent != null && newEvent.EditType == CPDFEditType.EditImage)
             {
-                //RotationTxb.Text = newEvent.CurrentRotated.ToString(CultureInfo.CurrentCulture);
+                GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+                RotationTxb.Text = imageArea.GetRotation().ToString();
+                //RotationTxb.Text = newEvent.Rotate.ToString(CultureInfo.CurrentCulture);
             }
-            
+
             EditEvent = newEvent;
             SetImageThumb();
         }
+        #endregion
 
         //public void SetPDFImageMultiEditData(List<PDFEditEvent> editEvents)
         //{
@@ -139,7 +196,7 @@ namespace Compdfkit_Tools.Edit
         //        ImageThumbUI.Source = null;
         //    }
 
-           
+
         //    if (editEvents != null && editEvents.Count > 0)
         //    {
         //        PDFEditEvent editEvent = editEvents[0];
@@ -152,6 +209,8 @@ namespace Compdfkit_Tools.Edit
         //    EditMultiEvents = editEvents;
         //}
 
+        #region Property changed
+
         private void FlipUI_FlipChanged(object sender, bool e)
         {
             GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
@@ -275,7 +334,7 @@ namespace Compdfkit_Tools.Edit
             //{
             //    foreach (PDFEditEvent editEvent in EditMultiEvents)
             //    {
-            //        editEvent.Transparency = (int)(ImasgeOpacitySlider.Value * 255);
+            //        editEvent.Transparency = (int)(ImageOpacitySlider.Value * 255);
             //    }
             //    PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
             //}
@@ -333,7 +392,7 @@ namespace Compdfkit_Tools.Edit
                         int imageWidth = 0;
                         int imageHeight = 0;
                         byte[] imageData = null;
-                        PDFHelp.ImagePathToByte(openFileDialog.FileName,ref imageData,ref imageWidth,ref imageHeight);
+                        PDFHelp.ImagePathToByte(openFileDialog.FileName, ref imageData, ref imageWidth, ref imageHeight);
 
                         if (imageData != null && imageWidth > 0 && imageHeight > 0)
                         {
@@ -363,7 +422,6 @@ namespace Compdfkit_Tools.Edit
         {
             if (ToolView != null)
             {
-                //需要选中图片对象
                 // Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
                 Dictionary<int, List<Bitmap>> imageDict = new Dictionary<int, List<Bitmap>>();
                 if (imageDict != null && imageDict.Count > 0)
@@ -398,16 +456,6 @@ namespace Compdfkit_Tools.Edit
 
         private void ImageClipBtn_Click(object sender, RoutedEventArgs e)
         {
-            //if(EditMultiEvents!=null && EditMultiEvents.Count>1)
-            //{
-            //    return;
-            //}
-
-            //if (EditEvent != null)
-            //{
-            //    EditEvent.ClipImage = true;
-            //    EditEvent.UpdatePDFEditByEventArgs();
-            //}
             ToolView.SetCropMode(!ToolView.GetIsCropMode());
         }
 
@@ -424,42 +472,6 @@ namespace Compdfkit_Tools.Edit
             }
         }
 
-        public void SetImageThumb()
-        {
-            if (EditEvent != null)
-            {
-                try
-                {
-                    GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
-
-                    string path = Path.GetTempPath();
-                    string uuid = Guid.NewGuid().ToString("N");
-                    string imagePath = Path.Combine(path, uuid + ".tmp");
-                    imageArea.ExtractImage(imagePath);
-
-                    Bitmap bitmapImage = new Bitmap(imagePath);
-                    MemoryStream memoryStream = new MemoryStream();
-
-                    bitmapImage.Save(memoryStream, bitmapImage.RawFormat);
-                    BitmapImage imageShow = new BitmapImage();
-                    imageShow.BeginInit();
-                    imageShow.StreamSource = memoryStream;
-                    imageShow.EndInit();
-                    ImageThumbUI.Source = imageShow;
-                }
-                catch (Exception ex)
-                {
-
-                }
-            }
-        }
-
-        public void SetImageTransparency(double transparency)
-        {
-            ImasgeOpacitySlider.Value = transparency / 255D;
-            OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Round(ImasgeOpacitySlider.Value * 100)));
-        }
-
         private void GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage)
         {
             imageArea = null;
@@ -487,7 +499,7 @@ namespace Compdfkit_Tools.Edit
 
             }
         }
-        
+
         private void SetAbsRotation(double absRotation)
         {
             GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
@@ -511,10 +523,10 @@ namespace Compdfkit_Tools.Edit
                 }
             }
         }
-        
+
         private void RotationTxb_LostFocus(object sender, RoutedEventArgs e)
         {
-            if(!double.TryParse(RotationTxb.Text, out double rotation))
+            if (!double.TryParse(RotationTxb.Text, out double rotation))
             {
                 return;
             }
@@ -528,6 +540,6 @@ namespace Compdfkit_Tools.Edit
                 RotationTxb_LostFocus(null, null);
             }
         }
-
+        #endregion 
     }
 }

+ 4 - 0
Demo/Examples/Compdfkit_Tools/Edit/PDFImageEdit/PDFImageUI/CPDFImageFlipUI.xaml.cs

@@ -12,6 +12,7 @@ namespace Compdfkit_Tools.Edit
             InitializeComponent();
         }
 
+        #region Property
         public Orientation Orientation
         {
             get
@@ -23,7 +24,9 @@ namespace Compdfkit_Tools.Edit
                 ImageFlipUI.Orientation = value;
             }
         }
+        #endregion
 
+        #region UI Event
         private void FlipVertical_Click(object sender, RoutedEventArgs e)
         {
             FlipChanged?.Invoke(this, true);
@@ -33,5 +36,6 @@ namespace Compdfkit_Tools.Edit
         {
             FlipChanged?.Invoke(this, false);
         }
+        #endregion 
     }
 }

+ 7 - 0
Demo/Examples/Compdfkit_Tools/Edit/PDFImageEdit/PDFImageUI/CPDFImageRotateUI.xaml.cs

@@ -6,6 +6,7 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class CPDFImageRotateUI : UserControl
     {
+        #region 
         public event EventHandler<double> RotationChanged;
         public CPDFImageRotateUI()
         {
@@ -24,6 +25,10 @@ namespace Compdfkit_Tools.Edit
             }
         }
 
+        #endregion
+
+        #region 
+
         private void RotateLeftBtn_Click(object sender, RoutedEventArgs e)
         {
             RotationChanged?.Invoke(this, -90);
@@ -33,5 +38,7 @@ namespace Compdfkit_Tools.Edit
         {
             RotationChanged?.Invoke(this, 90);
         }
+
+        #endregion 
     }
 }

+ 19 - 1
Demo/Examples/Compdfkit_Tools/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -17,20 +17,28 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class PDFTextEditControl : UserControl
     {
+        #region Property
         public CPDFViewerTool ToolView { get; private set; }
         public TextEditParam EditEvent { get; set; }
+
         //public List<PDFEditEvent> EditMultiEvents { get; set; }
+
+        #endregion 
+
         public PDFTextEditControl()
         {
             InitializeComponent();
             Loaded += PDFTextEditControl_Loaded;
         }
 
+        #region Init PDFView
         public void InitWithPDFViewer(CPDFViewerTool newPDFView)
         {
             ToolView = newPDFView;
         }
+        #endregion
 
+        #region UI
         public void SetPDFTextEditData(TextEditParam newEvent)
         {
             if (newEvent.EditIndex<0)
@@ -276,6 +284,9 @@ namespace Compdfkit_Tools.Edit
             //}
         }
 
+        #endregion
+
+        #region Loaded
         private void PDFTextEditControl_Loaded(object sender, RoutedEventArgs e)
         {
 
@@ -294,6 +305,10 @@ namespace Compdfkit_Tools.Edit
             FontColorUI.ColorChanged += FontColorUI_ColorChanged;
         }
 
+        #endregion
+
+        #region Property changed
+
         private void TextStyleUI_TextSizeChanged(object sender, double e)
         {
             GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
@@ -529,6 +544,9 @@ namespace Compdfkit_Tools.Edit
             }
         }
 
+        #endregion
+
+        #region Text Edit
         private void GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage)
         {
             textArea = null;
@@ -567,6 +585,6 @@ namespace Compdfkit_Tools.Edit
                 editPage.EndEdit();
             }
         }
-
+        #endregion
     }
 }

+ 11 - 2
Demo/Examples/Compdfkit_Tools/Edit/PDFTextEdit/PDFTextEditUI/CPDFTextAlignUI.xaml.cs

@@ -9,13 +9,20 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class CPDFTextAlignUI : UserControl
     {
+        #region Property
+
         public event EventHandler<TextAlignType> TextAlignChanged;
+
+        public TextAlignType Alignment { get; private set; }
+
+        #endregion
+
         public CPDFTextAlignUI()
         {
             InitializeComponent();
         }
 
-        public TextAlignType Alignment { get;private set; }
+        #region Property changed
 
         public void SetFontAlign(TextAlignType newAlign)
         {
@@ -82,5 +89,7 @@ namespace Compdfkit_Tools.Edit
                 }
             }
         }
+        
+        #endregion
     }
-}
+}

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

@@ -7,15 +7,21 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class CPDFTextStyleUI : UserControl
     {
+        #region 
+        
         public event EventHandler<string> TextFontChanged;
         public event EventHandler<bool> TextBoldChanged;
         public event EventHandler<bool> TextItalicChanged;
         public event EventHandler<double> TextSizeChanged;
+
+        #endregion 
+
         public CPDFTextStyleUI()
         {
             InitializeComponent();
         }
 
+        #region  Set font name
         public void SetFontNames(List<string> fontNames)
         {
             FontNameComboBox.ItemsSource = null;
@@ -101,6 +107,9 @@ namespace Compdfkit_Tools.Edit
                 }
             }
         }
+        #endregion
+
+        #region Property changed
 
         private void FontNameComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
@@ -155,5 +164,7 @@ namespace Compdfkit_Tools.Edit
                 }
             }
         }
+        
+        #endregion 
     }
 }

+ 1 - 5
Demo/Examples/Compdfkit_Tools/PDFView/PDFDisplaySettings/PDFDisplaySettingsControl/CPDFDisplaySettingsControl.xaml.cs

@@ -70,8 +70,6 @@ namespace Compdfkit_Tools.PDFControl
                 if(pdfViewer != null)
                 {
                     ViewModeUI.SetViewModeUI(pdfViewer.GetViewMode());
-                    // ViewModeUI.SetSplitModeUI(ViewControl.Mode);
-                    //ViewModeUI.SetCropUI(ViewControl.IsCropMode());
                 }
             }
             ViewModeUI.ViewModeChanged -= ViewModeUI_ViewModeChanged;
@@ -92,9 +90,7 @@ namespace Compdfkit_Tools.PDFControl
                 CPDFViewer pdfViewer = ViewControl.FocusPDFViewTool.GetCPDFViewer();
                 if (pdfViewer != null)
                 {
-                    ViewModeUI.SetViewModeUI(pdfViewer.GetViewMode());
-                    // ViewModeUI.SetSplitModeUI(ViewControl.Mode);
-                    //ViewModeUI.SetCropUI(ViewControl.IsCropMode());
+                    ViewModeUI.SetViewModeUI(pdfViewer.GetViewMode()); 
                 }
             }
         }

+ 1 - 2
Demo/Examples/Compdfkit_Tools/Watermark/AddWatermark/WatermarkDialog.xaml.cs

@@ -341,8 +341,7 @@ namespace Compdfkit_Tools.PDFControl
             weakReference = new WeakReference(this);
 
             FontFamilyCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys;
-            FontFamilyCmb.SelectedIndex = 0;
-
+            FontFamilyCmb.SelectedIndex = 0; 
         }
 
         private void InitWatermarkData(ref WatermarkData watermarkData)