فهرست منبع

ComPDFKit.Tool(win) - tool层部分线上崩溃异常修复

liyuxuan 5 ماه پیش
والد
کامیت
aca16a72e5

+ 43 - 36
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.Command.cs

@@ -183,45 +183,52 @@ namespace ComPDFKit.Tool
             RoutedUICommand uiCommand = e.Command as RoutedUICommand;
             if (uiCommand != null)
             {
-                PasteParam = null;
-                CommandData commandData = new CommandData();
-                commandData.uIEventArgs = e;
-                commandData.StartCommand = true;
-                CPDFEditType editType = CPDFEditType.None;
-                CommandExecutedHandler?.Invoke(this, commandData);
-                if (e.Handled)
+                try
                 {
-                    return;
-                }
-                if (!IsCanDoCommand)
-                {
-                    CanDoCommand();
-                    return;
+                    PasteParam = null;
+                    CommandData commandData = new CommandData();
+                    commandData.uIEventArgs = e;
+                    commandData.StartCommand = true;
+                    CPDFEditType editType = CPDFEditType.None;
+                    CommandExecutedHandler?.Invoke(this, commandData);
+                    if (e.Handled)
+                    {
+                        return;
+                    }
+                    if (!IsCanDoCommand)
+                    {
+                        CanDoCommand();
+                        return;
+                    }
+                    switch (currentModel)
+                    {
+                        case ToolType.Viewer:
+                            ExecuteViewerCommand(uiCommand);
+                            break;
+                        case ToolType.CreateAnnot:
+                        case ToolType.WidgetEdit:
+                        case ToolType.Pan:
+                            ExecuteAnnotCommand(uiCommand);
+                            break;
+                        case ToolType.ContentEdit:
+                            {
+                                ExecutePDFEditCommand(uiCommand, out editType);
+                            }
+                            break;
+                        case ToolType.Customize:
+                            break;
+                        default:
+                            break;
+                    }
+                    commandData.StartCommand = false;
+                    commandData.PDFEditType = editType;
+                    commandData.CurrentParam = PasteParam;
+                    CommandExecutedHandler?.Invoke(this, commandData);
                 }
-                switch (currentModel)
-                {
-                    case ToolType.Viewer:
-                        ExecuteViewerCommand(uiCommand);
-                        break;
-                    case ToolType.CreateAnnot:
-                    case ToolType.WidgetEdit:
-                    case ToolType.Pan:
-                        ExecuteAnnotCommand(uiCommand);
-                        break;
-                    case ToolType.ContentEdit:
-                        {
-                            ExecutePDFEditCommand(uiCommand, out editType);
-                        }
-                        break;
-                    case ToolType.Customize:
-                        break;
-                    default:
-                        break;
+                catch (Exception ex) 
+                { 
+
                 }
-                commandData.StartCommand = false;
-                commandData.PDFEditType = editType;
-                commandData.CurrentParam = PasteParam;
-                CommandExecutedHandler?.Invoke(this, commandData);
             }
         }
 

+ 17 - 4
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.TextEdit.cs

@@ -1365,6 +1365,21 @@ namespace ComPDFKit.Tool
                 TextEditParam textEditParam = defaultSettingParam.TextEditParamDef;
                 textEditParam.EditIndex = EditPage.GetEditAreaList().Count;
 
+                if (string.IsNullOrEmpty(textEditParam.FontName))
+                {
+                    textEditParam.FontName = "Helvetica";
+                }
+
+                if (textEditParam.FontSize <= 0)
+                {
+                    textEditParam.FontSize = 14;
+                }
+
+                if (textEditParam.FontColor == null || textEditParam.FontColor.Length <= 3)
+                {
+                    textEditParam.FontColor = new byte[3] { 0, 0, 0 };
+                }
+
                 CPDFEditTextArea textArea = EditPage.CreateNewTextArea(
                     DataConversionForWPF.RectConversionForCRect(PDFRect),
                     textEditParam.FontName,
@@ -1400,10 +1415,8 @@ namespace ComPDFKit.Tool
                 PDFViewer.UpdateRenderFrame();
                 return true;
             }
-            else
-            {
-                return false;
-            }
+
+            return false;
         }
 
         public bool MoveEditArea(Point moveOffset)

+ 59 - 51
Demo/Examples/ComPDFKit.Tool/DrawTool/PageSelectedRect.cs

@@ -1006,72 +1006,80 @@ namespace ComPDFKit.Tool.DrawTool
         /// </returns>
         public PointControlType GetHitControlIndex(Point point)
         {
-            HitTestResult hitResult = VisualTreeHelper.HitTest(this, point);
-            if (hitResult != null && hitResult.VisualHit is DrawingVisual)
+            try
             {
-                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++)
+                HitTestResult hitResult = VisualTreeHelper.HitTest(this, point);
+                if (hitResult != null && hitResult.VisualHit is DrawingVisual)
                 {
-                    Point checkPoint = controlPoints[i];
+                    List<PointControlType> ignoreList = GetIgnorePoints();
 
-                    if (IgnorePointsList.Contains(checkPoint))
+                    List<Point> IgnorePointsList = new List<Point>();
+                    foreach (PointControlType type in ignoreList)
                     {
-                        continue;
+                        if ((int)type < controlPoints.Count)
+                        {
+                            IgnorePointsList.Add(controlPoints[(int)type]);
+                        }
                     }
-                    switch (currentDrawPointType)
+                    for (int i = 0; i < controlPoints.Count; i++)
                     {
-                        case DrawPointType.Circle:
-                            Vector checkVector = checkPoint - point;
-                            if (checkVector.Length < pointSize)
-                            {
-                                return (PointControlType)i;
-                            }
-                            break;
-                        case DrawPointType.Square:
+                        Point checkPoint = controlPoints[i];
 
-                            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 (IgnorePointsList.Contains(checkPoint))
+                        {
+                            continue;
+                        }
+                        switch (currentDrawPointType)
+                        {
+                            case DrawPointType.Circle:
+                                Vector checkVector = checkPoint - point;
+                                if (checkVector.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))
-                {
-                    Rect rect = new Rect(Math.Max(drawRect.X + rectPadding, 0), Math.Max(drawRect.Y + rectPadding, 0), drawRect.Width - 2 * rectPadding, drawRect.Height - 2 * rectPadding);
-                    if (rect.Contains(point))
+                    if (drawRect.Contains(point))
                     {
+                        Rect rect = new Rect(Math.Max(drawRect.X + rectPadding, 0), Math.Max(drawRect.Y + rectPadding, 0), drawRect.Width - 2 * rectPadding, drawRect.Height - 2 * rectPadding);
+                        if (rect.Contains(point))
+                        {
+                            if (!ignoreList.Contains(PointControlType.Body))
+                            {
+                                return PointControlType.Body;
+                            }
+                        }
                         if (!ignoreList.Contains(PointControlType.Body))
                         {
-                            return PointControlType.Body;
+                            return PointControlType.Line;
                         }
                     }
-                    if (!ignoreList.Contains(PointControlType.Body))
-                    {
-                        return PointControlType.Line;
-                    }
                 }
             }
+            catch (Exception ex) 
+            { 
+
+            }
+
             return PointControlType.None;
         }