Browse Source

ComPDFKit.Tool(pdftech) - 注释旋部分转效果

liyuxuan 9 tháng trước cách đây
mục cha
commit
76e7832bd8

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

@@ -1650,7 +1650,7 @@ namespace ComPDFKit.Tool
 
 
                     Cursor oldCursor = viewerTool.Cursor;
                     Cursor oldCursor = viewerTool.Cursor;
                     Cursor newCursor = viewerTool.GetMoveSelectedRectCursor();
                     Cursor newCursor = viewerTool.GetMoveSelectedRectCursor();
-                    if (oldCursor != newCursor)
+                    if (oldCursor != newCursor || viewerTool.PDFViewer.Cursor!=newCursor)
                     {
                     {
                         viewerTool.PDFViewer.Cursor = viewerTool.Cursor = newCursor;
                         viewerTool.PDFViewer.Cursor = viewerTool.Cursor = newCursor;
                     }
                     }

+ 27 - 0
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.SelectedRect.cs

@@ -22,11 +22,13 @@ namespace ComPDFKit.Tool
         public event EventHandler<SelectedAnnotData> SelectedDataChanging;
         public event EventHandler<SelectedAnnotData> SelectedDataChanging;
         public event EventHandler<SelectedAnnotData> SelectedDataChanged;
         public event EventHandler<SelectedAnnotData> SelectedDataChanged;
 
 
+        private bool canRotateAnnot;
         private void InsertSelectedRectView()
         private void InsertSelectedRectView()
         {
         {
             int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
             int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
             CustomizeLayer customizeLayer = new CustomizeLayer();
             CustomizeLayer customizeLayer = new CustomizeLayer();
             SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.Annot);
             SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.Annot);
+            selectedRect.CanRotate=canRotateAnnot;
             selectedRect.SetDrawMoveType(DrawMoveType.kDefault);
             selectedRect.SetDrawMoveType(DrawMoveType.kDefault);
             customizeLayer.Children.Add(selectedRect);
             customizeLayer.Children.Add(selectedRect);
             selectedRect.DataChanged += SelectedRect_DataChanged;
             selectedRect.DataChanged += SelectedRect_DataChanged;
@@ -191,5 +193,30 @@ namespace ComPDFKit.Tool
             }
             }
             return false;
             return false;
         }
         }
+
+        public bool SetRotateAnnot(bool canRotate)
+        {
+            if (canRotateAnnot != canRotate)
+            {
+                canRotateAnnot = canRotate;
+                try
+                {
+                    BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
+                    SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
+                    selectedRect.CanRotate = canRotate;
+                }
+                catch (Exception ex)
+                {
+                }
+                return false;
+            }
+
+            return true;
+        }
+
+        public bool GetRotateAnnot()
+        {
+            return canRotateAnnot;
+        }
     }
     }
 }
 }

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

@@ -55,6 +55,9 @@ namespace ComPDFKit.Tool.DrawTool
     public enum DrawMoveType
     public enum DrawMoveType
     {
     {
         kDefault,
         kDefault,
+        /// <summary>
+        /// 移动画线
+        /// </summary>
         kReferenceLine,
         kReferenceLine,
     }
     }
 
 
@@ -72,42 +75,11 @@ namespace ComPDFKit.Tool.DrawTool
 
 
         public AnnotData annotData { get; set; }
         public AnnotData annotData { get; set; }
 
 
