Explorar el Código

ComPDFKit.Tool(win) - 补充云朵注释复制粘贴功能

TangJinZhou hace 3 días
padre
commit
493528d932

+ 59 - 0
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.Command.cs

@@ -1517,8 +1517,67 @@ namespace ComPDFKit.Tool
                             (annotHistory as CircleAnnotHistory).CurrentParam = (CircleParam)annotParam;
                         }
                         break;
+
                     case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
+                        {
+                            CPDFDocument cPDFDocument = PDFViewer.GetDocument();
+                            Rect rect;
+                            annotHistory = new PolygonMeasureAnnotHistory();
+                            annotHistory.PDFDoc = cPDFDocument;
+                            int index = -1;
+                            if (point.Equals(new Point(-1, -1)))
+                            {
+                                index = item.PageIndex;
+                                rect = new Rect(
+                                    (item.ClientRect.left + 25),
+                                    (item.ClientRect.top + 25),
+                                    item.ClientRect.width(),
+                                    item.ClientRect.height()
+                                );
+                            }
+                            else
+                            {
+                                PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
+                                CRect cRect = item.ClientRect;
+                                Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
+                                Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
+                                rect = new Rect(
+                                    (pdfPoint.X - cRect.width() / 2),
+                                    (pdfPoint.Y - cRect.height() / 2),
+                                    cRect.width(),
+                                    cRect.height()
+                                );
+                            }
+
+                            CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
+                            PolygonMeasureParam newPolygonParam = new PolygonMeasureParam();
+                            item.CopyTo(newPolygonParam);
+                            if(newPolygonParam.SavePoints != null && newPolygonParam.SavePoints.Count>0)
+                            {
+                                float offsetX = setRect.left - item.ClientRect.left;
+                                float offsetY = setRect.top - item.ClientRect.top;
+                                List<CPoint> arrangeList = new List<CPoint>();
+                                foreach (CPoint addPoint in newPolygonParam.SavePoints)
+                                {
+                                    arrangeList.Add(new CPoint(addPoint.x + offsetX, addPoint.y + offsetY));
+                                }
+
+                                newPolygonParam.SavePoints = arrangeList;
+                                newPolygonParam.ClientRect = setRect;
+                            }
+
+                            CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
+                            if (cPDFPage == null)
+                                return;
+
+                            CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(newPolygonParam.CurrentType);
+                            CreateDefaultAnnot(cPDFAnnotation, newPolygonParam.CurrentType, newPolygonParam);
+                            cPDFAnnotation.UpdateAp();
+                            AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
+                            (annotHistory as PolygonMeasureAnnotHistory).CurrentParam = (PolygonMeasureParam)annotParam;
+                        }
                         break;
+
                     case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:

+ 28 - 31
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.DataMethod.cs

@@ -795,84 +795,81 @@ namespace ComPDFKit.Tool
         private void DefaultPolygonMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
         {
             CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
-
             bool IsOpenMeasure = true;
-
             if (PolyAnnotation == null)
             {
                 return;
             }
-            if (annotParam != null)
-            {
-                return;
-            }
 
-            PolygonMeasureParam MeasureParam;
+            PolygonMeasureParam polyonMeasureParam;
             if (annotParam == null)
             {
                 DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
-                MeasureParam = defaultSettingParam.PolygonMeasureParamDef;
+                polyonMeasureParam = defaultSettingParam.PolygonMeasureParamDef;
                 IsOpenMeasure = defaultSettingParam.IsOpenMeasure;
             }
             else
             {
-                MeasureParam = annotParam as PolygonMeasureParam;
+                polyonMeasureParam = annotParam as PolygonMeasureParam;
                 IsOpenMeasure = defaultSettingParam.IsOpenMeasure; 
             }
 
-            if (MeasureParam.LineColor != null)
+            if (polyonMeasureParam.LineColor != null)
             {
-                PolyAnnotation.SetLineColor(MeasureParam.LineColor);
+                PolyAnnotation.SetLineColor(polyonMeasureParam.LineColor);
             }
-            PolyAnnotation.SetLineWidth((float)MeasureParam.LineWidth);
 
-            if (MeasureParam.LineDash != null)
+            PolyAnnotation.SetLineWidth((float)polyonMeasureParam.LineWidth);
+            if (polyonMeasureParam.LineDash != null)
             {
-                if (MeasureParam.LineDash.Length == 0)
+                if (polyonMeasureParam.LineDash.Length == 0)
                 {
                     PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
                 }
                 else
                 {
-                    PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, MeasureParam.LineDash);
+                    PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, polyonMeasureParam.LineDash);
                 }
             }
 
