Преглед изворни кода

ComPDFKit.Demo(win) - 修复多边形注释Undo问题

TangJinZhou пре 2 недеља
родитељ
комит
ada11a7f06

+ 54 - 42
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCloudUI.xaml.cs

@@ -2,11 +2,9 @@
 using ComPDFKit.Controls.Data;
 using ComPDFKit.Controls.PDFControl;
 using ComPDFKit.PDFAnnotation;
-using ComPDFKit.PDFDocument;
 using ComPDFKit.Tool;
 using ComPDFKit.Tool.Help;
 using ComPDFKit.Tool.UndoManger;
-using ComPDFKitViewer.Annot;
 using ComPDFKitViewer.Helper;
 using System;
 using System.Collections.Generic;
@@ -28,16 +26,6 @@ namespace ComPDFKit.Controls.PDFControlUI
         private PDFViewControl viewControl;
         public event EventHandler<CPDFAnnotationData> PropertyChanged;
 
-        private AnnotHistory GetHistory()
-        {
-            if (annotCore != null && annotCore.IsValid())
-            {
-                return new PolygonAnnotHistory();
-            }
-            return new AnnotHistory();
-        }
-
-
         public CPDFCloudUI()
         {
             InitializeComponent();
@@ -89,7 +77,7 @@ namespace ComPDFKit.Controls.PDFControlUI
 
                     if (viewControl != null && viewControl.PDFViewTool != null)
                     {
-                        AnnotHistory history = GetHistory();
+                        PolygonMeasureAnnotHistory history = new PolygonMeasureAnnotHistory();
                         history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
                         history.Action = HistoryAction.Update;
                         CPDFPolygonAnnotation polygonAnnotation = annotCore as CPDFPolygonAnnotation;
@@ -97,9 +85,10 @@ namespace ComPDFKit.Controls.PDFControlUI
                         history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
                         polygonAnnotation.SetBorderStyle(borderStyle, dashArray);
                         history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+
                         annotCore.UpdateAp();
                         viewControl.UpdateAnnotFrame();
-                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }
@@ -113,9 +102,16 @@ namespace ComPDFKit.Controls.PDFControlUI
             }
             if (IsLoadedData)
             {
-                if (annotCore != null && annotCore.IsValid())
+                if (annotCore != null && annotCore.IsValid() && annotCore is CPDFPolygonAnnotation polygonAnnotation)
                 {
-                    (annotCore as CPDFPolygonAnnotation).SetAnnotBorderEffector(e);
+                    PolygonMeasureAnnotHistory history = new PolygonMeasureAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+                    polygonAnnotation.SetAnnotBorderEffector(e);
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+
                     annotCore.UpdateAp();
                     viewControl.UpdateAnnotFrame();
                 }
@@ -130,16 +126,18 @@ namespace ComPDFKit.Controls.PDFControlUI
             }
             if (IsLoadedData)
             {
-                if (annotCore != null && annotCore.IsValid())
+                if (annotCore != null && annotCore.IsValid() && annotCore is CPDFPolygonAnnotation polygonAnnotation)
                 {
-                    double thickness = (sender as CPDFThicknessControl).Thickness;
+                    PolygonMeasureAnnotHistory history = new PolygonMeasureAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
+                    polygonAnnotation.SetLineWidth((sender as CPDFThicknessControl).Thickness);
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
 
-                    if (Math.Abs(thickness - annotCore.GetTransparency()) > 1)
-                    {
-                        annotCore.SetBorderWidth((byte)thickness);
-                        annotCore.UpdateAp();
-                        viewControl.UpdateAnnotFrame();
-                    }
+                    annotCore.UpdateAp();
+                    viewControl.UpdateAnnotFrame();
                 }
             }
         }
@@ -159,12 +157,17 @@ namespace ComPDFKit.Controls.PDFControlUI
                     {
                         opacity *= 255;
                     }
