Browse Source

其他 - 异常处理

liyuxuan 8 months ago
parent
commit
f879b36cde

+ 60 - 45
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.Command.cs

@@ -33,7 +33,7 @@ namespace ComPDFKit.Tool
             public bool StartCommand { get; set; }
 
             public CPDFEditType PDFEditType { get; set; }
-             
+
             public AnnotParam CurrentParam { get; set; } = null;
         }
 
@@ -263,21 +263,29 @@ namespace ComPDFKit.Tool
                             break;
                         }
                     }
-                    if (Clipboard.ContainsText())
+                    try
                     {
-                        if (!string.IsNullOrEmpty(Clipboard.GetText()))
+                        if (Clipboard.ContainsText())
                         {
-                            e.CanExecute = true;
+                            if (!string.IsNullOrEmpty(Clipboard.GetText()))
+                            {
+                                e.CanExecute = true;
+                            }
                         }
-                    }
 
-                    if (Clipboard.ContainsImage())
-                    {
-                        if (Clipboard.GetImage() != null)
+                        if (Clipboard.ContainsImage())
                         {
-                            e.CanExecute = true;
+                            if (Clipboard.GetImage() != null)
+                            {
+                                e.CanExecute = true;
+                            }
                         }
                     }
+                    catch (Exception ex)
+                    {
+
+                    }
+
                     break;
             }
         }
@@ -324,28 +332,49 @@ namespace ComPDFKit.Tool
 
         private void SetEditCopyData()
         {
-            if (Clipboard.ContainsText())
+            try
             {
-                string copyText = Clipboard.GetText();
-                bool findCopy = false;
-                if (lastPDFEditArgsList != null && lastPDFEditArgsList.Count > 0)
+                if (Clipboard.ContainsText())
                 {
-                    foreach (PDFEditCommandData checkItem in lastPDFEditArgsList)
+                    string copyText = Clipboard.GetText();
+                    bool findCopy = false;
+                    if (lastPDFEditArgsList != null && lastPDFEditArgsList.Count > 0)
+                    {
+                        foreach (PDFEditCommandData checkItem in lastPDFEditArgsList)
+                        {
+                            if (checkItem.EditType == CPDFEditType.EditText && copyText == checkItem.TextContent)
+                            {
+                                findCopy = true;
+                            }
+                        }
+                    }
+                    if (findCopy == false)
                     {
-                        if (checkItem.EditType == CPDFEditType.EditText && copyText == checkItem.TextContent)
+                        lastPDFEditArgsList?.Clear();
+                        if (string.IsNullOrEmpty(copyText) == false)
                         {
-                            findCopy = true;
+                            PDFEditCommandData commandData = new PDFEditCommandData();
+                            commandData.EditType = CPDFEditType.EditText;
+                            commandData.TextContent = copyText;
+                            int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
+                            RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
+                            Rect rect = render.PaintRect;
+
+                            Point centerPoint = new Point(
+                                rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
+                                rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
+                            commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, 0, 0));
+                            lastPDFEditArgsList.Add(commandData);
                         }
                     }
                 }
-                if (findCopy == false)
+                else if (Clipboard.ContainsImage())
                 {
-                    lastPDFEditArgsList?.Clear();
-                    if (string.IsNullOrEmpty(copyText) == false)
+                    if (Clipboard.GetImage() != null)
                     {
+                        BitmapSource bitmapSource = Clipboard.GetImage();
                         PDFEditCommandData commandData = new PDFEditCommandData();
-                        commandData.EditType = CPDFEditType.EditText;
-                        commandData.TextContent = copyText;
+                        commandData.EditType = CPDFEditType.EditImage;
                         int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
                         RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
                         Rect rect = render.PaintRect;
@@ -353,29 +382,15 @@ namespace ComPDFKit.Tool
                         Point centerPoint = new Point(
                             rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
                             rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
-                        commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, 0, 0));
+                        commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, bitmapSource.PixelWidth, bitmapSource.PixelHeight));
+                        lastPDFEditArgsList.Clear();
                         lastPDFEditArgsList.Add(commandData);
                     }
                 }
             }
