Prechádzať zdrojové kódy

ComPDFKit.Tool(win) - 补充多边形注释Undo参数

TangJinZhou 1 týždeň pred
rodič
commit
ea33934037

+ 0 - 1
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.DataMethod.cs

@@ -267,7 +267,6 @@ namespace ComPDFKit.Tool
 
             if (FreeTextParam.Dash != null && FreeTextParam.Dash.Length > 0)
             {
-                //补充保存虚线样式
                 freeTextAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, FreeTextParam.Dash);
             }
 

+ 32 - 33
Demo/Examples/ComPDFKit.Tool/DrawTool/CreateAnnotTool.cs

@@ -1045,29 +1045,29 @@ namespace ComPDFKit.Tool.DrawTool
 
         private void DrawPolygonMeasure(DrawingContext drawingContext)
         {
-            CPDFPolygonAnnotation polyLine = (cPDFAnnotation as CPDFPolygonAnnotation);
-            byte[] bytes = polyLine.LineColor;
+            CPDFPolygonAnnotation polygonAnnot = (cPDFAnnotation as CPDFPolygonAnnotation);
+            byte[] bytes = polygonAnnot.LineColor;
             Color color = ParamConverter.ConverterByteForColor(bytes);
-            color.A = polyLine.GetTransparency();
-            Pen DrawPen = new Pen(new SolidColorBrush(color), polyLine.GetBorderWidth());
-            Pen EndDrawPen = new Pen(Brushes.Black, polyLine.GetBorderWidth());
+            color.A = polygonAnnot.GetTransparency();
+            Pen DrawPen = new Pen(new SolidColorBrush(color), polygonAnnot.GetBorderWidth());
+            Pen EndDrawPen = new Pen(Brushes.Black, polygonAnnot.GetBorderWidth());
             SolidColorBrush TextBrush = Brushes.Red;
 
-            if (polyLine.IsMeasured())
+            if (polygonAnnot.IsMeasured())
             {
-                CPDFAreaMeasure measureInfo = polyLine.GetAreaMeasure();
+                CPDFAreaMeasure measureInfo = polygonAnnot.GetAreaMeasure();
                 if (measureInfo != null && measureInfo.TextAttribute != null && measureInfo.TextAttribute.FontColor != null && measureInfo.TextAttribute.FontColor.Length >= 3)
                 {
                     byte[] fontColor = measureInfo.TextAttribute.FontColor;
                     TextBrush = new SolidColorBrush(Color.FromRgb(fontColor[0], fontColor[1], fontColor[2]));
                 }
 
-                if (polyLine.Dash != null && polyLine.Dash.Length > 0)
+                if (polygonAnnot.Dash != null && polygonAnnot.Dash.Length > 0)
                 {
                     DashStyle dash = new DashStyle();
-                    foreach (var offset in polyLine.Dash)
+                    foreach (var offset in polygonAnnot.Dash)
                     {
-                        dash.Dashes.Add(offset / polyLine.LineWidth);
+                        dash.Dashes.Add(offset / polygonAnnot.LineWidth);
                     }
                     DrawPen.DashStyle = dash;
                     DrawPen.DashCap = PenLineCap.Flat;
@@ -1081,6 +1081,7 @@ namespace ComPDFKit.Tool.DrawTool
                     mouseEndPoint = CalcAnglePoint(mouseEndPoint, drawPoints[drawPoints.Count - 1], pageBound);
                 }
             }
+
             Point checkPoint = mouseEndPoint;
             checkPoint.X = Math.Max(pageBound.Left, checkPoint.X);
             checkPoint.X = Math.Min(pageBound.Right, checkPoint.X);
@@ -1098,9 +1099,10 @@ namespace ComPDFKit.Tool.DrawTool
                 points.Add(rect.BottomRight);
                 points.Add(rect.TopRight);
             }
