Browse Source

ComPDFKit(win) - 修复多边形修改出界问题、多边形批注、参数异常问题

liuaoran 16 hours ago
parent
commit
533454458d

+ 8 - 2
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.xaml.cs

@@ -27,6 +27,7 @@ namespace ComPDFKit.Tool
         public MouseEventArgs mouseButtonEventArgs;
         public MouseHitTestType hitTestType;
         public C_ANNOTATION_TYPE annotType;
+
         /// <summary>
         /// Identifies whether the object is created
         /// </summary>
@@ -339,6 +340,7 @@ namespace ComPDFKit.Tool
             {
                 RemovePopTextUI();
             }
+
             Focus();
             Mouse.Capture(this, CaptureMode.SubTree);
             MouseEventObject mouseEventObject = new MouseEventObject
@@ -475,7 +477,7 @@ namespace ComPDFKit.Tool
                 {
                     cacheHitTestAnnot = PDFViewer?.AnnotHitTest() as BaseWidget;
                     SelectedAnnot();
-                    mouseEventObject.hitTestType = MouseHitTestType.Annot;
+                    mouseEventObject.hitTestType = MouseHitTestType.Annot;                              
 
                     mouseEventObject.annotType = cacheMoveWidget.GetAnnotData().AnnotType;
                 }
@@ -610,7 +612,8 @@ namespace ComPDFKit.Tool
         }
 
         protected override async void OnMouseMove(MouseEventArgs e)
-        { 
+        {  
+
             if (PDFViewer == null || PDFViewer.CurrentRenderFrame == null || PDFViewer.IsRendering)
             {
                 return;
@@ -720,11 +723,13 @@ namespace ComPDFKit.Tool
             }
 
             MouseMoveHandler?.Invoke(this, mouseEventObject);
+
             PDFViewer.SetCustomMousePoint(Mouse.GetPosition(this).Y, Mouse.GetPosition(this).X);
             if (oldCursor != newCursor)
             {
                 this.Cursor = newCursor;
             }
+
         }
 
         protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
@@ -822,6 +827,7 @@ namespace ComPDFKit.Tool
                 else
                 {
                     CleanSelectedRect();
+                    CleanEditAnnot();
                 }
             }
 

+ 26 - 18
Demo/Examples/ComPDFKit.Tool/DrawTool/AnnotEdit.cs

@@ -44,7 +44,11 @@ namespace ComPDFKit.Tool.DrawTool
         /// </summary>
         protected bool isMouseDown { get; set; }
 
-        protected DrawingContext drawDC { get; set; }
+        protected DrawingContext drawDC
+        {
+            get;
+            set;
+        }
 
         /// <summary>
         /// Current annotation's control points collection (96 DPI coordinate points, minus page offset)
@@ -315,7 +319,7 @@ namespace ComPDFKit.Tool.DrawTool
             lineVector.Normalize();
             Vector leadEndVector = lineVector * (Math.Abs(LeadLength) + Math.Abs(LeadOffset) + Math.Abs(LeadExtension) * annotData.CurrentZoom);
             Vector leadStartVector = lineVector * (Math.Abs(LeadOffset)) * annotData.CurrentZoom;
-            Vector leadCrossVector = lineVector * (Math.Abs(LeadLength)  * annotData.CurrentZoom + Math.Abs(LeadOffset));
+            Vector leadCrossVector = lineVector * (Math.Abs(LeadLength) * annotData.CurrentZoom + Math.Abs(LeadOffset));
             Matrix rotateMatrix = new Matrix();
             double angle = LeadLength < 0 ? 90 : -90;
             rotateMatrix.Rotate(angle);
@@ -365,13 +369,14 @@ namespace ComPDFKit.Tool.DrawTool
                     );
 
                 Point movePoint = CheckMoveOffSet(activePoints.ToList(), maxRect, newOffset);
-                if(movePoint.X==0)
+
+                if (movePoint.X == 0)
                 {
-                    newOffset.X=moveOffset.X;
+                    newOffset.X = moveOffset.X;
                 }
