Browse Source

ComPDFKit.Tool(win) - 新增Stamp旋转参数

TangJinZhou 4 months ago
parent
commit
cefb2ab087

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

@@ -23,8 +23,6 @@ using System.Globalization;
 using ComPDFKitViewer.Layer;
 using ComPDFKitViewer;
 using ComPDFKitViewer.Annot;
-using System.Windows.Annotations;
-using ComPDFKit.Viewer.Annot;
 
 namespace ComPDFKit.Tool
 {
@@ -481,7 +479,7 @@ namespace ComPDFKit.Tool
                 {
                     CPDFStampAnnotation stampAnnot = e.annotData.Annot as CPDFStampAnnotation;
                     stampAnnot.SetSourceRect(cRect);
-                    stampAnnot.AnnotationRotator.SetRotation(e.rotationAngle);
+                    stampAnnot.AnnotationRotator.SetRotation(- e.rotationAngle);
                 }
                 else
                 {

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

@@ -240,7 +240,7 @@ namespace ComPDFKit.Tool
             {
                 DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
                 StampParam stampParam = defaultSettingParam.StampParamDef;
-                stampParam.Rotation = cPDFPage.Rotation;
+                stampParam.PageRotation = cPDFPage.Rotation;
                 defaultSettingParam.SetAnnotParam(stampParam);
             }
             Point cropPoint = new Point();

+ 3 - 2
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.Command.cs

@@ -1541,7 +1541,7 @@ namespace ComPDFKit.Tool
                             else
                             {
                                 PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
-                                CRect cRect = item.ClientRect;
+                                CRect cRect = (item as StampParam).SourceRect;
                                 Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
                                 Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
                                 rect = new Rect(
@@ -1558,8 +1558,9 @@ namespace ComPDFKit.Tool
                                 return;
 
                             CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
+                            (cPDFAnnotation as CPDFStampAnnotation).SetSourceRect(setRect);
+                            //cPDFAnnotation.SetRect(setRect);
                             CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
-                            cPDFAnnotation.SetRect(setRect);
                             cPDFAnnotation.UpdateAp();
                             AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
                             (annotHistory as StampAnnotHistory).CurrentParam = (StampParam)annotParam;

+ 10 - 12
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.DataMethod.cs

@@ -4,9 +4,6 @@ using ComPDFKit.PDFDocument.Action;
 using ComPDFKit.PDFDocument;
 using ComPDFKit.Tool.SettingParam;
 using ComPDFKitViewer;
-using System;
-using System.Collections.Generic;
-using System.Linq;
 using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
 using static ComPDFKit.PDFAnnotation.CTextAttribute;
 using ComPDFKit.Tool.Help;
@@ -535,8 +532,8 @@ namespace ComPDFKit.Tool
 
         private void DefaultStampAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
         {
-            CPDFStampAnnotation strikeoutAnnotation = (cPDFAnnotation as CPDFStampAnnotation);
-            if (strikeoutAnnotation == null)
+            CPDFStampAnnotation stampAnnot = (cPDFAnnotation as CPDFStampAnnotation);
+            if (stampAnnot == null)
             {
                 return;
             }
@@ -545,7 +542,6 @@ namespace ComPDFKit.Tool
             if (annotParam == null)
             {
                 DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
-
                 stampParam = defaultSettingParam.StampParamDef;
             }
             else
@@ -562,7 +558,8 @@ namespace ComPDFKit.Tool
                         {
                             stampText = string.Empty;
                         }
-                        strikeoutAnnotation.SetStandardStamp(stampText, stampParam.Rotation);
+
+                        stampAnnot.SetStandardStamp(stampText, stampParam.PageRotation);
                     }
                     break;
                 case C_STAMP_TYPE.IMAGE_STAMP:
@@ -574,12 +571,12 @@ namespace ComPDFKit.Tool
 
                         if (imageData != null && imageWidth > 0 && imageHeight > 0)
                         {
-                            strikeoutAnnotation.SetRect(new CRect(0, imageHeight, imageWidth, 0));
-                            strikeoutAnnotation.SetImageStamp(
+                            stampAnnot.SetRect(new CRect(0, imageHeight, imageWidth, 0));
+                            stampAnnot.SetImageStamp(
                                 imageData,
                                 imageWidth,
                                 imageHeight,
-                                stampParam.Rotation);
+                                stampParam.PageRotation);
                         }
                     }
                     break;
@@ -595,18 +592,19 @@ namespace ComPDFKit.Tool
                         {
                             stampText = string.Empty;
                         }
-                        strikeoutAnnotation.SetTextStamp(
+                        stampAnnot.SetTextStamp(
                             stampText,
                             dateText,
                             stampParam.TextStampShape,
                             stampParam.TextStampColor,
-                            stampParam.Rotation);
+                            stampParam.PageRotation);
                     }
                     break;
                 default:
                     break;
             }
 
+            stampAnnot.AnnotationRotator.SetRotation(stampParam.Rotation);
             DefaultAnnot(cPDFAnnotation, stampParam);
         }
 