+
             if (points.Count > 0)
             {
-                CPDFBorderEffector borderEffector = polyLine.GetAnnotBorderEffector();
+                CPDFBorderEffector borderEffector = polygonAnnot.GetAnnotBorderEffector();
                 if (borderEffector != null && borderEffector.BorderIntensity != C_BORDER_INTENSITY.C_INTENSITY_ZERO && borderEffector.BorderType != C_BORDER_TYPE.C_BORDER_TYPE_STRAIGHT)
                 {
                     //Draw the example line connected by the start point and the end point.
@@ -1108,30 +1110,29 @@ namespace ComPDFKit.Tool.DrawTool
                     {
                         Pen dashedPen = new Pen(Brushes.Gray, 1);
                         dashedPen.DashStyle = new DashStyle(new double[] { 2, 2 }, 0);
-
                         drawingContext?.DrawLine(dashedPen, points[0], checkPoint);
                     }
 
-                    CPDFPolygonAnnotation polygonAnnot = cPDFAnnotation as CPDFPolygonAnnotation;
+                    double left = drawPoints.AsEnumerable().Select(x => x.X).Min();
+                    double right = drawPoints.AsEnumerable().Select(x => x.X).Max();
+                    double top = drawPoints.AsEnumerable().Select(x => x.Y).Min();
+                    double bottom = drawPoints.AsEnumerable().Select(x => x.Y).Max();
+                    DPIRect = new Rect(left, top, right - left, bottom - top);
+
                     polygonAnnot.SetAnnotBorderEffector(borderEffector);
                     drawPoints.Add(checkPoint);
                     List<Point> measurePoint = new List<Point>();
-
                     measurePoint = GetMeasureDrawPoints();
-
+                    drawPoints.RemoveAt(drawPoints.Count - 1);
                     List<CPoint> cPoints = new List<CPoint>();
                     foreach (Point item in measurePoint)
                     {
                         cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
                     }
 
-                    (cPDFAnnotation as CPDFPolygonAnnotation).SetPoints(cPoints);
-
-                    drawPoints.RemoveAt(drawPoints.Count - 1);
-
+                    polygonAnnot.SetPoints(cPoints);
                     polygonAnnot.UpdateAp();
                     cPDFViewer.UpdateAnnotFrame();
-
                 }
                 else
                 {
@@ -1191,21 +1192,18 @@ namespace ComPDFKit.Tool.DrawTool
                             totalInch += measureSetting.GetMeasureLength(points[i], points[i + 1], zoomFactor);
                         }
                     }
+
                     double currentInch = measureSetting.GetMeasureLength(points[points.Count - 1], checkPoint, zoomFactor);
                     if (defaultSettingParam.IsCreateSquarePolygonMeasure)
                     {
                         currentInch = measureSetting.GetMeasureLength(points[points.Count - 1], points[0], zoomFactor);
                     }
-                    totalInch += currentInch;
 
+                    totalInch += currentInch;
                     Point closePoint = points[points.Count - 1];
                     Vector movevector = checkPoint - closePoint;
-
-
-
-                    if (polyLine.IsMeasured())
+                    if (polygonAnnot.IsMeasured())
                     {
-
                         FormattedText moveText = new FormattedText(
                             string.Format("{0} {1}", measureSetting.GetPrecisionData(currentInch), measureSetting.RulerTranslateUnit),
                             CultureInfo.GetCultureInfo("en-us"),
@@ -1262,7 +1260,6 @@ namespace ComPDFKit.Tool.DrawTool
                                     linePoint.Y - moveText.Height);
 
                                 Vector anglevector = linePoint - closePoint;
-
                                 RotateTransform transform = new RotateTransform();
                                 transform.CenterX = closePoint.X;
                                 transform.CenterY = closePoint.Y;
@@ -1287,20 +1284,22 @@ namespace ComPDFKit.Tool.DrawTool
                         }
                     }
 
