Pārlūkot izejas kodu

ComPDFKit(win) - 部分bug修复和测量注释右键菜单

weixiangjie 7 mēneši atpakaļ
vecāks
revīzija
753d9852e6

+ 4 - 8
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -221,16 +221,8 @@ baseWidget.GetAnnotData().Annot);
             ExpandRightPropertyPanel(null, Visibility.Collapsed);
             PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
             PDFAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
-            //PDFViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
-            //PDFViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
             PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
             PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
-            //PDFViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
-            //PDFViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
-
-
-            //PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
-            //PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         }
 
         private void PDFViewControl_MouseRightButtonDownHandler(object sender, ComPDFKit.Tool.MouseEventObject e)
@@ -357,6 +349,10 @@ baseWidget.GetAnnotData().Annot);
 
         public void UnloadEvent()
         {
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
+            PDFAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
+            PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
+            PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
             PDFAnnotationControl.UnLoadPDFViewHandler();
         }
 

+ 1 - 0
Demo/Examples/Compdfkit_Tools/Common/PropertyControl/PDFFont/CPDFFontUI.xaml.cs

@@ -164,6 +164,7 @@ namespace Compdfkit_Tools.Common
                 }
                 FontFamilyComboBox.SelectedIndex = defaultIndex;
                 FontStyleComboBox.SelectedIndex = 0;
+                FamilyName = FontFamilyComboBox.SelectedValue.ToString();
                 isFirstLoad = false;
                 return;
             }

+ 0 - 2
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml

@@ -5,8 +5,6 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
              xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
              xmlns:cpdftools="clr-namespace:Compdfkit_Tools.PDFControl"
-             Loaded="UserControl_Loaded"
-             Unloaded="UserControl_Unloaded"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
     <UserControl.Resources>

+ 11 - 39
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml.cs

@@ -139,6 +139,9 @@ namespace Compdfkit_Tools.PDFControl
             DigitalSignatureBarControl.DigitalSignatureActionChanged -= DigitalSignatureBarControl_DigitalSignatureActionChanged;
             DigitalSignatureBarControl.DigitalSignatureActionChanged += DigitalSignatureBarControl_DigitalSignatureActionChanged;
             
+            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
+            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
+            
             PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler -= PDFViewControl_MouseLeftButtonDownHandler;
             PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler += PDFViewControl_MouseLeftButtonDownHandler;
             
@@ -249,17 +252,6 @@ namespace Compdfkit_Tools.PDFControl
             }
         }
 
-        /// <summary>
-        /// Separately, init PDFView and load undo manager event. Only use for ensuring SaveBtn is enabled after deleting digital signature on Viewer mode.
-        /// </summary>
-        /// <param name="pdfViewer"></param>
-        public void LoadUndoManagerEvent(CPDFViewer pdfViewer)
-        {
-            //PDFViewControl.PDFView = pdfViewer;
-            //PDFViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
-            //PDFViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
-        }
-
         /// <summary>
         /// Set child for BOTAContainer with BOTABarControl.
         /// </summary>
@@ -342,6 +334,14 @@ namespace Compdfkit_Tools.PDFControl
             dialog.ShowDialog();
         }
         
+        public void UnloadEvent()
+        {
+            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
+            PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler -= PDFViewControl_MouseLeftButtonDownHandler;
+            DigitalSignatureBarControl.DigitalSignatureActionChanged -= DigitalSignatureBarControl_DigitalSignatureActionChanged;
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
+        }
+        
         #endregion
 
         #region Private Method
@@ -615,33 +615,5 @@ namespace Compdfkit_Tools.PDFControl
             PDFViewControl.SetRightMenu(ContextMenu);
         }
         #endregion
-
-        #region Load Unload Event
-        
-        /// <summary>
-        /// Load event
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void UserControl_Loaded(object sender, RoutedEventArgs e)
-        {
-            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
-            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
-        }
-         
-        /// <summary>
-        /// Unload event
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
-        {
-            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
-            PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler -= PDFViewControl_MouseLeftButtonDownHandler;
-        }
-        
-        #endregion
-
-        
     }
 }