+        public double Angle {  get; set; }
     }
     }
 
 
     public partial class SelectedRect : DrawingVisual
     public partial class SelectedRect : DrawingVisual
     {
     {
-
-        /// <summary>
-        /// Re-layout child elements
-        /// </summary>
-        public void Arrange()
-        {
-            foreach (Visual child in Children)
-            {
-                if (!(child is UIElement))
-                {
-                    continue;
-                }
-                UIElement checkChild = child as UIElement;
-                try
-                {
-                    double left = Canvas.GetLeft(checkChild);
-                    double top = Canvas.GetTop(checkChild);
-                    double width = (double)checkChild.GetValue(FrameworkElement.WidthProperty);
-                    double height = (double)checkChild.GetValue(FrameworkElement.HeightProperty);
-                    checkChild.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
-                    checkChild.Arrange(new Rect(
-                        double.IsNaN(left) ? 0 : left,
-                        double.IsNaN(top) ? 0 : top,
-                        double.IsNaN(width) ? checkChild.DesiredSize.Width : width,
-                        double.IsNaN(height) ? checkChild.DesiredSize.Height : height));
-                }
-                catch (Exception ex)
-                {
-
-                }
-            }
-        }
         protected DefaultDrawParam DrawParam = new DefaultDrawParam();
         protected DefaultDrawParam DrawParam = new DefaultDrawParam();
 
 
         protected DrawingContext drawDC { get; set; }
         protected DrawingContext drawDC { get; set; }
@@ -127,7 +99,10 @@ namespace ComPDFKit.Tool.DrawTool
         protected bool isSelected = false;
         protected bool isSelected = false;
 
 
         protected SelectedType selectedType = SelectedType.None;
         protected SelectedType selectedType = SelectedType.None;
-
+        public bool CanRotate {  get; set; }
+        private double angle = 0;
+        private Point rotateCenter= new Point(0,0);
+        private int rotateline = 25;
         public SelectedType GetSelectedType()
         public SelectedType GetSelectedType()
         {
         {
             return selectedType;
             return selectedType;
@@ -177,6 +152,7 @@ namespace ComPDFKit.Tool.DrawTool
                 {
                 {
                     cacheRect = drawRect;
                     cacheRect = drawRect;
                 }
                 }
+                rotateCenter = new Point(drawRect.Left + drawRect.Width / 2, drawRect.Top + drawRect.Height / 2);
             }
             }
         }
         }
 
 
@@ -242,6 +218,8 @@ namespace ComPDFKit.Tool.DrawTool
                     return Cursors.Arrow;
                     return Cursors.Arrow;
                 case PointControlType.Line:
                 case PointControlType.Line:
                     return Cursors.SizeAll;
                     return Cursors.SizeAll;
+                case PointControlType.Rotate:
+                    return Cursors.Arrow;
                 default:
                 default:
                     return Cursors.Arrow;
                     return Cursors.Arrow;
             }
             }
@@ -254,53 +232,101 @@ namespace ComPDFKit.Tool.DrawTool
             selectedType = type;
             selectedType = type;
         }
         }
 
 