-                    double left = drawPoints.AsEnumerable().Select(x => x.X).Min();
-                    double right = drawPoints.AsEnumerable().Select(x => x.X).Max();
-                    double top = drawPoints.AsEnumerable().Select(x => x.Y).Min();
-                    double bottom = drawPoints.AsEnumerable().Select(x => x.Y).Max();
-                    DPIRect = new Rect(left, top, right - left, bottom - top);
                     if (defaultSettingParam.IsCreateSquarePolygonMeasure)
                     {
                         double deleft = points.AsEnumerable().Select(x => x.X).Min();
                         double deright = points.AsEnumerable().Select(x => x.X).Max();
                         double detop = points.AsEnumerable().Select(x => x.Y).Min();
                         double debottom = points.AsEnumerable().Select(x => x.Y).Max();
-
                         DPIRect = new Rect(deleft, detop, deright - deleft, debottom - detop);
                     }
+                    else
+                    {
+                        double left = drawPoints.AsEnumerable().Select(x => x.X).Min();
+                        double right = drawPoints.AsEnumerable().Select(x => x.X).Max();
+                        double top = drawPoints.AsEnumerable().Select(x => x.Y).Min();
+                        double bottom = drawPoints.AsEnumerable().Select(x => x.Y).Max();
+                        DPIRect = new Rect(left, top, right - left, bottom - top);
+                    }
 
                     MeasureEventArgs measureEvent = new MeasureEventArgs();
                     if (points.Count < 2)

+ 1 - 27
Demo/Examples/ComPDFKit.Tool/DrawTool/FrameSelectTool.cs

@@ -1,35 +1,9 @@
-using ComPDFKit.Import;
-using ComPDFKit.Measure;
-using ComPDFKit.PDFAnnotation;
-using ComPDFKit.PDFDocument;
-using ComPDFKit.PDFPage;
-using ComPDFKit.Tool.Help;
-using ComPDFKit.Tool.SettingParam;
-using ComPDFKit.Tool.UndoManger;
-using ComPDFKit.Viewer.Helper;
-using ComPDFKit.Viewer.Layer;
-using ComPDFKitViewer;
-using ComPDFKitViewer.Annot;
-using ComPDFKitViewer.BaseObject;
+using ComPDFKit.Viewer.Layer;
 using ComPDFKitViewer.Helper;
-using ComPDFKitViewer.Layer;
 using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Annotations;
 using System.Windows.Controls;
-using System.Windows.Input;
 using System.Windows.Media;
-using System.Windows.Media.Animation;
-using System.Windows.Media.Media3D;
-using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
-using static ComPDFKit.Tool.Help.ImportWin32;
 
 namespace ComPDFKit.Tool.DrawTool
 {

+ 12 - 12
Demo/Examples/ComPDFKit.Tool/Help/ParamConverter.cs

@@ -1150,7 +1150,6 @@ namespace ComPDFKit.Tool.Help
             }
 
             PolygonMeasureParam polygonParam = new PolygonMeasureParam();
-
             if (polygonAnnot.LineColor != null && polygonAnnot.LineColor.Length == 3)
             {
                 polygonParam.LineColor = new byte[3]
@@ -1755,7 +1754,7 @@ namespace ComPDFKit.Tool.Help
                     redactParam.FontColor = new byte[3] { redactAnnot.TextDa.FontColor[0], redactAnnot.TextDa.FontColor[1], redactAnnot.TextDa.FontColor[2] };
                 }
                 
-               redactParam.FontName= redactAnnot.TextDa.FontName;
+                redactParam.FontName= redactAnnot.TextDa.FontName;
                 redactParam.FontSize = redactAnnot.TextDa.FontSize;
                 redactParam.Alignment=redactAnnot.TextAlignment;
             }
