Sfoglia il codice sorgente

ComPDFKit.Tools - 旋转相关更新

liuaoran 5 mesi fa
parent
commit
2bee94fea1

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

@@ -478,9 +478,8 @@ namespace ComPDFKit.Tool
                 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)
-                {
-                    // Test
-                    (e.annotData.Annot as CPDFStampAnnotation).SetRotation(45);
+                { 
+                    (e.annotData.Annot as CPDFStampAnnotation).AnnotationRotator.SetRotation(-e.rotationAngle);
                 }
             }
 
@@ -1371,6 +1370,7 @@ namespace ComPDFKit.Tool
                                         );
                                     CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
                                     annotation.SetRect(cStampRect);
+                                    annotation.SetSourceRect(cStampRect);
                                     annotation.UpdateAp();
                                     e.IsCreate = true;
                                     e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;

+ 22 - 6
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.cs

@@ -77,7 +77,7 @@ namespace ComPDFKit.Tool.DrawTool
 
         public AnnotData annotData { get; set; }
 
-        public double rotationAngle { get; set; }
+        public int rotationAngle { get; set; }
     }
 
     public partial class SelectedRect : DrawingVisual
@@ -266,7 +266,7 @@ namespace ComPDFKit.Tool.DrawTool
                 case PointControlType.Line:
                     return Cursors.SizeAll;
                 case PointControlType.Rotate:
-                    return CommonHelper.RotationCursor;
+                    // return CommonHelper.RotationCursor;
                 default:
                     return Cursors.Arrow;
             }
@@ -298,7 +298,7 @@ namespace ComPDFKit.Tool.DrawTool
                             SolidColorBrush moveBrush = DrawParam.AnnotMoveBrush;
                             Pen movepen = DrawParam.AnnotMovePen;
 
-                            GetMoveBrushAndPen(ref moveBrush, ref movepen);
+                            GetMoveBrushAndPen(ref moveBrush, ref movepen); 
                             if (selectedType == SelectedType.PDFEdit)
                             {
                                 DrawMoveBounds(drawDC, hitControlType, movepen, moveBrush, drawRect, DrawParam.PDFEditMoveRectPen);
@@ -488,6 +488,7 @@ namespace ComPDFKit.Tool.DrawTool
         public virtual void ClearDraw()
         {
             SetDrawRect = drawRect = new Rect();
+            rotateAngle = 0;
             drawDC = RenderOpen();
             drawDC?.Close();
             drawDC = null;
@@ -520,12 +521,22 @@ namespace ComPDFKit.Tool.DrawTool
         /// <param name="newRect">
         /// The new rect to set
         /// </param>
-        public Rect GetRect()
+        public Rect GetRect() 
         {
             Rect rect = new Rect(drawRect.X + rectPadding * currentZoom, drawRect.Y + rectPadding * currentZoom, Math.Max(rectMinWidth, drawRect.Width - 2 * rectPadding * currentZoom), Math.Max(RectMinHeight, drawRect.Height - 2 * rectPadding * currentZoom));
             return rect;
         }
 
+        public int GetRotation()
+        {
+            return rotateAngle;
+        }
+
+        public void SetRotation(int rotationAngle)
+        {
+            this.rotateAngle = rotationAngle;
+        }
+
         public void SetRectPadding(double rectPadding)
         {
             this.rectPadding = rectPadding;
@@ -628,7 +639,8 @@ namespace ComPDFKit.Tool.DrawTool
                     break;
             }
             SetMaxRect(annotData.PaintOffset);
-            SetRect(annotData.PaintRect, annotData.CurrentZoom); 
+            SetRect(annotData.PaintRect, annotData.CurrentZoom);
+            SetRotation(annotData.Rotation);
             selectedRectData = new SelectedAnnotData();
             selectedRectData.annotData = annotData;
         }
@@ -921,7 +933,11 @@ namespace ComPDFKit.Tool.DrawTool
                             }
                             if (canRotation)
                             { 
-                                Vector checkVector1 = point - rotationPoint;
+                                // rotationPoint 围绕centerPoint旋转angle度
+                                
+                                Point hitRotationPoint = new Point(centerPoint.X + (rotationPoint.X - centerPoint.X) * Math.Cos(rotateAngle * Math.PI / 180) - (rotationPoint.Y - centerPoint.Y) * Math.Sin(rotateAngle * Math.PI / 180),
+                                    centerPoint.Y + (rotationPoint.X - centerPoint.X) * Math.Sin(rotateAngle * Math.PI / 180) + (rotationPoint.Y - centerPoint.Y) * Math.Cos(rotateAngle * Math.PI / 180));
+                                Vector checkVector1 = point - hitRotationPoint;
 
                                 if (checkVector1.Length < pointSize)
                                 {

+ 16 - 6
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.protected.cs

@@ -77,12 +77,20 @@ namespace ComPDFKit.Tool.DrawTool
         /// <summary>
         /// Current set of drawing rectangles (original data).
         /// </summary>
-        protected Rect SetDrawRect { get; set; } = new Rect(0, 0, 0, 0);
+        protected Rect SetDrawRect
+        {
+            get;
+            set;
+        } = new Rect(0, 0, 0, 0);
 
         /// <summary>
         /// Current drawing rectangle (calculated during operation).
         /// </summary>
-        protected Rect drawRect { get; set; } = new Rect(0, 0, 0, 0);
+        protected Rect drawRect
+        {
+            get;
+            set;
+        } = new Rect(0, 0, 0, 0);
 
         /// <summary>
         /// Maximum range that can be drawn.
@@ -135,7 +143,7 @@ namespace ComPDFKit.Tool.DrawTool
 
         protected double PDFViewerActualHeight { get; set; } = 0;
 
-        protected double rotateAngle { get; set; } = 0;
+        protected int rotateAngle { get; set; } = 0;
 
         protected double rectPadding = 6;
 
@@ -260,7 +268,7 @@ namespace ComPDFKit.Tool.DrawTool
             }
             if (hitControlType == PointControlType.Rotate)
             {
-                return SetRotate(mousePoint);
+                return SetRotateByMousePoint(mousePoint);
             }
 
             if (!isOutSideScaling)
@@ -299,12 +307,13 @@ namespace ComPDFKit.Tool.DrawTool
 
             return new Size(width, height);
         }
-        private bool SetRotate(Point mousePoint)
+
+        private bool SetRotateByMousePoint(Point mousePoint)
         {
             dragRotationPoint = mousePoint;
             Vector moveVector = (mousePoint - centerPoint);
 
-            rotateAngle = Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI;
+            rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI);
 
             return false;
         }
@@ -1261,6 +1270,7 @@ namespace ComPDFKit.Tool.DrawTool
         protected void InvokeDataChangEvent(bool isFinish)
         {
             selectedRectData.Square = GetRect();
+            selectedRectData.rotationAngle = rotateAngle;
             if (isFinish)
             {
                 DataChanged?.Invoke(this, selectedRectData);