+ 4 - 1
Demo/Examples/Compdfkit_Tools/Form/FormControl/FormControl.xaml.cs

@@ -364,7 +364,10 @@ namespace Compdfkit_Tools.PDFControl
 
         public void UnloadEvent()
         {
-
+            PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
+            PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
+            PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
         }
 
         public void ClearViewerControl()

+ 173 - 90
Demo/Examples/Compdfkit_Tools/Measure/MeasureControl.xaml.cs

@@ -7,7 +7,10 @@ using ComPDFKitViewer;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Diagnostics;
+using System.Drawing;
 using System.Globalization;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -20,9 +23,11 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using ComPDFKit.PDFPage;
 using ComPDFKit.Tool.Help;
 using ComPDFKit.Viewer.Annot;
 using ComPDFKitViewer.BaseObject;
+using Path = System.IO.Path;
 
 
 namespace Compdfkit_Tools.Measure
@@ -80,22 +85,172 @@ namespace Compdfkit_Tools.Measure
             PDFGrid.Child = PdfViewControl;
 
             panelState.PropertyChanged -= PanelState_PropertyChanged;
-            panelState.PropertyChanged += PanelState_PropertyChanged; 
             PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
             PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
             PdfViewControl.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
+            pdfViewControl.MouseRightButtonDownHandler -= PDFToolManager_MouseRightButtonDownHandler;
 
             PdfViewControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
             PdfViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
             PdfViewControl.MouseMoveHandler += PDFToolManager_MouseMoveHandler;
-            //pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
-            //pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
-            //pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
-            //pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
+            pdfViewControl.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
+            panelState.PropertyChanged += PanelState_PropertyChanged; 
             SetInfoPanelVisble(false, false);
             SettingPanel.PdfViewControl= pdfViewControl;
         }
 
+        private void PDFToolManager_MouseRightButtonDownHandler(object sender, MouseEventObject e)
+        {
+            ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
+            if (ContextMenu == null)
+            {
+                ContextMenu = new ContextMenu();
+            }
+            switch (e.hitTestType)
+            {
+                case MouseHitTestType.Annot:
+                case MouseHitTestType.SelectRect:
+                    CreateAnnotContextMenu(sender, ref ContextMenu, e.annotType);
+                    break;
+                case MouseHitTestType.Text:
+                    CreateSelectTextContextMenu(sender, ref ContextMenu);
+                    break;
+                case MouseHitTestType.ImageSelect:
+                    CreateSelectImageContextMenu(sender, ref ContextMenu);
+                    break;
+                default:
+                    ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                    PdfViewControl.CreateViewerMenu(sender, ref ContextMenu);
+                    break;
+            }
+            PdfViewControl.SetRightMenu(ContextMenu);
+        }
+        
+        private void CreateAnnotContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
+        {
+            switch (annotType)
+            {
+                case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
+                case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
+                case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
+                    CreateMeasureContextMenu(sender, ref menu);
+                    break;
+                case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
+                    break;
+                case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
+                case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
+                case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Play"), Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = (sender as CPDFViewerTool).GetCacheHitTestAnnot() });
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                    break;
+                default:
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                    break;
+            }
+        }
+        
+        private void CreateMeasureContextMenu(object sender, ref ContextMenu menu)
+        {
+            menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+            
+            MenuItem menuItem = new MenuItem();
+            menuItem.Header = "Measurement Settings";
+            menuItem.Click += (item, param) =>
+            {
+                if (currentAnnot is CPDFLineAnnotation annotation)
+                {
+                    SettingPanel.BindMeasureSetting(annotation.GetDistanceMeasure().MeasureInfo);
+                }
+                SetInfoPanelVisble(false, true);
+            };
+            menu.Items.Add(menuItem);
+            
+            MenuItem propertyItem = new MenuItem();
+            propertyItem.Header = "Properties";
+            propertyItem.Click += (item, param) =>
+            {
+                panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
+            };
+            menu.Items.Add(propertyItem);
+        }
+        
+        private void CreateSelectTextContextMenu(object sender, ref ContextMenu menu)
+        {
+            menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+        }
+        
+        private void CreateSelectImageContextMenu(object sender, ref ContextMenu menu)
+        {
+            if (menu == null)
+            {
+                menu = new ContextMenu();
+            }
+            MenuItem copyImage = new MenuItem();
+            copyImage.Header = "Copy Image";
+            copyImage.Click += CopyImage_Click;
+            menu.Items.Add(copyImage);
+
+            MenuItem extractImage = new MenuItem();
+            extractImage.Header = "Extract Image";
+            extractImage.Click += ExtractImage_Click;
+            menu.Items.Add(extractImage);
+        }
+
+        private void ExtractImage_Click(object sender, RoutedEventArgs e)
+        {
+            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
+            if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+            {
+                var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
+                if (image == null)
+                {
+                    return;
+                }
+                CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
+                string savePath = System.IO.Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
+                string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid() + ".jpg");
+                page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
+
+                Bitmap bitmap = new Bitmap(tempPath);
+                bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
+                Process.Start("explorer", "/select,\"" + savePath + "\"");
+            }
+        }
+
+        private void CopyImage_Click(object sender, RoutedEventArgs e)
+        {
+            var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
+            if (image == null)
+            {
+                return;
+            }
+            CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
+            string tempPath = System.IO.Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
+            page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);
+
+            Bitmap bitmap = new Bitmap(tempPath);
+            BitmapImage imageData;
+            using (MemoryStream ms = new MemoryStream())
+            {
+                bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
+                imageData = new BitmapImage();
+                imageData.BeginInit();
+                imageData.StreamSource = ms;
+
+                imageData.CacheOption = BitmapCacheOption.OnLoad;
+                imageData.EndInit();
+                imageData.Freeze();
+                Clipboard.SetImage(imageData);
+                bitmap.Dispose();
+                File.Delete(tempPath);
+            }
+        }
+
         private void PDFToolManager_MouseMoveHandler(object sender, MouseEventObject e)
         {
         }