-                if(movePoint.Y==0)
+                if (movePoint.Y == 0)
                 {
-                    newOffset.Y=moveOffset.Y;
+                    newOffset.Y = moveOffset.Y;
                 }
                 moveOffset = newOffset;
                 Draw();
@@ -413,11 +418,11 @@ namespace ComPDFKit.Tool.DrawTool
                     activePoints.Add(moveCrossLine[1]);
                 }
             }
-   
+
             moveLeftLine = null;
             moveRightLine = null;
             moveCrossLine = null;
-            if (moveOffset!= new Point(0, 0))
+            if (moveOffset != new Point(0, 0))
             {
                 InvokeDataChangEvent(true);
             }
@@ -514,7 +519,7 @@ namespace ComPDFKit.Tool.DrawTool
             });
         }
 
-        private Point CheckPointBound(Point checkPoint,Rect bound)
+        private Point CheckPointBound(Point checkPoint, Rect bound)
         {
             if (checkPoint.X < bound.Left)
             {
@@ -554,7 +559,7 @@ namespace ComPDFKit.Tool.DrawTool
 
             Point movePoint = moveOffset;
 
-            if(left+moveOffset.X<bound.Left || right+moveOffset.X>bound.Right)
+            if (left + moveOffset.X < bound.Left || right + moveOffset.X > bound.Right)
             {
                 movePoint.X = 0;
             }
@@ -575,7 +580,7 @@ namespace ComPDFKit.Tool.DrawTool
             PolyLineSegment polySegment = new PolyLineSegment();
             if (hitIndex != -1 && hitIndex < activePoints.Count)
             {
-                if (mouseEndDrawPoint!=new Point() && !activePoints.Contains(mouseEndDrawPoint))
+                if (mouseEndDrawPoint != new Point() && !activePoints.Contains(mouseEndDrawPoint))
                 {
                     activePoints[hitIndex] = CheckPointBound(mouseEndDrawPoint, maxRect);
                 }
@@ -587,7 +592,7 @@ namespace ComPDFKit.Tool.DrawTool
                 StartPoint.X += moveOffset.X;
                 StartPoint.Y += moveOffset.Y;
             }
-            
+
             drawFigure.StartPoint = StartPoint;
             for (int i = 1; i < activePoints.Count; i++)
             {
@@ -654,7 +659,7 @@ namespace ComPDFKit.Tool.DrawTool
                 moveRightLine = rightLine.ToArray();
                 moveCrossLine = crossLine.ToArray();
                 switch (hitIndex)
-                { 
+                {
                     case 0://Left
                         {
                             moveLeftLine[0].X += moveOffset.X;
@@ -828,12 +833,13 @@ namespace ComPDFKit.Tool.DrawTool
             PolyLineSegment polySegment = new PolyLineSegment();
             if (hitIndex != -1 && hitIndex < activePoints.Count)
             {
-                if (mouseEndDrawPoint != new Point())
+                if (mouseEndDrawPoint != new Point() && !activePoints.Contains(mouseEndDrawPoint))
                 {
-                    activePoints[hitIndex] = mouseEndDrawPoint;
+                    activePoints[hitIndex] = CheckPointBound(mouseEndDrawPoint, maxRect);
                 }
             }
 
+
             Point StartPoint = activePoints[0];
             if (hitIndex == -1)
             {
@@ -892,11 +898,12 @@ namespace ComPDFKit.Tool.DrawTool
             PathFigure drawFigure = new PathFigure();
 
             PolyLineSegment polySegment = new PolyLineSegment();
+
             if (hitIndex != -1 && hitIndex < activePoints.Count)
             {
-                if (mouseEndDrawPoint!=new Point())
+                if (mouseEndDrawPoint != new Point() && !activePoints.Contains(mouseEndDrawPoint))
                 {
-                    activePoints[hitIndex] = mouseEndDrawPoint;
+                    activePoints[hitIndex] = CheckPointBound(mouseEndDrawPoint, maxRect);
                 }
             }
 
@@ -953,9 +960,10 @@ namespace ComPDFKit.Tool.DrawTool
             }
         }
 
+        int i = 0;
         public virtual void ClearDraw()
         {
-            drawDC = RenderOpen();
+            drawDC = RenderOpen(); 
             drawDC?.Close();
             drawDC = null;
         }

+ 1 - 1
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationData/CPDFAnnotationData.cs

@@ -157,7 +157,7 @@ namespace ComPDFKit.Controls.Data
 
     public class CPDFMarkupData : CPDFAnnotationData
     {
-        public double Opacity = 1;
+        public double Opacity = 255;
         public Color Color = Color.FromRgb(255, 0, 0);
     }
 

+ 3 - 2
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationPanel/PDFAnnotationControl/CPDFAnnotationControl.xaml.cs

@@ -326,7 +326,7 @@ namespace ComPDFKit.Controls.PDFControl
                         CPDFPolygonData polygonData = pdfAnnotationData as CPDFPolygonData;
                         pdfViewerControl.PDFViewTool.GetDefaultSettingParam().IsCreateSquarePolygonMeasure = false;
                         annotHandlerEventArgs = new PolygonMeasureParam()
-                        {
+                        {   
                             CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON
                         };
                         if (annotHandlerEventArgs is PolygonMeasureParam polygonMeasureParam)
@@ -345,6 +345,7 @@ namespace ComPDFKit.Controls.PDFControl
                             polygonMeasureParam.LineWidth = polygonData.Thickness; 
                             polygonMeasureParam.Transparency = (byte)(polygonData.Opacity / 100 * 255.0);
                             polygonMeasureParam.IsMeasure = false;
+                            polygonMeasureParam.Content = polygonData.Note;
                         }
                         pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON);
                     }
@@ -1227,7 +1228,7 @@ namespace ComPDFKit.Controls.PDFControl
             }
         }
 
-        private void ShowTempAnnotPanel()
+        public void ShowTempAnnotPanel()
         {
             BaseAnnot baseAnnot = pdfViewerControl.GetCacheHitTestAnnot();
             if (baseAnnot != null)

+ 10 - 5
Demo/Examples/Samples/AnnotationTest/CS/AnnotationTest.cs

@@ -111,7 +111,7 @@ namespace AnnotationTest
         /// Include:
         /// Square, Circle, Line
         /// </summary>
-        /// <param name="document"></param>
+        /// <param name="document"></param>7
         static private void CreateShapeAnnotation(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
@@ -119,15 +119,18 @@ namespace AnnotationTest
             byte[] lineColor = { 255, 0, 0 };
             byte[] bgColor = { 0, 255, 0 };
 
+            CPDFBorderEffector borderEffect = new CPDFBorderEffector( C_BORDER_TYPE.C_BORDER_TYPE_Cloud, C_BORDER_INTENSITY.C_INTENSITY_TWO);
             // Square
+
             CPDFSquareAnnotation square = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE) as CPDFSquareAnnotation;
             square.SetSourceRect(new CRect(10, 250, 200, 200)); 
             square.SetLineColor(lineColor);
             square.SetBgColor(bgColor);
             square.SetTransparency(120);
             square.SetLineWidth(1);
-            square.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, dashArray);
-            square.AnnotationRotator.SetRotation(45);
+            square.SetBorderWidth(1);
+            square.SetAnnotBorderEffector(borderEffect); 
+            square.AnnotationRotator.SetRotation(45); 
             square.UpdateAp();
 
             // Circle
@@ -138,6 +141,8 @@ namespace AnnotationTest
             circle.SetTransparency(120);
             circle.SetLineWidth(1);
             circle.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, dashArray);
+            circle.SetAnnotBorderEffect(borderEffect);
+            square.SetBorderWidth(1);
             circle.UpdateAp();
 
             // Line
@@ -262,8 +267,8 @@ namespace AnnotationTest
             CPDFStampAnnotation standard = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP) as CPDFStampAnnotation;
             standard.SetStandardStamp("Approved");
              
-            standard.SetRect(new CRect(100, 100, 250, 150));
-            // standard.AnnotationRotator.SetRotation(45);
+            standard.SetSourceRect(new CRect(100, 100, 250, 150));
+            standard.AnnotationRotator.SetRotation(45);
 
             standard.UpdateAp();