Переглянути джерело

ComPDFKit.Tool(win) - 修复多边形外边框绘制位置不对的问题

TangJinZhou 2 тижнів тому
батько
коміт
c40cacde4f

+ 1 - 8
Demo/Examples/ComPDFKit.Tool/CPDFToolManager.cs

@@ -832,14 +832,7 @@ namespace ComPDFKit.Tool
             annotHistory.CurrentParam = currentParam;
             annotHistory.Action = HistoryAction.Update;
             viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
-            if (e.annotData.Annot.IsMeasured())
-            {
-                viewerTool.GetCPDFViewer().UpdateRenderFrame();
-            }
-            else
-            {
-                viewerTool.GetCPDFViewer().UpdateAnnotFrame();
-            }
+            viewerTool.GetCPDFViewer().UpdateAnnotFrame();
         }
 
         private void ViewerTool_MouseLeftButtonUpHandler(object sender, MouseEventObject e)

+ 1 - 2
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.AnnotEdit.cs

@@ -74,8 +74,8 @@ namespace ComPDFKit.Tool
             AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
             if (annotEdit != null)
             {
-                annotEdit.Draw();
                 annotEdit.OnMouseLeftButtonUp(point);
+                annotEdit.Draw();
             }
         }
 
@@ -108,7 +108,6 @@ namespace ComPDFKit.Tool
         private bool DrawEditAnnotDownEvent()
         {
             BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
-
             AnnotEdit selectedRect = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
             if (selectedRect != null)
             {

+ 33 - 30
Demo/Examples/ComPDFKit.Tool/DrawTool/AnnotEdit.cs

@@ -4,18 +4,13 @@ using ComPDFKit.PDFAnnotation;
 using ComPDFKit.Tool.SettingParam;
 using ComPDFKit.Viewer.Helper;
 using ComPDFKitViewer;
-using ComPDFKitViewer.Annot;
 using ComPDFKitViewer.Helper;
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Linq;
-using System.Net;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
-using System.Windows.Media.TextFormatting;
-using static ComPDFKit.Tool.Help.ImportWin32;
 
 namespace ComPDFKit.Tool.DrawTool
 {
@@ -188,17 +183,17 @@ namespace ComPDFKit.Tool.DrawTool
                 case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
                     break;
                 case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
-                    for (int i = 0; i < (annotData.Annot as CPDFPolygonAnnotation).Points.Count; i++)
-                    {
-                        Point point = DpiHelper.PDFPointToStandardPoint(new Point((annotData.Annot as CPDFPolygonAnnotation).Points[i].x, (annotData.Annot as CPDFPolygonAnnotation).Points[i].y));
-                        point = new Point(
-                            point.X * annotData.CurrentZoom + annotData.PaintOffset.X - annotData.CropLeft * annotData.CurrentZoom,
-                            point.Y * annotData.CurrentZoom + annotData.PaintOffset.Y - annotData.CropTop * annotData.CurrentZoom
-                            );
-                        activePoints.Add(point);
-                    }
-                    if ((annotData.Annot as CPDFPolygonAnnotation).IsMeasured())
                     {
+                        for (int i = 0; i < (annotData.Annot as CPDFPolygonAnnotation).Points.Count; i++)
+                        {
+                            Point point = DpiHelper.PDFPointToStandardPoint(new Point((annotData.Annot as CPDFPolygonAnnotation).Points[i].x, (annotData.Annot as CPDFPolygonAnnotation).Points[i].y));
+                            point = new Point(
+                                point.X * annotData.CurrentZoom + annotData.PaintOffset.X - annotData.CropLeft * annotData.CurrentZoom,
+                                point.Y * annotData.CurrentZoom + annotData.PaintOffset.Y - annotData.CropTop * annotData.CurrentZoom
+                                );
+                            activePoints.Add(point);
+                        }
+
                         CRect rawRect = annotData.Annot.GetRect();
                         Rect rect = DataConversionForWPF.CRectConversionForRect(rawRect);
                         rect = DpiHelper.PDFRectToStandardRect(rect);
@@ -210,18 +205,19 @@ namespace ComPDFKit.Tool.DrawTool
                             );
                     }
                     break;
+
                 case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
-                    for (int i = 0; i < (annotData.Annot as CPDFPolylineAnnotation).Points.Count; i++)
-                    {
-                        Point point = DpiHelper.PDFPointToStandardPoint(new Point((annotData.Annot as CPDFPolylineAnnotation).Points[i].x, (annotData.Annot as CPDFPolylineAnnotation).Points[i].y));
-                        point = new Point(
-                            point.X * annotData.CurrentZoom + annotData.PaintOffset.X - annotData.CropLeft * annotData.CurrentZoom,
-                            point.Y * annotData.CurrentZoom + annotData.PaintOffset.Y - annotData.CropTop * annotData.CurrentZoom
-                            );
-                        activePoints.Add(point);
-                    }
-                    if ((annotData.Annot as CPDFPolylineAnnotation).IsMeasured())
                     {
+                        for (int i = 0; i < (annotData.Annot as CPDFPolylineAnnotation).Points.Count; i++)
+                        {
+                            Point point = DpiHelper.PDFPointToStandardPoint(new Point((annotData.Annot as CPDFPolylineAnnotation).Points[i].x, (annotData.Annot as CPDFPolylineAnnotation).Points[i].y));
+                            point = new Point(
+                                point.X * annotData.CurrentZoom + annotData.PaintOffset.X - annotData.CropLeft * annotData.CurrentZoom,
+                                point.Y * annotData.CurrentZoom + annotData.PaintOffset.Y - annotData.CropTop * annotData.CurrentZoom
+                                );
+                            activePoints.Add(point);
+                        }
+
                         CRect rawRect = annotData.Annot.GetRect();
                         Rect rect = DataConversionForWPF.CRectConversionForRect(rawRect);
                         rect = DpiHelper.PDFRectToStandardRect(rect);
@@ -233,6 +229,7 @@ namespace ComPDFKit.Tool.DrawTool
                             );
                     }
                     break;
+
                 case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
                     break;
                 case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
@@ -362,7 +359,6 @@ namespace ComPDFKit.Tool.DrawTool
             {
                 Tag = isMouseDown;
                 mouseEndDrawPoint = mousePoint;
-
                 Point newOffset = new Point(
                     mouseEndDrawPoint.X - mouseDownPoint.X,
                     mouseEndDrawPoint.Y - mouseDownPoint.Y
@@ -385,26 +381,30 @@ namespace ComPDFKit.Tool.DrawTool
 
         public virtual void OnMouseLeftButtonUp(Point upPoint)
         {
+            if (annotData == null)
+                return;
+
             isMouseDown = false;
-            Draw();
-            if (annotData!=null&&annotData.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
+            if (annotData.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
             {
                 if ((annotData.Annot as CPDFLineAnnotation).IsMeasured())
                 {
                     activePoints.Clear();
-
                     if (moveLeftLine == null)
                     {
                         moveLeftLine = leftLine.ToArray();
                     }
+
                     if (moveRightLine == null)
                     {
                         moveRightLine = rightLine.ToArray();
                     }
+
                     if (moveCrossLine == null)
                     {
                         moveCrossLine = crossLine.ToArray();
                     }
+
                     activePoints.Add(moveLeftLine[0]);
                     activePoints.Add(moveLeftLine[1]);
                     activePoints.Add(moveRightLine[0]);
@@ -413,6 +413,7 @@ namespace ComPDFKit.Tool.DrawTool
                     activePoints.Add(moveCrossLine[1]);
                 }
             }
+   
             moveLeftLine = null;
             moveRightLine = null;
             moveCrossLine = null;
@@ -420,11 +421,13 @@ namespace ComPDFKit.Tool.DrawTool
             {
                 InvokeDataChangEvent(true);
             }
+
             moveOffset = new Point(0, 0);
             mouseDownPoint = new Point();
-
             mouseEndDrawPoint = new Point();
             hitIndex = -1;
+
+            SetAnnotObject(annotData);
         }
 
         /// <summary>