Преглед на файлове

ComPDFKit.Tool(win) - Stamp注释旋转兼容页面渲染

TangJinZhou преди 2 седмици
родител
ревизия
166904adfc

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

@@ -268,12 +268,12 @@ namespace ComPDFKit.Tool
             createContentEditType = editType;
             return true;
         }
+
         public CPDFEditType GetCreateContentEditType()
         {
             return createContentEditType;
         }
 
-
         public void ClearSelect()
         {
             /// Clear some UI effects of other modules
@@ -1361,19 +1361,25 @@ namespace ComPDFKit.Tool
                                         (mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
                                         stampRect.Width, stampRect.Height)
                                         );
+
+                                    if (annotation.Page.Rotation % 2 != 0)
+                                    {
+                                        PDFRect = RotateRect90(PDFRect);
+                                    }
+
                                     CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
-                                    annotation.SetRect(cStampRect);
                                     annotation.SetSourceRect(cStampRect);
+                                    (annotation as CPDFStampAnnotation).AnnotationRotator.SetRotation(annotation.Page.Rotation * 90);
                                     annotation.UpdateAp();
                                     e.IsCreate = true;
                                     e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
                                     e.Data = GetAnnotExpandObject(annotation);
-                                    StampAnnotHistory freeTextAnnotHistory = new StampAnnotHistory();
+                                    StampAnnotHistory stampAnnotHistory = new StampAnnotHistory();
                                     AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
                                     annotParam.AnnotIndex = annotation.Page.GetAnnotCount() - 1;
-                                    freeTextAnnotHistory.CurrentParam = (StampParam)annotParam;
-                                    freeTextAnnotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
-                                    viewerTool.GetCPDFViewer().UndoManager.AddHistory(freeTextAnnotHistory);
+                                    stampAnnotHistory.CurrentParam = annotParam;
+                                    stampAnnotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
+                                    viewerTool.GetCPDFViewer().UndoManager.AddHistory(stampAnnotHistory);
                                 }
                                 viewerTool.GetCPDFViewer().UpdateAnnotFrame();
                             }
@@ -2401,5 +2407,19 @@ namespace ComPDFKit.Tool
 
             MouseRightButtonDownHandler?.Invoke(sender, e);
         }
+
+        private Rect RotateRect90(Rect rect)
+        {
+            double centerX = rect.Left + rect.Width / 2;
+            double centerY = rect.Top + rect.Height / 2;
+
+            double newWidth = rect.Height;
+            double newHeight = rect.Width;
+
+            double newLeft = centerX - newWidth / 2.0;
+            double newTop = centerY - newHeight / 2.0;
+
+            return new Rect(newLeft, newTop, newWidth, newHeight);
+        }
     }
 }

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

@@ -605,7 +605,6 @@ namespace ComPDFKit.Tool
                     break;
             }
 
-            stampAnnot.AnnotationRotator.SetRotation(stampParam.Rotation);
             DefaultAnnot(cPDFAnnotation, stampParam);
         }
 

+ 1 - 0
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.cs

@@ -645,6 +645,7 @@ namespace ComPDFKit.Tool.DrawTool
                     rotateRect.Y += renderData.PageBound.Y - renderData.CropTop * annotData.CurrentZoom;
                     SetRect(rotateRect, annotData.CurrentZoom);
                     rotateAngle = -(annotData.Annot as CPDFStampAnnotation).AnnotationRotator.GetRotation();
+                    pageRotation = annotData.Annot.Page.Rotation;
                 }
                 else
                 {

+ 80 - 9
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.protected.cs

@@ -142,6 +142,8 @@ namespace ComPDFKit.Tool.DrawTool
 
         protected int rotateAngle { get; set; } = 0;
 
+        protected int pageRotation { get; set; } = 0;
+
         protected double rectPadding = 6;
 
         protected double currentZoom = 1;
@@ -182,6 +184,27 @@ namespace ComPDFKit.Tool.DrawTool
             if (canRotate)
             {
                 rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
+                switch (pageRotation)
+                {
+                    case 0:
+                        rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
+                        break;
+
+                    case 1:
+                        rotationPoint = new Point(currentRect.Right + 30, centerPoint.Y);
+                        break;
+
+                    case 2:
+                        rotationPoint = new Point(centerPoint.X, currentRect.Bottom + 30);
+                        break;
+
+                    case 3:
+                        rotationPoint = new Point(currentRect.Left - 30, centerPoint.Y);
+                        break;
+
+                    default:
+                        break;
+                }
             }
         }
 