@@ -123,88 +278,6 @@ namespace Compdfkit_Tools.Measure
             SetInfoPanelVisble(true, false);
         }
 
-        //private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
-        //{
-        //    switch (e.CommandType)
-        //    {
-        //        case CommandType.Context:
-        //            if (e.CommandTarget == TargetType.Annot && e.PressOnAnnot)
-        //            {
-        //                e.Handle = true;
-        //                e.PopupMenu = new ContextMenu();
-        //                e.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
-        //                MenuItem menuItem = new MenuItem();
-        //                menuItem.Header = "Measurement Settings";
-        //                menuItem.Click += (item, param) =>
-        //                {
-        //                    SettingPanel.UpdateArgsList = e.AnnotEventArgsList;
-        //                    SettingPanel.BindMeasureSetting();
-        //                    SetInfoPanelVisble(false, true);
-        //                };
-
-        //                MenuItem propertyItem = new MenuItem();
-        //                propertyItem.Header = "Properties";
-        //                propertyItem.Click += (item, param) =>
-        //                {
-        //                    ExpandEvent?.Invoke(this, new EventArgs());
-        //                };
-        //                e.PopupMenu.Items.Add(menuItem);
-        //                e.PopupMenu.Items.Add(propertyItem);
-        //            }
-        //            break;
-
-        //        case CommandType.Delete:
-        //            e.DoCommand();
-        //            break;
-        //        default:
-        //            break;
-        //    }
-        //}
-
-        //private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
-        //{
-        //    if (e == null || e.IsAnnotCreateReset)
-        //    {
-        //        if (e == null)
-        //        {
-        //            measurePropertyControl?.ClearMeasurePanel();
-        //            if(PDFMeasureTool.ToolChecked()==false)
-        //            {
-        //                SetInfoPanelVisble(false, false);
-        //            }
-        //        }
-        //        return;
-        //    }
-        //    else
-        //    {
-        //        switch (e.GetAnnotTypes())
-        //        {
-        //            case AnnotArgsType.LineMeasure:
-        //                LineMeasureArgs LineArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.LineMeasure).First() as LineMeasureArgs;
-        //                panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
-        //                measurePropertyControl.SetPropertyForMeasureCreate(LineArgs, e);
-        //                SetInfoPanelVisble(true, false);
-        //                SetMeasureInfoPanel(LineArgs.GetPDFAnnot(), LineArgs);
-        //                break;
-        //            case AnnotArgsType.PolygonMeasure:
-        //                PolygonMeasureArgs polygonArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.PolygonMeasure).First() as PolygonMeasureArgs;
-        //                panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
-        //                measurePropertyControl.SetPropertyForMeasureCreate(polygonArgs, e);
-        //                SetInfoPanelVisble(true, false);
-        //                SetMeasureInfoPanel(polygonArgs.GetPDFAnnot(),polygonArgs);
-        //                break;
-
-        //            case AnnotArgsType.PolyLineMeasure:
-        //                PolyLineMeasureArgs polyLineArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.PolyLineMeasure).First() as PolyLineMeasureArgs;
-        //                panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
-        //                measurePropertyControl.SetPropertyForMeasureCreate(polyLineArgs, e);
-        //                SetInfoPanelVisble(true, false);
-        //                SetMeasureInfoPanel(polyLineArgs.GetPDFAnnot(),polyLineArgs);
-        //                break;
-        //        }
-        //    }
-        //}
-
         private void SetMeasureInfoPanel(CPDFAnnotation annot,AnnotParam param = null)
         {
             if (annot == null)
@@ -317,7 +390,14 @@ namespace Compdfkit_Tools.Measure
             BotaContainer.Child = null;
             PropertyContainer.Child = null;
             displaySettingsControl = null;
+        }
+
+        public void UnloadEvent()
+        {
             PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
+            PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
+            PdfViewControl.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
         }
 
         private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -417,9 +497,12 @@ namespace Compdfkit_Tools.Measure
             }
             SettingPanel.ReturnToInfoPanel = true;
             SetInfoPanelVisble(false, true);