@@ -1818,6 +1817,15 @@ namespace ComPDFKit.Tool.Help
             {
                 CPDFAreaMeasure areaMeasure = polygonAnnot.GetAreaMeasure();
                 measureParam.measureInfo = areaMeasure.MeasureInfo;
+                CTextAttribute textAttr = polygonAnnot.GetTextAttribute();
+                measureParam.FontName = textAttr.FontName;
+                measureParam.FontSize = textAttr.FontSize;
+                if (textAttr.FontColor != null && textAttr.FontColor.Length == 3)
+                {
+                    measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
+                }
+                measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
+                measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
             }
 
             if (polygonAnnot.LineColor != null && polygonAnnot.LineColor.Length == 3)
@@ -1825,7 +1833,7 @@ namespace ComPDFKit.Tool.Help
                 measureParam.LineColor = new byte[] { polygonAnnot.LineColor[0], polygonAnnot.LineColor[1], polygonAnnot.LineColor[2] };
             }
 
-            if(polygonAnnot.BgColor!=null && polygonAnnot.BgColor.Length == 3)
+            if(polygonAnnot.HasBgColor && polygonAnnot.BgColor!=null && polygonAnnot.BgColor.Length == 3)
             {
                 measureParam.HasFillColor = true;
                 measureParam.FillColor = new byte[] { polygonAnnot.BgColor[0], polygonAnnot.BgColor[1], polygonAnnot.BgColor[2] };
@@ -1836,15 +1844,7 @@ namespace ComPDFKit.Tool.Help
             measureParam.LineWidth = polygonAnnot.LineWidth;
             measureParam.Transparency = polygonAnnot.Transparency;
             measureParam.LineDash = polygonAnnot.Dash;
-            CTextAttribute textAttr = polygonAnnot.GetTextAttribute();
-            measureParam.FontName = textAttr.FontName;
-            measureParam.FontSize = textAttr.FontSize;
-            if (textAttr.FontColor != null && textAttr.FontColor.Length == 3)
-            {
-                measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
-            }
-            measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
-            measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
+            measureParam.BorderEffector = polygonAnnot.GetAnnotBorderEffector();
 
             GetAnnotCommonParam(polygonAnnot, measureParam);
             return measureParam;

+ 2 - 2
Demo/Examples/ComPDFKit.Tool/Properties/AssemblyInfo.cs

@@ -15,5 +15,5 @@ using System.Runtime.InteropServices;
 
 [assembly: Guid("a061ee7a-6704-4bd9-86ee-48ed5df75e2f")]
 
-[assembly: AssemblyVersion("2.1.0.0")]
-[assembly: AssemblyFileVersion("2.1.0.0")]
+[assembly: AssemblyVersion("2.2.0.0")]
+[assembly: AssemblyFileVersion("2.2.0.0")]

+ 0 - 1
Demo/Examples/ComPDFKit.Tool/UndoManger/AnnotHistory/HighlightAnnotHistory.cs

@@ -39,7 +39,6 @@ namespace ComPDFKit.Tool.UndoManger
             }
         }
 