@@ -266,9 +289,11 @@ namespace ComPDFKit.Tool.DrawTool
             {
                 return false;
             }
+
             if (hitControlType == PointControlType.Rotate)
             {
-                return SetRotateByMousePoint(mousePoint);
+                SetRotateByMousePoint(mousePoint);
+                return false;
             }
 
             if (!isOutSideScaling)
@@ -314,13 +339,11 @@ namespace ComPDFKit.Tool.DrawTool
             return new Size(width, height);
         }
 
-        private bool SetRotateByMousePoint(Point mousePoint)
+        private void SetRotateByMousePoint(Point mousePoint)
         {
             dragRotationPoint = mousePoint;
             Vector moveVector = (mousePoint - centerPoint);
-
-            rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI);
-            return false;
+            rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180  / Math.PI) - pageRotation * 90;
         }
 
         /// <summary>
@@ -1223,8 +1246,33 @@ namespace ComPDFKit.Tool.DrawTool
                 double angleInRadians = rotateAngle * (Math.PI / 180);
                 double sinValue = Math.Sin(angleInRadians);
                 double cosValue = Math.Cos(angleInRadians);
-                double rotatedX = currentRotationPoint.X - pointSize * sinValue;
-                double rotatedY = currentRotationPoint.Y + pointSize * cosValue;
+                double rotatedX = 0;
+                double rotatedY = 0;
+                switch (pageRotation)
+                {
+                    case 0:
+                         rotatedX = currentRotationPoint.X - pointSize * sinValue;
+                         rotatedY = currentRotationPoint.Y + pointSize * cosValue;
+                        break;
+
+                    case 1:
+                        rotatedX = currentRotationPoint.X - pointSize * cosValue;
+                        rotatedY = currentRotationPoint.Y + pointSize * sinValue;
+                        break;
+
+                    case 2:
+                        rotatedX = currentRotationPoint.X + pointSize * sinValue;
+                        rotatedY = currentRotationPoint.Y - pointSize * cosValue;
+                        break;
+
+                    case 3:
+                        rotatedX = currentRotationPoint.X + pointSize * sinValue;
+                        rotatedY = currentRotationPoint.Y - pointSize * cosValue;
+                        break;
+
+                    default:
+                        break;
+                }
 
                 GeometryGroup rotateGroup = new GeometryGroup();
                 LineGeometry moveLineGeometry = new LineGeometry(centerPoint, new Point(rotatedX, rotatedY));
@@ -1235,6 +1283,31 @@ namespace ComPDFKit.Tool.DrawTool
                 {
                     rotateGroup.Children.Remove(moveLineGeometry);
                     LineGeometry stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y + pointSize));
+                    switch (pageRotation)
+                    {
+                        case 0:
+                            stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y + pointSize));
+
+                            break;
+
+                        case 1:
+                            stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X - pointSize, currentRotationPoint.Y ));
+
+                            break;
+
+                        case 2:
+                            stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y - pointSize));
+
+                            break;
+
+                        case 3:
+                            stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X + pointSize, currentRotationPoint.Y));
+                            break;
+
+                        default:
+                            break;
+                    }
+
                     rotateGroup.Children.Add(stopLineGeometry);
                     drawingContext.PushTransform(rotateTransform);
                 }
@@ -1275,8 +1348,6 @@ namespace ComPDFKit.Tool.DrawTool
                 drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
                 drawingContext.Pop();
             }
-
-
         }
 
         protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)