-            else if (Clipboard.ContainsImage())
+            catch (Exception ex)
             {
-                if (Clipboard.GetImage() != null)
-                {
-                    BitmapSource bitmapSource = Clipboard.GetImage();
-                    PDFEditCommandData commandData = new PDFEditCommandData();
-                    commandData.EditType = CPDFEditType.EditImage;
-                    int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
-                    RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
-                    Rect rect = render.PaintRect;
-
-                    Point centerPoint = new Point(
-                        rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
-                        rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
-                    commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, bitmapSource.PixelWidth, bitmapSource.PixelHeight));
-                    lastPDFEditArgsList.Clear();
-                    lastPDFEditArgsList.Add(commandData);
-                }
+
             }
         }
 
@@ -387,11 +402,11 @@ namespace ComPDFKit.Tool
                 CPDFEditPage.CopyPage.ReleaseCopyEditAreaList();
             }
 
-            lastPDFEditArgsList.Clear();
-            Clipboard.Clear();
-
             try
             {
+                lastPDFEditArgsList.Clear();
+                Clipboard.Clear();
+
                 if (currentEditAreaObject != null)
                 {
                     PDFEditCommandData commandData = new PDFEditCommandData();
@@ -714,10 +729,10 @@ namespace ComPDFKit.Tool
                     }
                     else
                     {
-                        if (Clipboard.GetImage() != null)
+                        BitmapSource bitmapSource = BinaryStructConverter.ImageFromClipboardDib();
+                        if (bitmapSource != null)
                         {
                             PDFEditHistory createHistory = new PDFEditHistory();
-                            BitmapSource bitmapSource = BinaryStructConverter.ImageFromClipboardDib();
 
                             byte[] imageData = new byte[bitmapSource.PixelWidth * bitmapSource.PixelHeight * 4];
                             if (bitmapSource.Format != PixelFormats.Bgra32)
@@ -1456,7 +1471,7 @@ namespace ComPDFKit.Tool
                         break;
                 }
 
-                PasteParam= annotHistory.CurrentParam;
+                PasteParam = annotHistory.CurrentParam;
                 PDFViewer.UndoManager.AddHistory(annotHistory);
             }
         }

+ 9 - 5
Demo/Examples/ComPDFKit.Tool/DrawTool/MultiSelectedRect.cs

@@ -303,7 +303,7 @@ namespace ComPDFKit.Tool.DrawTool
                 case MulitiDrawMoveType.Default:
                     Dispatcher.Invoke(() =>
                     {
-                        if(drawDefaultRect.IsEmpty==false && drawDefaultRect.Width>0 && drawDefaultRect.Height>0)
+                        if (drawDefaultRect.IsEmpty == false && drawDefaultRect.Width > 0 && drawDefaultRect.Height > 0)
                         {
                             drawDC = RenderOpen();
                             CalcControlPoint(drawDefaultRect);
@@ -358,7 +358,7 @@ namespace ComPDFKit.Tool.DrawTool
                             drawDC?.Close();
                             drawDC = null;
                         }
-                        
+
                     });
                     break;
                 case MulitiDrawMoveType.Alone:
@@ -926,6 +926,10 @@ namespace ComPDFKit.Tool.DrawTool
             {
                 TmpDown = maxRect.Bottom;
             }
+            if (TmpRight - TmpLeft < 0.0 || TmpDown - TmpUp < 0.0)
+            {
+                return false;
+            }
             drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
             moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
             return true;