-
         internal override bool Add()
         {
             HighlightParam currentParam = CurrentParam as HighlightParam;

+ 1 - 1
Demo/Examples/ComPDFKit.Tool/UndoManger/AnnotHistory/PolyLineMeasureAnnotHistory.cs

@@ -11,7 +11,7 @@ using static ComPDFKit.PDFAnnotation.CTextAttribute;
 
 namespace ComPDFKit.Tool.UndoManger
 {
-    internal class PolyLineMeasureAnnotHistory : AnnotHistory
+    public class PolyLineMeasureAnnotHistory : AnnotHistory
     {
         public override int GetAnnotIndex()
         {

+ 42 - 33
Demo/Examples/ComPDFKit.Tool/UndoManger/AnnotHistory/PolygonMeasureAnnotHistory.cs

@@ -2,17 +2,13 @@
 using ComPDFKit.PDFAnnotation;
 using ComPDFKit.PDFPage;
 using ComPDFKit.Tool.Help;
-using ComPDFKitViewer.Annot;
-using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using static ComPDFKit.PDFAnnotation.CTextAttribute;
 
 namespace ComPDFKit.Tool.UndoManger
 {
-    internal class PolygonMeasureAnnotHistory : AnnotHistory
+    public class PolygonMeasureAnnotHistory : AnnotHistory
     {
         public override int GetAnnotIndex()
         {
@@ -58,7 +54,6 @@ namespace ComPDFKit.Tool.UndoManger
             if (polygonAnnot != null)
             {
                 int annotIndex = pdfPage.GetAnnotCount() - 1;
-
                 if (currentParam.HasFillColor)
                 {
                     if (currentParam.FillColor != null && currentParam.FillColor.Length == 3)
@@ -72,12 +67,11 @@ namespace ComPDFKit.Tool.UndoManger
                     polygonAnnot.SetLineColor(currentParam.LineColor);
                 }
 
-                polygonAnnot.SetTransparency((byte)currentParam.Transparency);
+                polygonAnnot.SetTransparency(currentParam.Transparency);
                 polygonAnnot.SetLineWidth(currentParam.LineWidth);
-
                 polygonAnnot.SetPoints(currentParam.SavePoints);
+                polygonAnnot.SetAnnotBorderEffector(currentParam.BorderEffector);
                 polygonAnnot.SetRect(currentParam.ClientRect);
-
                 if (currentParam.LineDash != null)
                 {
                     if (currentParam.LineDash.Length == 0)
@@ -91,28 +85,33 @@ namespace ComPDFKit.Tool.UndoManger
                         {
                             floatArray.Add(num);
                         }
+
                         polygonAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
                     }
                 }
 
-                CTextAttribute textAttribute = new CTextAttribute();
-                textAttribute.FontColor = currentParam.FontColor;
-                textAttribute.FontSize = (float)currentParam.FontSize;
-                textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(currentParam.FontName),
-                            currentParam.IsBold,
-                            currentParam.IsItalic);
-                polygonAnnot.SetTextAttribute(textAttribute);
-                if (currentParam.measureInfo != null)
+                if(polygonAnnot.IsMeasured())
                 {
-                    CPDFAreaMeasure polygonMeasure = polygonAnnot.GetAreaMeasure();
-                    if (polygonMeasure != null)
+                    CTextAttribute textAttribute = new CTextAttribute();
+                    textAttribute.FontColor = currentParam.FontColor;
+                    textAttribute.FontSize = (float)currentParam.FontSize;
+                    textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(currentParam.FontName),
+                                currentParam.IsBold,
+                                currentParam.IsItalic);
+                    polygonAnnot.SetTextAttribute(textAttribute);
+                    if (currentParam.measureInfo != null)
                     {
-                        polygonMeasure.SetMeasureInfo(currentParam.measureInfo);
-                        polygonMeasure.SetMeasureScale(currentParam.measureInfo.RulerBase, currentParam.measureInfo.RulerBaseUnit,
-                                                       currentParam.measureInfo.RulerTranslate, currentParam.measureInfo.RulerTranslateUnit);
-                        polygonMeasure.UpdateAnnotMeasure();
+                        CPDFAreaMeasure polygonMeasure = polygonAnnot.GetAreaMeasure();
+                        if (polygonMeasure != null)
+                        {
+                            polygonMeasure.SetMeasureInfo(currentParam.measureInfo);
+                            polygonMeasure.SetMeasureScale(currentParam.measureInfo.RulerBase, currentParam.measureInfo.RulerBaseUnit,
+                                                           currentParam.measureInfo.RulerTranslate, currentParam.measureInfo.RulerTranslateUnit);
+                            polygonMeasure.UpdateAnnotMeasure();
+                        }
                     }
                 }
+ 
                 if (!string.IsNullOrEmpty(currentParam.Author))
                 {
                     polygonAnnot.SetAuthor(currentParam.Author);
@@ -122,6 +121,7 @@ namespace ComPDFKit.Tool.UndoManger
                 {
                     polygonAnnot.SetContent(currentParam.Content);
                 }
+
                 polygonAnnot.SetIsLocked(currentParam.Locked);
                 polygonAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
                 polygonAnnot.UpdateAp();
@@ -131,6 +131,7 @@ namespace ComPDFKit.Tool.UndoManger
                 {
                     currentParam.AnnotIndex = annotIndex;
                 }
+
                 if (PreviousParam != null)
                 {
                     PreviousParam.AnnotIndex = annotIndex;
@@ -149,7 +150,7 @@ namespace ComPDFKit.Tool.UndoManger
             if (MakeAnnotValid(CurrentParam))
             {
                 CPDFPolygonAnnotation polygonAnnot = Annot as CPDFPolygonAnnotation;
-                if (polygonAnnot == null || !polygonAnnot.IsValid() || !polygonAnnot.IsMeasured())
+                if (polygonAnnot == null || !polygonAnnot.IsValid())
                 {
                     return false;
                 }
@@ -211,12 +212,16 @@ namespace ComPDFKit.Tool.UndoManger
                     polygonAnnot.SetPoints(updateParam.SavePoints);
                 }
 
+                if(!updateParam.BorderEffector.Equals(checkParam.BorderEffector))
+                {
+                    polygonAnnot.SetAnnotBorderEffector(updateParam.BorderEffector);
+                }
+
                 if (!updateParam.ClientRect.Equals(checkParam.ClientRect))
                 {
                     polygonAnnot.SetRect(updateParam.ClientRect);
                 }
 
-
                 if (updateParam.Author != checkParam.Author)
                 {
                     polygonAnnot.SetAuthor(updateParam.Author);
@@ -231,19 +236,23 @@ namespace ComPDFKit.Tool.UndoManger
                 {
                     polygonAnnot.SetIsLocked(updateParam.Locked);
                 }
-                if (updateParam.measureInfo != checkParam.measureInfo)
+
+                if (polygonAnnot.IsMeasured())
                 {
-                    CPDFAreaMeasure polygonMeasure = polygonAnnot.GetAreaMeasure();
-                    if (polygonMeasure != null)
+                    if (updateParam.measureInfo != checkParam.measureInfo)
                     {
-                        polygonMeasure.SetMeasureInfo(updateParam.measureInfo);
-                        polygonMeasure.SetMeasureScale(updateParam.measureInfo.RulerBase, updateParam.measureInfo.RulerBaseUnit,
-                                                       updateParam.measureInfo.RulerTranslate, updateParam.measureInfo.RulerTranslateUnit);
-                        polygonMeasure.UpdateAnnotMeasure();
+                        CPDFAreaMeasure polygonMeasure = polygonAnnot.GetAreaMeasure();
+                        if (polygonMeasure != null)
+                        {
+                            polygonMeasure.SetMeasureInfo(updateParam.measureInfo);
+                            polygonMeasure.SetMeasureScale(updateParam.measureInfo.RulerBase, updateParam.measureInfo.RulerBaseUnit,
+                                                           updateParam.measureInfo.RulerTranslate, updateParam.measureInfo.RulerTranslateUnit);
+                            polygonMeasure.UpdateAnnotMeasure();
+                        }
                     }
                 }
-                polygonAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
 
+                polygonAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
                 polygonAnnot.UpdateAp();
 
                 return true;

+ 1 - 2
Demo/Examples/ComPDFKit.Tool/UndoManger/AnnotHistory/SquigglyAnnotHistory.cs

@@ -40,12 +40,11 @@ namespace ComPDFKit.Tool.UndoManger
         internal override bool Add()
 		{
             SquigglyParam currentParam = CurrentParam as SquigglyParam;
-
-
             if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
 			{
 				return false;
 			}
+
 			CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
 			CPDFSquigglyAnnotation squigglyAnnot = pdfPage?.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY) as CPDFSquigglyAnnotation;
 			if (squigglyAnnot != null)