-        public void Draw()
+        private void DrawNormal(DrawingContext drawDC)
         {
         {
-            Dispatcher.Invoke(() =>
+            Rect currentRect = SetDrawRect;
+           
+            switch (currentDrawMoveType)
             {
             {
-                Rect currentRect = SetDrawRect;
-                drawDC = RenderOpen();
-                switch (currentDrawMoveType)
-                {
-                    case DrawMoveType.kDefault:
-                        currentRect = drawRect;
-                        CalcControlPoint(currentRect);
-                        break;
-                    case DrawMoveType.kReferenceLine:
-                        CalcControlPoint(currentRect);
-                        if (isMouseDown == true)
-                        {
-                            SolidColorBrush moveBrush = DrawParam.AnnotMoveBrush;
-                            Pen movepen = DrawParam.AnnotMovePen;
-                            GetMoveBrushAndPen(ref moveBrush, ref movepen);
-                            DrawMoveBounds(drawDC, hitControlType, movepen, moveBrush, drawRect);
-                        }
-                        break;
-                    default:
-                        break;
-                }
+                case DrawMoveType.kDefault:
+                    currentRect = drawRect;
+                    CalcControlPoint(currentRect);
+                    break;
+                case DrawMoveType.kReferenceLine:
+                    CalcControlPoint(currentRect);
+                    if (isMouseDown == true)
+                    {
+                        SolidColorBrush moveBrush = DrawParam.AnnotMoveBrush;
+                        Pen movepen = DrawParam.AnnotMovePen;
+                        GetMoveBrushAndPen(ref moveBrush, ref movepen);
+                        DrawMoveBounds(drawDC, hitControlType, movepen, moveBrush, drawRect);
+                    }
+                    break;
+                default:
+                    break;
+            }
 
 
-                SolidColorBrush solidColorBrush = DrawParam.AnnotRectFillBrush;
-                Pen pen = DrawParam.AnnotRectLinePen;
-                GetBrushAndPen(ref solidColorBrush, ref pen);
-                drawDC?.DrawRectangle(solidColorBrush, pen, currentRect);
+            SolidColorBrush solidColorBrush = DrawParam.AnnotRectFillBrush;
+            Pen pen = DrawParam.AnnotRectLinePen;
+            GetBrushAndPen(ref solidColorBrush, ref pen);
+            drawDC?.DrawRectangle(solidColorBrush, pen, currentRect);
 
 
-                SolidColorBrush PointBrush = DrawParam.AnnotPointBorderBrush;
-                Pen PointPen = DrawParam.AnnotPointPen;
-                GetPointBrushAndPen(ref PointBrush, ref PointPen);
+            SolidColorBrush PointBrush = DrawParam.AnnotPointBorderBrush;
+            Pen PointPen = DrawParam.AnnotPointPen;
+            GetPointBrushAndPen(ref PointBrush, ref PointPen);
 
 
-                switch (currentDrawPointType)
+            switch (currentDrawPointType)
+            {
+                case DrawPointType.Circle:
+                    DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
+                    break;
+                case DrawPointType.Square:
+                    DrawSquarePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
+                    break;
+                case DrawPointType.Crop:
+                    DrawCropPoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
+                    break;
+            }
+        }
+
+        private void PushRotate(DrawingContext drawDC)
+        {
+            if (CanRotate)
+            {
+                RotateTransform transform = new RotateTransform();
+                transform.Angle = angle;
+                if(hitControlType==PointControlType.Body || hitControlType==PointControlType.Line)
                 {
                 {
-                    case DrawPointType.Circle:
-                        DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
-                        break;
-                    case DrawPointType.Square:
-                        DrawSquarePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
-                        break;
-                    case DrawPointType.Crop:
-                        DrawCropPoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
-                        break;
+                    rotateCenter.X  = drawRect.Left + drawRect.Width / 2;
+                    rotateCenter.Y = drawRect.Top + drawRect.Height / 2;
                 }
                 }
+               
+                transform.CenterX = rotateCenter.X;
+                transform.CenterY = rotateCenter.Y;
+
+                drawDC.PushTransform(transform);
+            }
+        }
+
+        private void PopRotate(DrawingContext drawDC)
+        {
+            if (CanRotate)
+            {
+               
+                drawDC.Pop();
+            }
+        }
+
+        private void DrawRotate(DrawingContext drawDC)
+        {
+            double centerX = drawRect.Left + drawRect.Width / 2;
+            double centerY = drawRect.Top + drawRect.Height / 2;
+
+            Pen PointPen = DrawParam.AnnotPointPen;
+            drawDC.DrawLine(PointPen, new Point(centerX, drawRect.Top), new Point(centerX, drawRect.Top - rotateline));
+            drawDC.DrawEllipse(PointPen.Brush, PointPen, new Point(centerX, drawRect.Top - rotateline), pointSize * 2, pointSize * 2);
+        }
+
+        public void Draw()
+        {
+            Dispatcher.Invoke(() =>
+            {
+                Rect currentRect = SetDrawRect;
+                drawDC = RenderOpen();
+                PushRotate(drawDC);
+                DrawRotate(drawDC);
+                DrawNormal(drawDC);
+                PopRotate(drawDC);
                 drawDC?.Close();
                 drawDC?.Close();
                 drawDC = null;
                 drawDC = null;
             });
             });
@@ -652,7 +678,17 @@ namespace ComPDFKit.Tool.DrawTool
         /// <returns>
         /// <returns>
         /// The control point type
         /// The control point type
         /// </returns>
         /// </returns>
-        public PointControlType GetHitControlIndex(Point point, bool isIgnore=true)
+        public PointControlType GetHitControlIndex(Point point, bool isIgnore = true)
+        {
+            if (CanRotate)
+            {
+                return GetRotateHitIndex(point,isIgnore);
+            }
+
+            return GetNormalHitIndex(point, isIgnore);
+        }
+
+        private PointControlType GetNormalHitIndex(Point point, bool isIgnore = true)
         {
         {
             HitTestResult hitResult = VisualTreeHelper.HitTest(this, point);
             HitTestResult hitResult = VisualTreeHelper.HitTest(this, point);
             if (hitResult != null && hitResult.VisualHit is DrawingVisual)
             if (hitResult != null && hitResult.VisualHit is DrawingVisual)
@@ -671,7 +707,7 @@ namespace ComPDFKit.Tool.DrawTool
                 {
                 {
                     Point checkPoint = controlPoints[i];
                     Point checkPoint = controlPoints[i];
 
 
-                    if (isIgnore&&IgnorePointsList.Contains(checkPoint))
+                    if (isIgnore && IgnorePointsList.Contains(checkPoint))
                     {
                     {
                         continue;
                         continue;
                     }
                     }
@@ -686,13 +722,13 @@ namespace ComPDFKit.Tool.DrawTool
                             break;
                             break;
                         case DrawPointType.Square:
                         case DrawPointType.Square:
 
 
-                            Rect checkRect = new Rect(Math.Max(checkPoint.X - pointSize,0), Math.Max(checkPoint.Y - pointSize,0), pointSize * 2, pointSize * 2);
+                            Rect checkRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
                             if (checkRect.Contains(point))
                             if (checkRect.Contains(point))
                             {
                             {
                                 return (PointControlType)i;
                                 return (PointControlType)i;
                             }
                             }
                             break;
                             break;
-                        
+
                         case DrawPointType.Crop:
                         case DrawPointType.Crop:
                             Rect cropRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
                             Rect cropRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
                             if (cropRect.Contains(point))
                             if (cropRect.Contains(point))
@@ -704,11 +740,12 @@ namespace ComPDFKit.Tool.DrawTool
                             break;
                             break;
                     }
                     }
                 }
                 }
+
                 if (drawRect.Contains(point))
                 if (drawRect.Contains(point))
                 {
                 {
-                    double rectWidth = (drawRect.Width - 2 * rectPadding > 0)? drawRect.Width - 2 * rectPadding: 0;
-                    double rectHeight = (drawRect.Height - 2 * rectPadding > 0)? drawRect.Height - 2 * rectPadding: 0;
-                    Rect rect = new Rect(Math.Max(drawRect.X + rectPadding,0),Math.Max( drawRect.Y + rectPadding,0), rectWidth, rectHeight);
+                    double rectWidth = (drawRect.Width - 2 * rectPadding > 0) ? drawRect.Width - 2 * rectPadding : 0;
+                    double rectHeight = (drawRect.Height - 2 * rectPadding > 0) ? drawRect.Height - 2 * rectPadding : 0;
+                    Rect rect = new Rect(Math.Max(drawRect.X + rectPadding, 0), Math.Max(drawRect.Y + rectPadding, 0), rectWidth, rectHeight);
                     if (rect.Contains(point))
                     if (rect.Contains(point))
                     {
                     {
                         if (!ignoreList.Contains(PointControlType.Body))
                         if (!ignoreList.Contains(PointControlType.Body))
@@ -724,5 +761,99 @@ namespace ComPDFKit.Tool.DrawTool
             }
             }
             return PointControlType.None;
             return PointControlType.None;
         }
         }
+
+        private PointControlType GetRotateHitIndex(Point point, bool isIgnore = true)
+        {
+            HitTestResult hitResult = VisualTreeHelper.HitTest(this, point);
+            if (hitResult != null && hitResult.VisualHit is DrawingVisual)
+            {
+                //旋转回去
+                Point centerPoint = rotateCenter;
+                Vector currentVector = point - centerPoint;
+
+                Matrix matrix = new Matrix();
+                matrix.Rotate(-angle);
+                Vector transVector = matrix.Transform(currentVector);
+                Point checkPos = new Point(centerPoint.X + transVector.X, centerPoint.Y + transVector.Y);
+
+                point= checkPos;
+                List<PointControlType> ignoreList = GetIgnorePoints();
+
+                List<Point> IgnorePointsList = new List<Point>();
+                foreach (PointControlType type in ignoreList)
+                {
+                    if ((int)type < controlPoints.Count)
+                    {
+                        IgnorePointsList.Add(controlPoints[(int)type]);
+                    }
+                }
+                for (int i = 0; i < controlPoints.Count; i++)
+                {
+                    Point checkPoint = controlPoints[i];
+
+                    if (isIgnore && IgnorePointsList.Contains(checkPoint))
+                    {
+                        continue;
+                    }
+                    switch (currentDrawPointType)
+                    {
+                        case DrawPointType.Circle:
+                            Vector checkCircle = checkPoint - point;
+                            if (checkCircle.Length < pointSize)
+                            {
+                                return (PointControlType)i;
+                            }
+                            break;
+                        case DrawPointType.Square:
+
+                            Rect checkRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
+                            if (checkRect.Contains(point))
+                            {
+                                return (PointControlType)i;
+                            }
+                            break;
+
+                        case DrawPointType.Crop:
+                            Rect cropRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
+                            if (cropRect.Contains(point))
+                            {
+                                return (PointControlType)i;
+                            }
+                            break;
+                        default:
+                            break;
+                    }
+                }
+
+                if (drawRect.Contains(point))
+                {
+                    double rectWidth = (drawRect.Width - 2 * rectPadding > 0) ? drawRect.Width - 2 * rectPadding : 0;
+                    double rectHeight = (drawRect.Height - 2 * rectPadding > 0) ? drawRect.Height - 2 * rectPadding : 0;
+                    Rect rect = new Rect(Math.Max(drawRect.X + rectPadding, 0), Math.Max(drawRect.Y + rectPadding, 0), rectWidth, rectHeight);
+                    if (rect.Contains(point))
+                    {
+                        if (!ignoreList.Contains(PointControlType.Body))
+                        {
+                            return PointControlType.Body;
+                        }
+                    }
+                    if (!ignoreList.Contains(PointControlType.Body))
+                    {
+                        return PointControlType.Line;
+                    }
+                }
+
+                double centerX = drawRect.Left + drawRect.Width / 2;
+                double centerY = drawRect.Top + drawRect.Height / 2;
+
+                Point rotatePoint = new Point(centerX, drawRect.Top - rotateline);
+                Vector checkVector = point - rotatePoint;
+                if (checkVector.Length <= pointSize * 2)
+                {
+                    return PointControlType.Rotate;
+                }
+            }
+            return PointControlType.None;
+        }
     }
     }
 }
 }

