Browse Source

ComPDFKit.Tool(win) - 修复Stamp注释旋转矩形和角度问题

TangJinZhou 2 months ago
parent
commit
d3aee4e83a

+ 10 - 6
Demo/Examples/ComPDFKit.Tool/CPDFToolManager.cs

@@ -474,12 +474,18 @@ namespace ComPDFKit.Tool
                     e.Square.Width / e.annotData.CurrentZoom,
                     e.Square.Height / e.annotData.CurrentZoom
                     );
+
                 Rect rect = DpiHelper.StandardRectToPDFRect(rect1);
                 CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
-                e.annotData.Annot.SetRect(cRect);
                 if(e.annotData.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_STAMP)
-                { 
-                    (e.annotData.Annot as CPDFStampAnnotation).AnnotationRotator.SetRotation(-e.rotationAngle);
+                {
+                    CPDFStampAnnotation stampAnnot = e.annotData.Annot as CPDFStampAnnotation;
+                    stampAnnot.SetSourceRect(cRect);
+                    stampAnnot.AnnotationRotator.SetRotation(e.rotationAngle);
+                }
+                else
+                {
+                    e.annotData.Annot.SetRect(cRect);
                 }
             }
 
@@ -1157,7 +1163,7 @@ namespace ComPDFKit.Tool
 
         private void SaveCreateAnnotation(ref CPDFAnnotation annotation, ref MouseEventObject e)
         {
-            if (annotation == null)
+            if (annotation == null || !annotation.IsValid())
             {
                 return;
             }
@@ -2034,7 +2040,6 @@ namespace ComPDFKit.Tool
                                 viewerTool.DrawMoveFrameSelect();
                             }
                         }
-
                     }
 
                     if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditText)
@@ -2048,7 +2053,6 @@ namespace ComPDFKit.Tool
                 {
                     Cursor cursor = Cursors.Arrow;
                     MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(viewerTool.PDFViewer.GetViewForTag(viewerTool.MultiSelectedRectViewTag));
-
                     if (viewerTool.GetLastSelectedRect() != null)
                     {
                         if (editSelected)

+ 2 - 2
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.SelectedRect.cs

@@ -150,7 +150,7 @@ namespace ComPDFKit.Tool
             SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
             if (selectedRect != null)
             {
-                selectedRect.SetAnnotData(cacheHitTestAnnot.GetAnnotData());
+                selectedRect.SetAnnotData(cacheHitTestAnnot.GetAnnotData(), PDFViewer);
             }
         }
 
@@ -166,7 +166,7 @@ namespace ComPDFKit.Tool
                 }
                 else
                 {
-                    selectedRect.SetAnnotData(annotData);
+                    selectedRect.SetAnnotData(annotData, PDFViewer);
                 }
             }
         }

+ 27 - 3
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.cs

@@ -603,7 +603,7 @@ namespace ComPDFKit.Tool.DrawTool
             return maxRect;
         }
 
-        public void SetAnnotData(AnnotData annotData)
+        public void SetAnnotData(AnnotData annotData, CPDFViewer viewer)
         {
             SetIgnorePoints(new List<PointControlType>());
             SetIsProportionalScaling(false);
@@ -638,9 +638,33 @@ namespace ComPDFKit.Tool.DrawTool
                 default:
                     break;
             }
+
             SetMaxRect(annotData.PaintOffset);
-            SetRect(annotData.PaintRect, annotData.CurrentZoom);
-            SetRotation(annotData.Rotation);
+            if(annotData.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_STAMP)
+            {
+                CRect sourceRect = new CRect();
+                annotData.Annot.GetSourceRect(ref sourceRect);
+                if (!sourceRect.IsEmpty)
+                {
+                    RenderData renderData = viewer.GetCurrentRenderPageForIndex(annotData.PageIndex);
+                    Rect zoomRect = new Rect(sourceRect.left / 72 * 96 * annotData.CurrentZoom, sourceRect.top / 72 * 96 * annotData.CurrentZoom, sourceRect.width() / 72 * 96 * annotData.CurrentZoom, sourceRect.height() / 72 * 96 * annotData.CurrentZoom);
+                    Rect rotateRect = zoomRect;
+                    rotateRect.X += renderData.PageBound.X - renderData.CropLeft * annotData.CurrentZoom;
+                    rotateRect.Y += renderData.PageBound.Y - renderData.CropTop * annotData.CurrentZoom;
+                    SetRect(rotateRect, annotData.CurrentZoom);
+                    rotateAngle = (annotData.Annot as CPDFStampAnnotation).AnnotationRotator.GetRotation();
+                }
+                else
+                {
+                    SetRect(annotData.PaintRect, annotData.CurrentZoom);
+                }
+            }
+            else
+            {
+                SetRect(annotData.PaintRect, annotData.CurrentZoom);
+            }
+
+            //SetRotation(annotData.Rotation);
             selectedRectData = new SelectedAnnotData();
             selectedRectData.annotData = annotData;
         }