-            if (MeasureParam.HasFillColor && MeasureParam.FillColor != null && MeasureParam.FillColor.Length == 3)
+            if (polyonMeasureParam.HasFillColor && polyonMeasureParam.FillColor != null && polyonMeasureParam.FillColor.Length == 3)
+            {
+                PolyAnnotation.SetBgColor(polyonMeasureParam.FillColor);
+            }
+
+            if(polyonMeasureParam.BorderEffector != null)
             {
-                PolyAnnotation.SetBgColor(MeasureParam.FillColor);
+                PolyAnnotation.SetAnnotBorderEffector(polyonMeasureParam.BorderEffector);
             }
 
-            if(MeasureParam.BorderEffector != null)
+            if (polyonMeasureParam.SavePoints != null && polyonMeasureParam.SavePoints.Count>0)
             {
-                PolyAnnotation.SetAnnotBorderEffector(MeasureParam.BorderEffector);
+                PolyAnnotation.SetPoints(polyonMeasureParam.SavePoints);
             }
 
             if (IsOpenMeasure)
             {
                 CTextAttribute textAttribute = new CTextAttribute();
-                textAttribute.FontColor = MeasureParam.FontColor;
-                textAttribute.FontSize = (float)MeasureParam.FontSize;
-                textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(MeasureParam.FontName),
-                            MeasureParam.IsBold,
-                            MeasureParam.IsItalic);
+                textAttribute.FontColor = polyonMeasureParam.FontColor;
+                textAttribute.FontSize = (float)polyonMeasureParam.FontSize;
+                textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(polyonMeasureParam.FontName),
+                            polyonMeasureParam.IsBold,
+                            polyonMeasureParam.IsItalic);
                 PolyAnnotation.SetTextAttribute(textAttribute);
-                if (MeasureParam.measureInfo != null)
+                if (polyonMeasureParam.measureInfo != null)
                 {
                     CPDFAreaMeasure polygonMeasure = PolyAnnotation.GetAreaMeasure();
                     if (polygonMeasure != null)
                     {
-                        polygonMeasure.SetMeasureInfo(MeasureParam.measureInfo);
-                        polygonMeasure.SetMeasureScale(MeasureParam.measureInfo.RulerBase, MeasureParam.measureInfo.RulerBaseUnit,
-                                                       MeasureParam.measureInfo.RulerTranslate, MeasureParam.measureInfo.RulerTranslateUnit);
+                        polygonMeasure.SetMeasureInfo(polyonMeasureParam.measureInfo);
+                        polygonMeasure.SetMeasureScale(polyonMeasureParam.measureInfo.RulerBase, polyonMeasureParam.measureInfo.RulerBaseUnit,
+                                                       polyonMeasureParam.measureInfo.RulerTranslate, polyonMeasureParam.measureInfo.RulerTranslateUnit);
                         polygonMeasure.UpdateAnnotMeasure();
                     }
                 }
-                cPDFAnnotation.UpdateAp();
             }
 
-            
-            DefaultAnnot(cPDFAnnotation, MeasureParam);
+            DefaultAnnot(cPDFAnnotation, polyonMeasureParam);
         }
 
         private void DefaultPolyLineMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)

+ 3 - 1
Demo/Examples/ComPDFKit.Tool/SettingParam/AnnotParam/PolygonMeasureParam.cs

@@ -75,7 +75,9 @@ namespace ComPDFKit.Tool
 
             if (SavePoints != null)
             {
-                polygonTransfer.SavePoints.CopyTo(SavePoints.ToArray());
+                CPoint[] pointArray = new CPoint[SavePoints.Count];
+                SavePoints.CopyTo(pointArray);
+                polygonTransfer.SavePoints = pointArray.ToList();
             }
 
             if (LineColor != null)