+ 341 - 4
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.protected.cs

@@ -1,7 +1,10 @@
-using System;
+using ComPDFKit.Import;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Windows;
 using System.Windows;
 using System.Windows.Media;
 using System.Windows.Media;
+using static ComPDFKit.Tool.Help.ImportWin32;
 
 
 namespace ComPDFKit.Tool.DrawTool
 namespace ComPDFKit.Tool.DrawTool
 {
 {
@@ -122,8 +125,8 @@ namespace ComPDFKit.Tool.DrawTool
         protected void CalcControlPoint(Rect currentRect)
         protected void CalcControlPoint(Rect currentRect)
         {
         {
             controlPoints.Clear();
             controlPoints.Clear();
-            int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
-            int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
+            double centerX = (currentRect.Left + currentRect.Right) / 2;
+            double centerY = (currentRect.Top + currentRect.Bottom) / 2;
 
 
             controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
             controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
             controlPoints.Add(new Point(currentRect.Left, centerY));
             controlPoints.Add(new Point(currentRect.Left, centerY));
@@ -228,6 +231,15 @@ namespace ComPDFKit.Tool.DrawTool
         /// <param name="mousePoint">Current mouse position.</param>
         /// <param name="mousePoint">Current mouse position.</param>
         /// <returns></returns>
         /// <returns></returns>
         protected bool NormalScaling(Point mousePoint)
         protected bool NormalScaling(Point mousePoint)
+        {
+            if (CanRotate)
+            {
+                return RotateScaling(mousePoint);
+            }
+            return GenerallyScaling(mousePoint);
+        }
+
+        private bool GenerallyScaling(Point mousePoint)
         {
         {
             try
             try
             {
             {
@@ -480,6 +492,14 @@ namespace ComPDFKit.Tool.DrawTool
                         }
                         }
                         break;
                         break;
 
 
+                    case PointControlType.Rotate:
+                        {
+                            Point rotatPoint = new Point(centerPoint.X, centerPoint.Y - cacheRect.Height / 2 - rotateline);
+                            Vector startVector = rotatPoint - centerPoint;
+                            Vector currentVector = mousePoint - centerPoint;
+                            angle = Vector.AngleBetween(startVector, currentVector);
+                        }
+                        break;
                     default:
                     default:
                         break;
                         break;
                 }
                 }
@@ -514,6 +534,322 @@ namespace ComPDFKit.Tool.DrawTool
             return false;
             return false;
         }
         }
 
 
+        private Point CalcRotateRawPoint(Point calcPoint)
+        {
+            if(CanRotate==false || angle==0)
+            {
+                return calcPoint;
+            }
+
+            //旋转回去
+            Vector currentVector = calcPoint - rotateCenter;
+
+            Matrix matrix = new Matrix();
+            matrix.Rotate(-angle);
+            Vector transVector = matrix.Transform(currentVector);
+            Point checkPos = new Point(rotateCenter.X + transVector.X, rotateCenter.Y + transVector.Y);
+
+            return checkPos;
+        }
+
+
+        private bool RotateScaling(Point uiPoint)
+        {
+            try
+            {
+                //旋转回去
+                Point mousePoint = CalcRotateRawPoint(uiPoint);
+
+                double left = 0, right = 0, top = 0, bottom = 0;
+                double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
+                double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
+
+                Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
+                Point moveVector = (Point)(mousePoint - centerPoint);
+                moveVector = ProportionalScalingOffsetPos(moveVector);
+
+                switch (hitControlType)
+                {
+                    case PointControlType.LeftTop:
+                        {
+                            left = centerPoint.X + moveVector.X;
+                            right = cacheRect.Right;
+                            top = centerPoint.Y + moveVector.Y;
+                            bottom = cacheRect.Bottom;
+                            if (isProportionalScaling)
+                            {
+                                Size size = GetProportionalScalingSize(right - left, bottom - top);
+                                left = right - size.Width;
+                                top = bottom - size.Height;
+                                if (left < maxRect.Left)
+                                {
+                                    double tmpWidth = right - left;
+                                    left = maxRect.Left;
+                                    double width = right - left;
+                                    double height = (bottom - top) * width / tmpWidth;
+                                    top = bottom - height;
+                                }
+
+                                if (top < maxRect.Top)
+                                {
+                                    double tmpHeight = bottom - top;
+                                    top = maxRect.Top;
+                                    double height = bottom - top;
+                                    double width = (right - left) * height / tmpHeight;
+                                    left = right - width;
+                                }
+                            }
+                            else
+                            {
+                                if (left + minWidth > right)
+                                {
+                                    left = right - minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    top = bottom - minHeight;
+                                }
+                            }
+                        }
+                        break;
+
+                    case PointControlType.LeftMiddle:
+                        {
+                            left = centerPoint.X + moveVector.X;
+                            right = cacheRect.Right;
+                            top = cacheRect.Top;
+                            bottom = cacheRect.Bottom;
+                            if (left + minWidth > right)
+                            {
+                                left = right - minWidth;
+                            }
+                        }
+                        break;
+
+                    case PointControlType.LeftBottom:
+                        {
+                            left = centerPoint.X + moveVector.X;
+                            right = cacheRect.Right;
+                            top = cacheRect.Top;
+                            bottom = centerPoint.Y + moveVector.Y;
+                            if (isProportionalScaling)
+                            {
+                                Size size = GetProportionalScalingSize(right - left, bottom - top);
+                                left = right - size.Width;
+                                bottom = top + size.Height;
+                                if (left < maxRect.Left)
+                                {
+                                    double tmpWidth = right - left;
+                                    left = maxRect.Left;
+                                    double width = right - left;
+                                    double height = (bottom - top) * width / tmpWidth;
+                                    bottom = top + height;
+                                }
+
+                                if (bottom > maxRect.Bottom)
+                                {
+                                    double tmpHeight = bottom - top;
+                                    bottom = maxRect.Bottom;
+                                    double height = bottom - top;
+                                    double width = (right - left) * height / tmpHeight;
+                                    left = right - width;
+                                }
+                            }
+                            else
+                            {
+                                if (left + minWidth > right)
+                                {
+                                    left = right - minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    bottom = top + minHeight;
+                                }
+                            }
+                        }
+                        break;
+
+                    case PointControlType.MiddlBottom:
+                        {
+                            left = cacheRect.Left;
+                            right = cacheRect.Right;
+                            top = cacheRect.Top;
+                            bottom = centerPoint.Y + moveVector.Y;
+                            if (top + minHeight > bottom)
+                            {
+                                bottom = top + minHeight;
+                            }
+                        }
+                        break;
+
+                    case PointControlType.RightBottom:
+                        {
+                            left = cacheRect.Left;
+                            right = centerPoint.X + moveVector.X;
+                            top = cacheRect.Top;
+                            bottom = centerPoint.Y + moveVector.Y;
+                            if (isProportionalScaling)
+                            {
+                                Size size = GetProportionalScalingSize(right - left, bottom - top);
+                                right = left + size.Width;
+                                bottom = top + size.Height;
+                                if (right > maxRect.Right)
+                                {
+                                    double tmpWidth = right - left;
+                                    right = maxRect.Right;
+                                    double width = right - left;
+                                    double height = (bottom - top) * width / tmpWidth;
+                                    bottom = top + height;
+                                }
+
+                                if (bottom > maxRect.Bottom)
+                                {
+                                    double tmpHeight = bottom - top;
+                                    bottom = maxRect.Bottom;
+                                    double height = bottom - top;
+                                    double width = (right - left) * height / tmpHeight;
+                                    right = left + width;
+                                }
+                            }
+                            else
+                            {
+                                if (left + minWidth > right)
+                                {
+                                    right = left + minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    bottom = top + minHeight;
+                                }
+                            }
+                        }
+                        break;
+
+                    case PointControlType.RightMiddle:
+                        {
+                            left = cacheRect.Left;
+                            right = centerPoint.X + moveVector.X;
+                            top = cacheRect.Top;
+                            bottom = cacheRect.Bottom;
+                            if (left + minWidth > right)
+                            {
+                                right = left + minWidth;
+                            }
+                        }
+                        break;
+
+                    case PointControlType.RightTop:
+                        {
+                            left = cacheRect.Left;
+                            right = centerPoint.X + moveVector.X;
+                            top = centerPoint.Y + moveVector.Y;
+                            bottom = cacheRect.Bottom;
+                            if (isProportionalScaling)
+                            {
+                                Size size = GetProportionalScalingSize(right - left, bottom - top);
+                                right = left + size.Width;
+                                top = bottom - size.Height;
+                                if (right > maxRect.Right)
+                                {
+                                    double tmpWidth = right - left;
+                                    right = maxRect.Right;
+                                    double width = right - left;
+                                    double height = (bottom - top) * width / tmpWidth;
+                                    top = bottom - height;
+                                }
+
+                                if (top < maxRect.Top)
+                                {
+                                    double tmpHeight = bottom - top;
+                                    top = maxRect.Top;
+                                    double height = bottom - top;
+                                    double width = (right - left) * height / tmpHeight;
+                                    right = left + width;
+                                }
+                            }
+                            else
+                            {
+                                if (left + minWidth > right)
+                                {
+                                    right = left + minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    top = bottom - minHeight;
+                                }
+                            }
+                        }
+                        break;
+
+                    case PointControlType.MiddleTop:
+                        {
+                            left = cacheRect.Left;
+                            right = cacheRect.Right;
+                            top = centerPoint.Y + moveVector.Y;
+                            bottom = cacheRect.Bottom;
+                            if (top + minHeight > bottom)
+                            {
+                                top = bottom - minHeight;
+                            }
+                        }
+                        break;
+
+                    case PointControlType.Body:
+                    case PointControlType.Line:
+                        {
+                            Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(uiPoint -mouseDownPoint)), maxRect);
+                            left = cacheRect.Left + OffsetPos.X;
+                            right = cacheRect.Right + OffsetPos.X;
+                            top = cacheRect.Top + OffsetPos.Y;
+                            bottom = cacheRect.Bottom + OffsetPos.Y;
+                        }
+                        break;
+
+                    case PointControlType.Rotate:
+                        {
+                            Point rotatPoint = new Point(rotateCenter.X, rotateCenter.Y - cacheRect.Height / 2 - rotateline);
+                            Vector startVector = rotatPoint - rotateCenter;
+                            Vector endVector = uiPoint - rotateCenter;
+                            angle = Vector.AngleBetween(startVector, endVector);
+                        }
+                        break;
+                    default:
+                        break;
+                }
+
+                if (left < maxRect.Left)
+                {
+                    left = maxRect.Left;
+                }
+
+                if (top < maxRect.Top)
+                {
+                    top = maxRect.Top;
+                }
+
+                if (right > maxRect.Right)
+                {
+                    right = maxRect.Right;
+                }
+
+                if (bottom > maxRect.Bottom)
+                {
+                    bottom = maxRect.Bottom;
+                }
+
+                drawRect = new Rect(left, top, right - left, bottom - top);
+                moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
+                return true;
+            }
+            catch (Exception ex)
+            {
+            }
+            return false;
+        }
         /// <summary>
         /// <summary>
         /// Proportional scaling offset calibration
         /// Proportional scaling offset calibration
         /// </summary>
         /// </summary>