@@ -1181,7 +1185,7 @@ namespace ComPDFKit.Tool.DrawTool
                             break;
                         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))
                             {
                                 return (PointControlType)i;
@@ -1201,8 +1205,8 @@ namespace ComPDFKit.Tool.DrawTool
                 if (drawDefaultRect.Contains(point))
                 {
                     Rect rect = new Rect(
-                        Math.Max(drawDefaultRect.X + rectPadding, 0), 
-                        Math.Max(drawDefaultRect.Y + rectPadding,0),
+                        Math.Max(drawDefaultRect.X + rectPadding, 0),
+                        Math.Max(drawDefaultRect.Y + rectPadding, 0),
                         drawDefaultRect.Width - 2 * rectPadding,
                         drawDefaultRect.Height - 2 * rectPadding);
                     if (rect.Contains(point))

+ 6 - 1
Demo/Examples/ComPDFKit.Tool/DrawTool/PageSelectedRect.cs

@@ -886,6 +886,11 @@ namespace ComPDFKit.Tool.DrawTool
             {
                 TmpDown = maxRect.Bottom;
             }
+
+            if (TmpRight - TmpLeft < 0.0 || TmpDown - TmpUp < 0.0)
+            {
+                return false;
+            }
             drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
             moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
             return true;
@@ -1033,7 +1038,7 @@ namespace ComPDFKit.Tool.DrawTool
                             break;
                         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))
                             {
                                 return (PointControlType)i;

+ 228 - 221
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.protected.cs

@@ -229,282 +229,289 @@ namespace ComPDFKit.Tool.DrawTool
         /// <returns></returns>
         protected bool NormalScaling(Point mousePoint)
         {
-            double left = 0, right = 0, top = 0, bottom = 0;
-            double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
-            double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
+            try
+            {
+                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);
+                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)
+                switch (hitControlType)
+                {
+                    case PointControlType.LeftTop:
                         {
-                            Size size = GetProportionalScalingSize(right - left, bottom - top);
-                            left = right - size.Width;
-                            top = bottom - size.Height;
-                            if(left < maxRect.Left)
+                            left = centerPoint.X + moveVector.X;
+                            right = cacheRect.Right;
+                            top = centerPoint.Y + moveVector.Y;
+                            bottom = cacheRect.Bottom;
+                            if (isProportionalScaling)
                             {
-                                double tmpWidth = right - left;
-                                left = maxRect.Left;
-                                double width = right - left;
-                                double height = (bottom - top) * width / tmpWidth;
-                                top = bottom - height;
+                                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;
+                                }
                             }
-
-                            if (top < maxRect.Top)
+                            else
                             {
-                                double tmpHeight = bottom - top;
-                                top = maxRect.Top;
-                                double height = bottom - top;
-                                double width = (right - left) * height / tmpHeight;
-                                left = right - width;
+                                if (left + minWidth > right)
+                                {
+                                    left = right - minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    top = bottom - minHeight;
+                                }
                             }
                         }
-                        else
+                        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;
                             }
-
-                            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;
+                        break;
 
-                case PointControlType.LeftBottom:
-                    {
-                        left = centerPoint.X + moveVector.X;
-                        right = cacheRect.Right;
-                        top = cacheRect.Top;
-                        bottom = centerPoint.Y + moveVector.Y;
-                        if (isProportionalScaling)
+                    case PointControlType.LeftBottom:
                         {
-                            Size size = GetProportionalScalingSize(right - left, bottom - top);
-                            left = right - size.Width;
-                            bottom = top + size.Height;
-                            if (left < maxRect.Left)
+                            left = centerPoint.X + moveVector.X;
+                            right = cacheRect.Right;
+                            top = cacheRect.Top;
+                            bottom = centerPoint.Y + moveVector.Y;
+                            if (isProportionalScaling)
                             {
-                                double tmpWidth = right - left;
-                                left = maxRect.Left;
-                                double width = right - left;
-                                double height = (bottom - top) * width / tmpWidth;
-                                bottom = top + height;
+                                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;
+                                }
                             }
-
-                            if (bottom > maxRect.Bottom)
+                            else
                             {
-                                double tmpHeight = bottom - top;
-                                bottom = maxRect.Bottom;
-                                double height = bottom - top;
-                                double width = (right - left) * height / tmpHeight;
-                                left = right - width;
+                                if (left + minWidth > right)
+                                {
+                                    left = right - minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    bottom = top + minHeight;
+                                }
                             }
                         }