+ 10 - 4
Demo/Examples/ComPDFKit.Tool/Help/ParamConverter.cs

@@ -396,7 +396,7 @@ namespace ComPDFKit.Tool.Help
         {
             PathEditParam pathEditParam = new PathEditParam();
             pathEditParam.Transparency = cPDFEditArea.GetTransparency();
-            pathEditParam.Rotate = - cPDFEditArea.GetRotation();
+            pathEditParam.Rotate = cPDFEditArea.GetRotation();
             pathEditParam.StrokeColor = cPDFEditArea.GetStrokeColor();
             pathEditParam.FillColor = cPDFEditArea.GetFillColor();
             pathEditParam.ClipRect = cPDFEditArea.GetClipRect();
@@ -1657,6 +1657,12 @@ namespace ComPDFKit.Tool.Help
                     return null;
             }
 
+            stampParam.PageRotation = stampAnnot.Page.Rotation;
+            stampParam.Rotation = stampAnnot.AnnotationRotator.GetRotation();
+            CRect sourceRect = new CRect();
+            stampAnnot.GetSourceRect(ref sourceRect);
+            stampParam.SourceRect = sourceRect;
+
             GetAnnotCommonParam(stampAnnot, stampParam);
             return stampParam;
         }
@@ -2930,7 +2936,7 @@ namespace ComPDFKit.Tool.Help
                             {
                                 stampText = string.Empty;
                             }
-                            stampAnnot.SetStandardStamp(stampText, CurrentParam.Rotation);
+                            stampAnnot.SetStandardStamp(stampText, CurrentParam.PageRotation);
                             stampAnnot.SetRect(CurrentParam.ClientRect);
                         }
                         break;
@@ -2951,7 +2957,7 @@ namespace ComPDFKit.Tool.Help
                                 dateText,
                                 CurrentParam.TextStampShape,
                                 CurrentParam.TextStampColor,
-                                CurrentParam.Rotation);
+                                CurrentParam.PageRotation);
                             stampAnnot.SetRect(CurrentParam.ClientRect);
                         }
                         break;
@@ -2968,7 +2974,7 @@ namespace ComPDFKit.Tool.Help
                                     imageData,
                                     imageWidth,
                                     imageHeight,
-                                    CurrentParam.Rotation);
+                                    CurrentParam.PageRotation);
                             }
                         }
                         break;

+ 10 - 8
Demo/Examples/ComPDFKit.Tool/SettingParam/AnnotParam/StampParam.cs

@@ -1,4 +1,5 @@
-using ComPDFKit.PDFAnnotation;
+using ComPDFKit.Import;
+using ComPDFKit.PDFAnnotation;
 using System.IO;
 
 namespace ComPDFKit.Tool
@@ -10,18 +11,17 @@ namespace ComPDFKit.Tool
             CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
         }
 
-
 		public string StampText { get; set; } = string.Empty;
 		public string DateText {  get; set; }= string.Empty;
 		public C_STAMP_TYPE StampType { get; set; }
 		public C_TEXTSTAMP_SHAPE TextStampShape {  get; set; }
 		public C_TEXTSTAMP_COLOR TextStampColor {  get; set; }
 		public MemoryStream ImageStream { get; set; }
+		public int PageRotation { get; set; }	
 		public int Rotation { get; set; }	
-		//暂时做旋转用
-		//后续底层更新旋转角度支持后废除
-		//-1 逆时针 0 未动  1顺时针
-		public int Clockwise {  get; set; }
+		public CRect SourceRect { get; set; }
+
+        public int Clockwise {  get; set; }
 
         public override bool CopyTo(AnnotParam transfer)
 		{
@@ -42,8 +42,10 @@ namespace ComPDFKit.Tool
 			stampTransfer.TextStampColor = TextStampColor;
 			stampTransfer.TextStampShape = TextStampShape;
 			stampTransfer.ImageStream = ImageStream;
-			stampTransfer.Rotation = Rotation;
-			stampTransfer.Clockwise = Clockwise;
+			stampTransfer.PageRotation = PageRotation;
+            stampTransfer.Rotation = Rotation;
+			stampTransfer.SourceRect = SourceRect;
+            stampTransfer.Clockwise = Clockwise;
 
 			return true;
 		}