@@ -648,7 +984,7 @@ namespace ComPDFKit.Tool.DrawTool
                     continue;
                     continue;
                 }
                 }
                 RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
                 RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
-                    PointSize * 2, PointSize * 2), 1, 1);
+                    PointSize * 2, PointSize * 2));
                 controlGroup.Children.Add(rectPoint);
                 controlGroup.Children.Add(rectPoint);
             }
             }
             drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
             drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
@@ -789,6 +1125,7 @@ namespace ComPDFKit.Tool.DrawTool
             selectedRectData.Square = GetRect();
             selectedRectData.Square = GetRect();
             if (isFinish)
             if (isFinish)
             {
             {
+                selectedRectData.Angle=angle;
                 DataChanged?.Invoke(this, selectedRectData);
                 DataChanged?.Invoke(this, selectedRectData);
             }
             }
             else
             else

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

@@ -347,7 +347,7 @@ namespace ComPDFKit.Tool.Help
             bool isBold = false;
             bool isBold = false;
             bool isItalic = false;
             bool isItalic = false;
 
 
-            cPDFEditArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
+            cPDFEditArea.GetTextStyle(ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
             textEditParam.FontName = fontName;
             textEditParam.FontName = fontName;
             textEditParam.FontSize = fontSize;
             textEditParam.FontSize = fontSize;
             textEditParam.FontColor = fontColor;
             textEditParam.FontColor = fontColor;