-                    if (Math.Abs(opacity - annotCore.GetTransparency()) > 0.01)
-                    {
-                        annotCore.SetTransparency((byte)opacity);
-                        annotCore.UpdateAp();
-                        viewControl.UpdateAnnotFrame();
-                    }
+
+                    PolygonMeasureAnnotHistory history = new PolygonMeasureAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
+                    annotCore.SetTransparency((byte)opacity);
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+
+                    annotCore.UpdateAp();
+                    viewControl.UpdateAnnotFrame();
                 }
             }
         }
@@ -181,25 +184,28 @@ namespace ComPDFKit.Controls.PDFControlUI
                 {
                     if (annotCore is CPDFPolygonAnnotation polygonAnnotation)
                     {
-                        PolygonAnnotHistory history = new PolygonAnnotHistory();
+                        PolygonMeasureAnnotHistory history = new PolygonMeasureAnnotHistory();
                         history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
-                        history.Action = ComPDFKitViewer.Helper.HistoryAction.Update;
-                        SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
 
+                        SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
                         polygonAnnotation.SetBgColor(new byte[3]
                         {
                             brush.Color.R,
                             brush.Color.G,
                             brush.Color.B
                         });
+
                         if(brush.Color.A == 0)
                         {
                             polygonAnnotation.ClearBgColor();
                         }
+
                         history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
 
                         annotCore.UpdateAp();
-                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                         viewControl.UpdateAnnotFrame();
                     }
                 }
@@ -218,9 +224,11 @@ namespace ComPDFKit.Controls.PDFControlUI
                 {
                     if (annotCore is CPDFPolygonAnnotation polygonAnnotation)
                     {
-                        PolygonAnnotHistory history = new PolygonAnnotHistory();
+                        PolygonMeasureAnnotHistory history = new PolygonMeasureAnnotHistory();
                         history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
-                        history.Action = ComPDFKitViewer.Helper.HistoryAction.Update;
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+
                         SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
                         polygonAnnotation.SetLineColor(new byte[3]
                         {
@@ -230,9 +238,8 @@ namespace ComPDFKit.Controls.PDFControlUI
                         });
 
                         history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
-
+                        
                         annotCore.UpdateAp();
-
                         viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                         viewControl.UpdateAnnotFrame();
                     }
@@ -251,10 +258,17 @@ namespace ComPDFKit.Controls.PDFControlUI
             }
 
             Color lineColor = Color.FromRgb(polygonParam.LineColor[0], polygonParam.LineColor[1], polygonParam.LineColor[2]);
-            Color fillColor = Color.FromRgb(polygonParam.FillColor[0], polygonParam.FillColor[1], polygonParam.FillColor[2]);
+            Color fillColor;
+            if (annotation.HasBgColor)
+            {
+                fillColor = Color.FromRgb(polygonParam.FillColor[0], polygonParam.FillColor[1], polygonParam.FillColor[2]);
+            }
+            else
+            {
+                fillColor = Colors.Transparent;
+            }
 
             ctlBorderColorPicker.SetCheckedForColor(lineColor);
-
             ctlFillColorPicker.SetCheckedForColor(fillColor);
 
             double opacity = polygonParam.Transparency / 255.0 * 100.0;
@@ -278,8 +292,6 @@ namespace ComPDFKit.Controls.PDFControlUI
                 ctlLineStyle.DashStyle = new DashStyle(dashArray, 0);
             }
 
-
-
             NoteTextBox.Text = polygonParam.Content;
         }
 

+ 2 - 2
Demo/Examples/Compdfkit.Controls/Properties/AssemblyInfo.cs

@@ -51,5 +51,5 @@ using System.Windows;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.1.0.0")]
-[assembly: AssemblyFileVersion("2.1.0.0")]
+[assembly: AssemblyVersion("2.2.0.0")]
+[assembly: AssemblyFileVersion("2.2.0.0")]