-                        else
+                        break;
+
+                    case PointControlType.MiddlBottom:
                         {
-                            if (left + minWidth > right)
-                            {
-                                left = right - minWidth;
-                            }
-                            
+                            left = cacheRect.Left;
+                            right = cacheRect.Right;
+                            top = cacheRect.Top;
+                            bottom = centerPoint.Y + moveVector.Y;
                             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;
+                        break;
 
-                case PointControlType.RightBottom:
-                    {
-                        left = cacheRect.Left;
-                        right = centerPoint.X + moveVector.X;
-                        top = cacheRect.Top;
-                        bottom = centerPoint.Y + moveVector.Y;
-                        if (isProportionalScaling)
+                    case PointControlType.RightBottom:
                         {
-                            Size size = GetProportionalScalingSize(right - left, bottom - top);
-                            right = left + size.Width;
-                            bottom = top + size.Height;
-                            if (right > maxRect.Right)
+                            left = cacheRect.Left;
+                            right = centerPoint.X + moveVector.X;
+                            top = cacheRect.Top;
+                            bottom = centerPoint.Y + moveVector.Y;
+                            if (isProportionalScaling)
                             {
-                                double tmpWidth = right - left;
-                                right = maxRect.Right;
-                                double width = right - left;
-                                double height = (bottom - top) * width / tmpWidth;
-                                bottom = top + height;
+                                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;
+                                }
                             }
-
-                            if (bottom > maxRect.Bottom)
+                            else
                             {
-                                double tmpHeight = bottom - top;
-                                bottom = maxRect.Bottom;
-                                double height = bottom - top;
-                                double width = (right - left) * height / tmpHeight;
-                                right = left + width;
+                                if (left + minWidth > right)
+                                {
+                                    right = left + minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    bottom = top + minHeight;
+                                }
                             }
                         }
-                        else
+                        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;
                             }
-
-                            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;
+                        break;
 
-                case PointControlType.RightTop:
-                    {
-                        left = cacheRect.Left;
-                        right = centerPoint.X + moveVector.X;
-                        top = centerPoint.Y + moveVector.Y;
-                        bottom = cacheRect.Bottom;
-                        if (isProportionalScaling)
+                    case PointControlType.RightTop:
                         {
-                            Size size = GetProportionalScalingSize(right - left, bottom - top);
-                            right = left + size.Width;
-                            top = bottom - size.Height;
-                            if (right > maxRect.Right)
+                            left = cacheRect.Left;
+                            right = centerPoint.X + moveVector.X;
+                            top = centerPoint.Y + moveVector.Y;
+                            bottom = cacheRect.Bottom;
+                            if (isProportionalScaling)
                             {
-                                double tmpWidth = right - left;
-                                right = maxRect.Right;
-                                double width = right - left;
-                                double height = (bottom - top) * width / tmpWidth;
-                                top =  bottom - height;
+                                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;
+                                }
                             }
-
-                            if (top < maxRect.Top)
+                            else
                             {
-                                double tmpHeight = bottom - top;
-                                top = maxRect.Top;
-                                double height = bottom - top;
-                                double width = (right - left) * height / tmpHeight;
-                                right = left + width;
+                                if (left + minWidth > right)
+                                {
+                                    right = left + minWidth;
+                                }
+
+                                if (top + minHeight > bottom)
+                                {
+                                    top = bottom - minHeight;
+                                }
                             }
                         }
