浏览代码

compdfkit(win) - 链接注释页码判断防止崩溃

liuaoran 7 月之前
父节点
当前提交
5349088cc6

+ 14 - 10
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFLinkUI.xaml.cs

@@ -34,7 +34,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
             if (PropertyChanged != null)
             {
                 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
-            } 
+            }
         }
 
         private bool _drawLink;
@@ -99,10 +99,10 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
             DataContext = this;
         }
 
-        public void SetPresentAnnotAttrib(LinkParam param,CPDFLinkAnnotation annot,PDFViewControl view, int PageCount)
+        public void SetPresentAnnotAttrib(LinkParam param, CPDFLinkAnnotation annot, PDFViewControl view, int PageCount)
         {
             linkAnnot = annot;
-            linkParam=param;
+            linkParam = param;
             viewControl = view;
             UrlText.Text = "";
             PageText.Text = "";
@@ -111,7 +111,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
             totalPage = PageCount;
             PagePromptText = Helper.LanguageHelper.PropertyPanelManager.GetString("Holder_Jump") + totalPage;
 
-            if (param.Action==C_ACTION_TYPE.ACTION_TYPE_GOTO)
+            if (param.Action == C_ACTION_TYPE.ACTION_TYPE_GOTO)
             {
                 PageText.Text = (param.DestinationPageIndex + 1).ToString();
                 SelectedIndex = 1;
@@ -169,6 +169,10 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
                         break;
                     case 1:
                         linkParam.Action = C_ACTION_TYPE.ACTION_TYPE_GOTO;
+                        if (LinkPage - 1 > viewControl.GetCPDFViewer().GetDocument().PageCount || LinkPage - 1 < 0)
+                        {
+                            return;
+                        }
                         linkParam.DestinationPageIndex = LinkPage - 1;
                         CSize pageSize = new CSize();
                         if (viewControl != null)
@@ -176,7 +180,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
                             pageSize = viewControl.GetCPDFViewer().GetDocument().PageAtIndex(LinkPage - 1).PageSize;
                         }
 
-                        linkParam.DestinationPosition = new CPoint(0,pageSize.height);
+                        linkParam.DestinationPosition = new CPoint(0, pageSize.height);
                         break;
                     case 2:
                         linkParam.Action = C_ACTION_TYPE.ACTION_TYPE_URI;
@@ -202,7 +206,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
             }
             else
             {
-                if(linkAnnot!=null && linkAnnot.IsValid())
+                if (linkAnnot != null && linkAnnot.IsValid())
                 {
                     switch (SelectedIndex)
                     {
@@ -220,7 +224,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
                                 }
                                 linkAnnot.SetLinkAction(uriAction);
                             }
-                           
+
                             break;
                         case 1:
                             {
@@ -244,7 +248,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
                             break;
                     }
                 }
-               
+
             }
             DrawLink = false;
             SaveBtn.IsEnabled = false;
@@ -386,7 +390,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
 
         private void CheckingItem(int ItemIndex)
         {
-            DrawLink =true;
+            DrawLink = true;
             bool BtnIsEnabled = false;
 
             if (linkParam != null)
@@ -458,7 +462,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
         {
             UrlText.Text = string.Empty;
-            PageText.Text = string.Empty;   
+            PageText.Text = string.Empty;
             EmailText.Text = string.Empty;
         }
     }