-            AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
-                PdfViewControl.GetCPDFViewer().GetDocument(), currentAnnot.Page.PageIndex, currentAnnot);
-            SettingPanel.BindMeasureSetting(GetMeasureInfoFromParam(annotParam));
+            if(currentAnnot != null)
+            {
+                AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
+                    PdfViewControl.GetCPDFViewer().GetDocument(), currentAnnot.Page.PageIndex, currentAnnot);
+                SettingPanel.BindMeasureSetting(GetMeasureInfoFromParam(annotParam));
+            }
         }
 
         private CPDFMeasureInfo GetMeasureInfoFromParam(AnnotParam param)

+ 11 - 199
Demo/Examples/Compdfkit_Tools/Measure/MeasureSettingPanel.xaml.cs

@@ -77,205 +77,6 @@ namespace Compdfkit_Tools.Measure
                     return;
                 }
             }
-
-            //if (UpdateArgsList != null && UpdateArgsList.Count == 0)
-            //{
-            //    SaveMeasureSetting();
-            //}
-
-            //if (UpdateArgsList != null && UpdateArgsList.Count > 0)
-            //{
-            //    List<AnnotArgsType> allowTypeList = new List<AnnotArgsType>()
-            //    {
-            //        AnnotArgsType.LineMeasure,
-            //        AnnotArgsType.PolyLineMeasure,
-            //        AnnotArgsType.PolygonMeasure
-            //    };
-
-            //    foreach (AnnotHandlerEventArgs args in UpdateArgsList)
-            //    {
-            //        if (allowTypeList.Contains(args.EventType))
-            //        {
-            //            CPDFAnnotation pdfAnnot = args.GetPDFAnnot();
-            //            switch (pdfAnnot.Type)
-            //            {
-            //                case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
-            //                    {
-            //                        CPDFLineAnnotation lineAnnot = (CPDFLineAnnotation)pdfAnnot;
-            //                        if (lineAnnot.IsMersured())
-            //                        {
-            //                            CPDFDistanceMeasure lineMeasure = lineAnnot.GetDistanceMeasure();
-            //                            CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
-            //                            if (PrecisionBox.SelectedValue != null)
-            //                            {
-            //                                ComboBoxItem checkItem = PrecisionBox.SelectedValue as ComboBoxItem;
-            //                                if (double.TryParse(checkItem.Content.ToString(), out double precision))
-            //                                {
-            //                                    measureInfo.Precision = GetMeasureSavePrecision(precision);
-            //                                }
-            //                            }
-            //                            if (double.TryParse(RulerBaseText.Text, out double ruleBasedata))
-            //                            {
-            //                                measureInfo.RulerBase = (float)ruleBasedata;
-            //                            }
-            //                            if (RulerBaseUnitCombo.SelectedItem != null)
-            //                            {
-            //                                ComboBoxItem RulerBaseUnitcheckItem = RulerBaseUnitCombo.SelectedItem as ComboBoxItem;
-            //                                measureInfo.RulerBaseUnit = RulerBaseUnitcheckItem.Content.ToString();
-            //                            }
-            //                            if (double.TryParse(RulerTranslateText.Text, out double ruletranBasedata))
-            //                            {
-            //                                measureInfo.RulerTranslate = (float)ruletranBasedata;
-            //                            }
-            //                            if (RulerTranslateCombo.SelectedItem != null)
-            //                            {
-            //                                ComboBoxItem RulerTranslatecheckItem = RulerTranslateCombo.SelectedItem as ComboBoxItem;
-            //                                measureInfo.RulerTranslateUnit = RulerTranslatecheckItem.Content.ToString();
-            //                            }
-            //                            lineMeasure.SetMeasureInfo(measureInfo);
-            //                            lineMeasure.SetMeasureScale(
-            //                                measureInfo.RulerBase,
-            //                                measureInfo.RulerBaseUnit,
-            //                                measureInfo.RulerTranslate,
-            //                                measureInfo.RulerTranslateUnit);
-            //                            lineMeasure.UpdateAnnotMeasure();
-            //                            lineAnnot.UpdateAp();
-            //                            args.Draw();
-            //                            if (PdfViewControl != null && PdfViewControl.PDFView != null)
-            //                            {
-            //                                CPDFViewer viewer = PdfViewControl.PDFView;
-            //                                if (viewer != null && viewer.UndoManager != null)
-            //                                {
-            //                                    viewer.UndoManager.CanSave = true;
-            //                                }
-            //                            }
-            //                        }
-            //                    }
-            //                    break;
-            //                case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
-            //                    {
-            //                        CPDFPolylineAnnotation polylineAnnot = (CPDFPolylineAnnotation)pdfAnnot;
-            //                        if (polylineAnnot.IsMersured())
-            //                        {
-            //                            CPDFPerimeterMeasure polylineMeasure = polylineAnnot.GetPerimeterMeasure();
-            //                            CPDFMeasureInfo measureInfo = polylineMeasure.MeasureInfo;
-            //                            if (PrecisionBox.SelectedValue != null)
-            //                            {
-            //                                ComboBoxItem checkItem = PrecisionBox.SelectedValue as ComboBoxItem;
-            //                                if (double.TryParse(checkItem.Content.ToString(), out double precision))
-            //                                {
-            //                                    measureInfo.Precision = GetMeasureSavePrecision(precision);
-            //                                }
-            //                            }
-            //                            if (double.TryParse(RulerBaseText.Text, out double ruleBasedata))
-            //                            {
-            //                                measureInfo.RulerBase = (float)ruleBasedata;
-            //                            }
-            //                            if (RulerBaseUnitCombo.SelectedItem != null)
-            //                            {
-            //                                ComboBoxItem RulerBaseUnitcheckItem = RulerBaseUnitCombo.SelectedItem as ComboBoxItem;
-            //                                measureInfo.RulerBaseUnit = RulerBaseUnitcheckItem.Content.ToString();
-            //                            }
-            //                            if (double.TryParse(RulerTranslateText.Text, out double ruletranBasedata))
-            //                            {
-            //                                measureInfo.RulerTranslate = (float)ruletranBasedata;
-            //                            }
-            //                            if (RulerTranslateCombo.SelectedItem != null)
-            //                            {
-            //                                ComboBoxItem RulerTranslatecheckItem = RulerTranslateCombo.SelectedItem as ComboBoxItem;
-            //                                measureInfo.RulerTranslateUnit = RulerTranslatecheckItem.Content.ToString();
-            //                            }
-            //                            polylineMeasure.SetMeasureInfo(measureInfo);
-            //                            polylineMeasure.SetMeasureScale(
-            //                                measureInfo.RulerBase,
-            //                                measureInfo.RulerBaseUnit,
-            //                                measureInfo.RulerTranslate,
-            //                                measureInfo.RulerTranslateUnit);
-            //                            polylineMeasure.UpdateAnnotMeasure();
-            //                            polylineAnnot.UpdateAp();
-            //                            args.Draw();
-            //                            if (PdfViewControl != null && PdfViewControl.PDFView != null)
-            //                            {
-            //                                CPDFViewer viewer = PdfViewControl.PDFView;
-            //                                if (viewer != null && viewer.UndoManager != null)
-            //                                {
-            //                                    viewer.UndoManager.CanSave = true;
-            //                                }
-            //                            }
-            //                        }
-            //                    }
-            //                    break;
-            //                case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
-            //                    {
-            //                        CPDFPolygonAnnotation areaAnnot = (CPDFPolygonAnnotation)pdfAnnot;
-            //                        if (areaAnnot.IsMersured())
-            //                        {
-            //                            CPDFAreaMeasure areaMeasure = areaAnnot.GetAreaMeasure();
-            //                            CPDFMeasureInfo measureInfo = areaMeasure.MeasureInfo;
-            //                            if (PrecisionBox.SelectedValue != null)
-            //                            {
-            //                                ComboBoxItem checkItem = PrecisionBox.SelectedValue as ComboBoxItem;
-            //                                if (double.TryParse(checkItem.Content.ToString(), out double precision))
-            //                                {
-            //                                    measureInfo.Precision = GetMeasureSavePrecision(precision);
-            //                                }
-            //                            }
-            //                            if (double.TryParse(RulerBaseText.Text, out double ruleBasedata))
-            //                            {
-            //                                measureInfo.RulerBase = (float)ruleBasedata;
-            //                            }
-            //                            if (RulerBaseUnitCombo.SelectedItem != null)
-            //                            {
-            //                                ComboBoxItem RulerBaseUnitcheckItem = RulerBaseUnitCombo.SelectedItem as ComboBoxItem;
-            //                                measureInfo.RulerBaseUnit = RulerBaseUnitcheckItem.Content.ToString();
-            //                            }
-            //                            if (double.TryParse(RulerTranslateText.Text, out double ruletranBasedata))
-            //                            {
-            //                                measureInfo.RulerTranslate = (float)ruletranBasedata;
-            //                            }
-            //                            if (RulerTranslateCombo.SelectedItem != null)
-            //                            {
-            //                                ComboBoxItem RulerTranslatecheckItem = RulerTranslateCombo.SelectedItem as ComboBoxItem;
-            //                                measureInfo.RulerTranslateUnit = RulerTranslatecheckItem.Content.ToString();
-            //                            }
-
-            //                            measureInfo.CaptionType = CPDFCaptionType.CPDF_CAPTION_NONE;
-            //                            if ((bool)AreaCheckBox.IsChecked)
-            //                            {
-            //                                measureInfo.CaptionType |= CPDFCaptionType.CPDF_CAPTION_AREA;
-            //                            }
-            //                            if ((bool)LengthCheckBox.IsChecked)
-            //                            {
-            //                                measureInfo.CaptionType |= CPDFCaptionType.CPDF_CAPTION_LENGTH;
-            //                            }
-            //                            areaMeasure.SetMeasureInfo(measureInfo);
-            //                            areaMeasure.SetMeasureScale(
-            //                                measureInfo.RulerBase,
-            //                                measureInfo.RulerBaseUnit,
-            //                                measureInfo.RulerTranslate,
-            //                                measureInfo.RulerTranslateUnit);
-            //                            areaMeasure.UpdateAnnotMeasure();
-            //                            areaAnnot.UpdateAp();
-            //                            args.Draw();
-            //                            if(PdfViewControl!=null && PdfViewControl.PDFView!=null)
-            //                            {
-            //                                CPDFViewer viewer = PdfViewControl.PDFView;
-            //                                if(viewer!=null && viewer.UndoManager!=null)
-            //                                {
-            //                                    viewer.UndoManager.CanSave = true;
-            //                                }
-            //                            }
-            //                        }
-            //                    }
-            //                    break;
-            //                default:
-            //                    break;
-            //            }
-            //        }
-            //    }
-            //    ReturnToInfoPanel = false;
-            //}
-            //UpdateArgsList?.Clear();
             DoneEvent?.Invoke(this, e);
             ReturnToInfoPanel = false;
         }
