Jelajahi Sumber

ComPDFKit.Tool(Win) - 修复测量创建时跨页问题;折线和多边形少于3个点不保存;

liyuxuan 2 bulan lalu
induk
melakukan
51aec26b95

+ 35 - 14
Demo/Examples/ComPDFKit.Tool/CPDFToolManager.cs

@@ -1236,31 +1236,52 @@ namespace ComPDFKit.Tool
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
                         {
-                            if ((annotation as CPDFPolygonAnnotation).IsMeasured())
+                            if (measurepoints.Count >= 3)
                             {
-                                List<CPoint> cPoints = new List<CPoint>();
-                                foreach (Point item in measurepoints)
+                                if ((annotation as CPDFPolygonAnnotation).IsMeasured())
                                 {
-                                    cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
-                                }
+                                    List<CPoint> cPoints = new List<CPoint>();
+                                    foreach (Point item in measurepoints)
+                                    {
+                                        cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
+                                    }
                                 (annotation as CPDFPolygonAnnotation).SetPoints(cPoints);
-                                (annotation as CPDFPolygonAnnotation).GetAreaMeasure().UpdateAnnotMeasure();
-                                PostMeasureInfo(this, annotation);
+                                    (annotation as CPDFPolygonAnnotation).GetAreaMeasure().UpdateAnnotMeasure();
+                                    PostMeasureInfo(this, annotation);
+                                }
+                            }
+                            else
+                            {
+                                annotation.RemoveAnnot();
+                                annotation = null;
+                                viewerTool.ClearDrawAnnot();
+                                return;
                             }
+
                         }
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
                         {
-                            if ((annotation as CPDFPolylineAnnotation).IsMeasured())
+                            if(measurepoints.Count>=3)
                             {
-                                List<CPoint> cPoints = new List<CPoint>();
-                                foreach (Point item in measurepoints)
+                                if ((annotation as CPDFPolylineAnnotation).IsMeasured())
                                 {
-                                    cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
+                                    List<CPoint> cPoints = new List<CPoint>();
+                                    foreach (Point item in measurepoints)
+                                    {
+                                        cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
+                                    }
+                               (annotation as CPDFPolylineAnnotation).SetPoints(cPoints);
+                                    (annotation as CPDFPolylineAnnotation).GetPerimeterMeasure().UpdateAnnotMeasure();
+                                    PostMeasureInfo(this, annotation);
                                 }
-                                (annotation as CPDFPolylineAnnotation).SetPoints(cPoints);
-                                (annotation as CPDFPolylineAnnotation).GetPerimeterMeasure().UpdateAnnotMeasure();
-                                PostMeasureInfo(this, annotation);
+                            }
+                            else
+                            {
+                                annotation.RemoveAnnot();
+                                annotation = null;
+                                viewerTool.ClearDrawAnnot();
+                                return;
                             }
                         }
                         break;

+ 1 - 1
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.Annot.cs

@@ -277,7 +277,7 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
-            (baseLayer as CreateAnnotTool).MultipleClick(point);
+            (baseLayer as CreateAnnotTool).MultipleClick(point, index);
         }
 
         public void SetScrollAndZoomTypeForAnnot(C_ANNOTATION_TYPE annotType)

+ 8 - 2
Demo/Examples/ComPDFKit.Tool/DrawTool/CreateAnnotTool.cs

@@ -88,6 +88,7 @@ namespace ComPDFKit.Tool.DrawTool
         /// The rectangle representing the original page range (calculated offset in continuous mode)
         /// </summary>
         protected Rect pageBound { get; set; }
+        protected int pageIndex { get; set; } = -1;
 
         /// <summary>
         /// The rectangle at standard DPI (without subtracting half of the pen thickness)
@@ -263,6 +264,7 @@ namespace ComPDFKit.Tool.DrawTool
                 drawPoints.Add(downPoint);
                 this.cropPoint = cropPoint;
                 this.pageBound = pageBound;
+                this.pageIndex = cPDFPage.PageIndex;
                 DPIRect = new Rect();
                 if (annotType != C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON)
                 {
@@ -310,6 +312,7 @@ namespace ComPDFKit.Tool.DrawTool
                 mouseEndPoint = new Point();
                 moveOffset = new Point();
                 pageBound = new Rect();
+                pageIndex = -1;
                 DPIRect = new Rect();
                 cPDFAnnotation = null;
                 inkDrawPoints.Clear();
@@ -1444,9 +1447,12 @@ namespace ComPDFKit.Tool.DrawTool
         }
 
         #endregion
-        public void MultipleClick(Point downPoint)
+        public void MultipleClick(Point downPoint,int pageIndex)
         {
-            drawPoints.Add(downPoint);
+            if(pageIndex==this.pageIndex)
+            {
+                drawPoints.Add(downPoint);
+            }
         }
 
         public Rect GetMaxRect()