-                        else
-                        {
-                            if (left + minWidth > right)
-                            {
-                                right = left + minWidth;
-                            }
+                        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;
+                        break;
 
-                case PointControlType.MiddleTop:
-                    {
-                        left = cacheRect.Left;
-                        right = cacheRect.Right;
-                        top = centerPoint.Y + moveVector.Y;
-                        bottom = cacheRect.Bottom;
-                        if (top + minHeight > bottom)
+                    case PointControlType.Body:
+                    case PointControlType.Line:
                         {
-                            top = bottom - minHeight;
+                            Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
+                            left = cacheRect.Left + OffsetPos.X;
+                            right = cacheRect.Right + OffsetPos.X;
+                            top = cacheRect.Top + OffsetPos.Y;
+                            bottom = cacheRect.Bottom + OffsetPos.Y;
                         }
-                    }
-                    break;
+                        break;
 
-                case PointControlType.Body:
-                case PointControlType.Line:
-                    {
-                        Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
-                        left = cacheRect.Left + OffsetPos.X;
-                        right = cacheRect.Right + OffsetPos.X;
-                        top = cacheRect.Top + OffsetPos.Y;
-                        bottom = cacheRect.Bottom + OffsetPos.Y;
-                    }
-                    break;
+                    default:
+                        break;
+                }
 
-                default:
-                    break;
-            }
+                if (left < maxRect.Left)
+                {
+                    left = maxRect.Left;
+                }
 
-            if (left < maxRect.Left)
-            {
-                left = maxRect.Left;
-            }
+                if (top < maxRect.Top)
+                {
+                    top = maxRect.Top;
+                }
 
-            if (top < maxRect.Top)
-            {
-                top = maxRect.Top;
-            }
+                if (right > maxRect.Right)
+                {
+                    right = maxRect.Right;
+                }
 
-            if (right > maxRect.Right)
-            {
-                right = maxRect.Right;
-            }
+                if (bottom > maxRect.Bottom)
+                {
+                    bottom = maxRect.Bottom;
+                }
 
-            if (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)
             {
-                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;
+            return false;
         }
 
         /// <summary>
@@ -646,19 +653,19 @@ namespace ComPDFKit.Tool.DrawTool
             }
             drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
         }
-        
+
         protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
         {
             GeometryGroup controlGroup = new GeometryGroup();
             controlGroup.FillRule = FillRule.Nonzero;
-            
+
             //Left Top Corner
             if (!ignoreList.Contains(PointControlType.LeftTop))
             {
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[0].X - PointSize, controlPoints[0].Y - PointSize, PointSize, PointSize * 4));
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[0].X - PointSize, controlPoints[0].Y - PointSize, PointSize * 4, PointSize));
             }
-            
+
             //Left Center
             if (!ignoreList.Contains(PointControlType.LeftMiddle))
             {
@@ -671,7 +678,7 @@ namespace ComPDFKit.Tool.DrawTool
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[2].X - PointSize, controlPoints[2].Y - PointSize * 3, PointSize, PointSize * 4));
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[2].X - PointSize, controlPoints[2].Y, PointSize * 4, PointSize));
             }
-            
+
             //Bottom Center
             if (!ignoreList.Contains(PointControlType.MiddlBottom))
             {
@@ -681,27 +688,27 @@ namespace ComPDFKit.Tool.DrawTool
             //Bottom Right Corner
             if (!ignoreList.Contains(PointControlType.RightBottom))
             {
-                drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X , controlPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
+                drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X, controlPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X - PointSize * 3, controlPoints[4].Y, PointSize * 4, PointSize));
             }
-            
+
             //Right Center
             if (!ignoreList.Contains(PointControlType.RightMiddle))
             {
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[5].X, (controlPoints[5].Y + controlPoints[5].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
             }
-            
+
             //Right Top Corner
             if (!ignoreList.Contains(PointControlType.RightTop))
             {
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[6].X, controlPoints[6].Y - PointSize, PointSize, PointSize * 4));
                 drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[6].X - PointSize * 4, controlPoints[6].Y - PointSize, PointSize * 4, PointSize));
             }
-            
+
             //Top Center
             if (!ignoreList.Contains(PointControlType.MiddleTop))
             {
-                drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlPoints[7].X + controlPoints[7].X - PointSize * 5) / 2, controlPoints[7].Y-PointSize, PointSize * 5, PointSize));
+                drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlPoints[7].X + controlPoints[7].X - PointSize * 5) / 2, controlPoints[7].Y - PointSize, PointSize * 5, PointSize));
             }
             drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
         }