@@ -534,6 +335,17 @@ namespace Compdfkit_Tools.Measure
                     PdfViewControl.UpdateAnnotFrame();
                 }
             }
+            else
+            {
+                MeasureSetting setting = PdfViewControl.PDFViewTool.GetMeasureSetting();
+                setting.RulerBase = measureSetting.RulerBase;
+                setting.RulerBaseUnit = measureSetting.RulerBaseUnit;
+                setting.RulerTranslate = measureSetting.RulerTranslate;
+                setting.RulerTranslateUnit = measureSetting.RulerTranslateUnit;
+                setting.Precision = measureSetting.Precision;
+                setting.IsShowArea = measureSetting.IsShowArea;
+                setting.IsShowLength = measureSetting.IsShowLength;
+            }
         }
         
         private double GetMeasureShowPrecision(int precision)

+ 4 - 199
Demo/Examples/Compdfkit_Tools/PDFView/RegularViewerControl.xaml.cs

@@ -175,44 +175,11 @@ namespace Compdfkit_Tools.PDFView
             DataContext = this;
             if (PdfViewControl != null && PdfViewControl.PDFViewTool.GetCPDFViewer() != null)
             {
-                //PdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
-                //PdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
-                //PdfViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
-                //PdfViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
+                PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
+                PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
             }
         }
-
-        //private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
-        //{
-        //    if ((e is WidgetSignArgs args))
-        //    {
-        //        var signatureWidget = args.Sign;
-        //        if(signatureWidget != null)
-        //        {
-        //            CPDFSignature sig = signatureWidget.GetSignature(PdfViewControl.PDFView.Document);
-        //            if (signatureWidget.IsSigned() && sig!=null && sig?.SignerList.Count > 0)
-        //            {
-        //                return;
-        //            }
-        //        }
-
-        //        if (args.WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
-        //        {
-        //            panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
-        //            CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
-        //            signatureProperty.SetFormProperty(args, PdfViewControl.PDFView);
-        //            PropertyContainer.Child = signatureProperty;
-        //        }
-        //    }
-        //}
-
-        public void CancelWidgetClickHandler()
-        {
-            //if (PdfViewControl != null && PdfViewControl.PDFView != null)
-            //{
-            //    PdfViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
-            //}
-        }
+        
 
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)
         {
@@ -321,178 +288,16 @@ namespace Compdfkit_Tools.PDFView
                 File.Delete(tempPath);
             }
         }
-
-        //private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
-        //{
-        //    if (e != null && e.CommandType == CommandType.Context)
-        //    {
-        //        if (e.PressOnSelectedText)
-        //        {
-        //            e.Handle = true;
-        //            e.PopupMenu = new ContextMenu();
-        //            e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
-        //        }
-        //        else if (e.CommandTarget == TargetType.ImageSelection)
-        //        {
-        //            if (PdfViewControl != null && PdfViewControl.PDFView != null && PdfViewControl.PDFView.GetSelectImageCount() > 0)
-        //            {
-        //                e.Handle = true;
-        //                e.PopupMenu = new ContextMenu();
-
-        //                MenuItem imageCopyMenu = new MenuItem();
-        //                imageCopyMenu = new MenuItem();
-        //                imageCopyMenu.Header = "Copy Images";
-        //                WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
-        //                imageCopyMenu.CommandParameter = e;
-        //                e.PopupMenu.Items.Add(imageCopyMenu);
-
-        //                MenuItem imageExtraMenu = new MenuItem();
-        //                imageExtraMenu = new MenuItem();
-        //                imageExtraMenu.Header = "Extract Images";
-        //                WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
-        //                imageExtraMenu.CommandParameter = e;
-        //                e.PopupMenu.Items.Add(imageExtraMenu);
-        //            }
-        //        }
-        //        else
-        //        {
-        //            e.Handle = true;
-        //            e.PopupMenu = new ContextMenu();
-        //            //if (PdfViewControl.CheckHasForm())
-
-        //            MenuItem fitWidthMenu = new MenuItem();
-        //            fitWidthMenu.Header = "Automatically Resize";
-        //            fitWidthMenu.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    PdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(fitWidthMenu);
-
-        //            MenuItem fitSizeMenu = new MenuItem();
-        //            fitSizeMenu.Header = "Actual Size";
-        //            fitSizeMenu.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    PdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(fitSizeMenu);
-
-        //            MenuItem zoomInMenu = new MenuItem();
-        //            zoomInMenu.Header = "Zoom In";
-        //            zoomInMenu.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,PdfViewControl.PDFView.ZoomFactor + 0.01, true);
-        //                    PdfViewControl.PDFView?.Zoom(newZoom);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(zoomInMenu);
-
-        //            MenuItem zoomOutMenu = new MenuItem();
-        //            zoomOutMenu.Header = "Zoom Out";
-        //            zoomOutMenu.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,PdfViewControl.PDFView.ZoomFactor - 0.01, false);
-        //                    PdfViewControl.PDFView?.Zoom(newZoom);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(zoomOutMenu);
-        //            e.PopupMenu.Items.Add(new Separator());
-
-        //            MenuItem singleView = new MenuItem();
-        //            singleView.Header = "Single Page";
-        //            singleView.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    PdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(singleView);
-
-        //            MenuItem singleContinuousView = new MenuItem();
-        //            singleContinuousView.Header = "Single Page Continuous";
-        //            singleContinuousView.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    PdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(singleContinuousView);
-
-        //            MenuItem doubleView = new MenuItem();
-        //            doubleView.Header = "Two Pages";
-        //            doubleView.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    PdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(doubleView);
-
-        //            MenuItem doubleContinuousView = new MenuItem();
-        //            doubleContinuousView.Header = "Two Pages Continuous";
-        //            doubleContinuousView.Click += (o, p) =>
-        //            {
-        //                if (PdfViewControl != null)
-        //                {
-        //                    PdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
-        //                }
-        //            };
-        //            e.PopupMenu.Items.Add(doubleContinuousView);
-
-        //            {
-        //                MenuItem resetForms = new MenuItem();
-        //                resetForms.Header = "Reset Forms";
-        //                resetForms.Click += (o, p) =>
-        //                {
-        //                    if (PdfViewControl != null)
-        //                    {
-        //                        PdfViewControl.PDFView?.ResetForm(null);
-        //                    }
-        //                };
-        //                e.PopupMenu.Items.Add(new Separator());
-        //                e.PopupMenu.Items.Add(resetForms);
-        //            }
-        //        }
-        //    }
-
-        //    if (e != null && e.CommandType == CommandType.Copy)
-        //    {
-        //        e.DoCommand();
-        //    }
-        //}
-
         #endregion
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
         {
             PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
-            //PdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
-            //PdfViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
         }
 
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
-            PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
-            PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
+            
         }
     }
 }

+ 2 - 1
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -393,7 +393,6 @@ namespace PDFViewer
 
             SignatureHelper.InitEffectiveSignatureList(viewControl.GetCPDFViewer().GetDocument());
             SignatureHelper.VerifySignatureList(viewControl.GetCPDFViewer().GetDocument());
-            digitalSignatureControl.LoadUndoManagerEvent(viewControl.GetCPDFViewer());
             signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
             viewControl.PDFViewTool.SetViewerModel(MouseModes.Viewer);
             
@@ -538,6 +537,7 @@ namespace PDFViewer
                 RightPanelButton.Visibility = Visibility.Visible;
                 digitalSignatureControl.ClearViewerControl();
                 botaBarControl.RemoveBOTAContent(BOTATools.Signature);
+                digitalSignatureControl.UnloadEvent();
             }
             else if (currentMode == "Measurement")
             {
@@ -545,6 +545,7 @@ namespace PDFViewer
                 GetPDFViewControl().PDFViewTool.GetDefaultSettingParam().IsOpenMeasure = false;
                 measureControl.ClearAllToolState();
                 measureControl.ClearViewerControl();
+                measureControl.UnloadEvent();
             }
 
             if (item.Tag as string == "Viewer")