Browse Source

compdfkit(windows) - 修复stamp注释模板bug,禁止添加空白图片注释,对已有无效注释,引发异常后清除这个异常注释

liuaoran 1 year ago
parent
commit
ba645ad877

+ 45 - 32
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationControl/CPDFAnnotationControl.xaml.cs

@@ -24,6 +24,7 @@ using System.Windows.Ink;
 using compdfkit_tools.Annotation.PDFAnnotationUI;
 using Microsoft.Win32;
 using System.Windows.Media;
+using compdfkit_tools.Properties;
 
 namespace compdfkit_tools.PDFControl
 {
@@ -89,7 +90,7 @@ namespace compdfkit_tools.PDFControl
 
         private void PdfViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
         {
-            if (e != null && e.Count > 0 )
+            if (e != null && e.Count > 0)
             {
                 if (e[0].EditAction == ActionType.Del)
                 {
@@ -100,14 +101,14 @@ namespace compdfkit_tools.PDFControl
                     SetAnnotEventData(null);
                 }
 
-                if (e[0].EditAction==ActionType.Modify && e[0].EditAnnotArgs!=null && e[0].EditAnnotArgs.EventType==AnnotArgsType.AnnotSticky)
+                if (e[0].EditAction == ActionType.Modify && e[0].EditAnnotArgs != null && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotSticky)
                 {
-                    CPDFNoteUI tempUI= annotationPanel as CPDFNoteUI;
-                    if(tempUI==null || tempUI.annotAttribEvent==null)
+                    CPDFNoteUI tempUI = annotationPanel as CPDFNoteUI;
+                    if (tempUI == null || tempUI.annotAttribEvent == null)
                     {
                         tempUI = tempAnnotationPanel as CPDFNoteUI;
                     }
-                    if(tempUI== null || tempUI.annotAttribEvent == null)
+                    if (tempUI == null || tempUI.annotAttribEvent == null)
                     {
                         tempUI = pdfNoteUI;
                     }
@@ -130,7 +131,7 @@ namespace compdfkit_tools.PDFControl
             if (this.pdfViewer != null)
             {
                 this.pdfViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
-                
+
             }
         }
 
@@ -300,7 +301,7 @@ namespace compdfkit_tools.PDFControl
                 case CPDFAnnotationType.Line:
                     CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
                     annotHandlerEventArgs = new LineAnnotArgs();
-                    (annotHandlerEventArgs as LineAnnotArgs).LineColor = lineData.BorderColor; 
+                    (annotHandlerEventArgs as LineAnnotArgs).LineColor = lineData.BorderColor;
                     (annotHandlerEventArgs as LineAnnotArgs).LineWidth = lineData.Thickness;
                     (annotHandlerEventArgs as LineAnnotArgs).Transparency = lineData.Opacity;
                     (annotHandlerEventArgs as LineAnnotArgs).LineDash = lineData.DashStyle;
@@ -446,10 +447,22 @@ namespace compdfkit_tools.PDFControl
             }
             else
             {
-                Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
-                stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
-                Args.ImageHeight = stamp.ImageSource.PixelHeight;
-                Args.ImageWidth = stamp.ImageSource.PixelWidth;
+                try
+                {
+                    Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
+                    stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
+                    Args.ImageHeight = stamp.ImageSource.PixelHeight;
+                    Args.ImageWidth = stamp.ImageSource.PixelWidth;
+                }
+                catch
+                {
+                    var i =  pdfStampUI.CustomStampList.IndexOf(stamp);
+                    Settings.Default.CustomStampList.RemoveAt(i);
+                    Settings.Default.Save();
+                    pdfStampUI.LoadSettings();
+                    return;
+                }
+
             }
             Args.Type = stamp.Type;
         }
@@ -470,7 +483,7 @@ namespace compdfkit_tools.PDFControl
                 {
                     FreehandAnnotArgs freehandArgs = pdfViewer.ToolManager.CurrentAnnotArgs as FreehandAnnotArgs;
                     CPDFFreehandData freehandData = e as CPDFFreehandData;
-                    if(freehandData != null)
+                    if (freehandData != null)
                     {
                         freehandArgs.InkColor = freehandData.BorderColor;
                         freehandArgs.LineWidth = freehandData.Thickness;
@@ -480,7 +493,7 @@ namespace compdfkit_tools.PDFControl
                     }
                 }
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
             }
         }
@@ -643,7 +656,7 @@ namespace compdfkit_tools.PDFControl
                     else
                     {
                         this.pdfViewer.SetMouseMode(MouseModes.PanTool);
-                    } 
+                    }
                     ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
                     ClearPanel();
                     break;
@@ -654,7 +667,7 @@ namespace compdfkit_tools.PDFControl
 
         private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
         {
-            if (pdfViewer != null && eraseArgs!=null)
+            if (pdfViewer != null && eraseArgs != null)
             {
                 eraseArgs.Thickness = e;
             }
@@ -662,17 +675,17 @@ namespace compdfkit_tools.PDFControl
 
         private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
         {
-           if(pdfViewer!=null)
+            if (pdfViewer != null)
             {
                 CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
                 if (e)
                 {
                     annotArgs = pdfViewer.ToolManager.CurrentAnnotArgs;
-                    eraseArgs =new EraseArgs();
+                    eraseArgs = new EraseArgs();
                     eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
                     eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
-                  
-                    if(freehandUI!=null)
+
+                    if (freehandUI != null)
                     {
                         eraseArgs.Thickness = freehandUI.GetEraseThickness();
                     }
@@ -680,7 +693,7 @@ namespace compdfkit_tools.PDFControl
                     {
                         eraseArgs.Thickness = 1;
                     }
-                   
+
                     disableClean = true;
                     pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
                     pdfViewer.SetToolParam(eraseArgs);
@@ -691,17 +704,17 @@ namespace compdfkit_tools.PDFControl
                 {
                     pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
                     FreehandAnnotArgs freehandAnnotArgs = annotArgs as FreehandAnnotArgs;
-                    if (freehandAnnotArgs==null)
+                    if (freehandAnnotArgs == null)
                     {
-                        freehandAnnotArgs=new FreehandAnnotArgs();
+                        freehandAnnotArgs = new FreehandAnnotArgs();
 
                         freehandAnnotArgs.InkColor = Colors.Red;
                         freehandAnnotArgs.Transparency = 1;
                         freehandAnnotArgs.LineWidth = 1;
                         annotArgs = freehandAnnotArgs;
                     }
-                    
-                    if(freehandUI!=null)
+
+                    if (freehandUI != null)
                     {
                         freehandUI.PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
                         Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
@@ -710,7 +723,7 @@ namespace compdfkit_tools.PDFControl
                         attribDict[AnnotAttrib.Thickness] = freehandAnnotArgs.LineWidth;
                         attribDict[AnnotAttrib.NoteText] = freehandAnnotArgs.Content;
 
-                        AnnotAttribEvent annotEvent= AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
+                        AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
                         freehandUI.SetPresentAnnotAttrib(annotEvent);
                         freehandUI.PropertyChanged += CPDFAnnotationControl_PropertyChanged;
                         freehandUI.ClearAnnotAttribEvent();
@@ -747,7 +760,7 @@ namespace compdfkit_tools.PDFControl
                     break;
 
                 case AnnotArgsType.AnnotFreehand:
-                    CPDFFreehandUI tempFreehandPanel= new CPDFFreehandUI();
+                    CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
                     tempFreehandPanel.SetPresentAnnotAttrib(annotAttribEvent);
                     tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
                     tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
@@ -798,9 +811,9 @@ namespace compdfkit_tools.PDFControl
         /// </summary>
         private void ShowCurrentAnnotPanel()
         {
-            if(annotationPanel != null)
+            if (annotationPanel != null)
             {
-                if(annotationPanel is CPDFFreehandUI)
+                if (annotationPanel is CPDFFreehandUI)
                 {
                     (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
                 }
@@ -813,11 +826,11 @@ namespace compdfkit_tools.PDFControl
             {
                 EmptyMessage.Visibility = Visibility.Visible;
                 SetAnnotationPanel(null);
-                if (pdfViewer!=null && pdfViewer.ToolManager.CurrentAnnotArgs is EraseArgs)
+                if (pdfViewer != null && pdfViewer.ToolManager.CurrentAnnotArgs is EraseArgs)
                 {
                     EmptyMessage.Visibility = Visibility.Collapsed;
                 }
-            } 
+            }
         }
 
         /// <summary>
@@ -826,7 +839,7 @@ namespace compdfkit_tools.PDFControl
         /// <param name="annotArgsType"></param>
         private void ShowTempAnnotPanel(AnnotAttribEvent annotAttribEvent)
         {
-            if(annotAttribEvent != null)
+            if (annotAttribEvent != null)
             {
                 CreatTempAnnotationPanel(annotAttribEvent);
                 SetAnnotationPanel(tempAnnotationPanel);
@@ -837,7 +850,7 @@ namespace compdfkit_tools.PDFControl
                 }
                 else
                 {
-                    EmptyMessage.Visibility = Visibility.Visible; 
+                    EmptyMessage.Visibility = Visibility.Visible;
                 }
             }
         }

+ 9 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateStampDialog.xaml.cs

@@ -45,6 +45,14 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
         public void SetCreateHeaderIndex(int index)
         {
             CreateHeader.SelectedIndex = index;
+            if (index == 0)
+            {
+                SaveBtn.IsEnabled = true;
+            }
+            else
+            {
+                SaveBtn.IsEnabled = false;
+            }
         }
 
         private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
@@ -137,6 +145,7 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                         StampWidth = targetBitmap.PixelWidth;
                         StampHeight = targetBitmap.PixelHeight;
                         AddImagebackground.Visibility = Visibility.Collapsed;
+                        SaveBtn.IsEnabled = true;
                     }
                     else
                     {

+ 4 - 8
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFStampUI.xaml

@@ -32,8 +32,7 @@
                 VerticalAlignment="Top"
                 Background="Transparent"
                 BorderThickness="0"
-                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
-                    >
+                ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                     <ListBox.ItemTemplate>
                         <DataTemplate>
                             <Image
@@ -104,7 +103,7 @@
                 <Grid>
                     <Grid.RowDefinitions>
                         <RowDefinition Height="72"/>
-                        <RowDefinition Height="auto"/>
+                        <RowDefinition Height="*"/>
                     </Grid.RowDefinitions>
                     <StackPanel  Orientation="Horizontal" HorizontalAlignment="Center">
                         <Button Background="#001A4E"  Height="32" Width="114" Click="Text_Click">
@@ -122,18 +121,15 @@
                     </StackPanel>
                     <ListView
                     x:Name="CustomListBox"
-                    Grid.Row="1"
-                    Height="500"
                     VerticalAlignment="Top"
                     Background="Transparent"
-                    BorderThickness="0"
-                    >
+                    BorderThickness="0" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                         <ListView.GroupStyle>
                             <GroupStyle>
                                 <GroupStyle.HeaderTemplate>
                                     <DataTemplate>
                                         <Grid Background="#F2F2F2">
-                                        <TextBlock Text="{Binding Name}" FontSize="14" FontFamily="Helvetica" FontWeight="Bold"/>
+                                            <TextBlock Text="{Binding Name}" FontSize="14" FontFamily="Helvetica" FontWeight="Bold"/>
                                         </Grid>
                                     </DataTemplate>
                                 </GroupStyle.HeaderTemplate>

+ 1 - 2
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFStampUI.xaml.cs

@@ -98,7 +98,6 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
 
         private void Image_Click(object sender, RoutedEventArgs e)
         {
-
             CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
             createStampDialog.SetCreateHeaderIndex(1);
             createStampDialog.Owner = Window.GetWindow(this);
@@ -161,6 +160,7 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
         public void LoadSettings()
         {
             CustomStampList stamps = Settings.Default.CustomStampList;
+            CustomStampList.Clear();
             if (stamps != null)
             {
                 for (int i = 0; i < stamps.Count; i++)
@@ -189,7 +189,6 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
             if (oldstamp != null)
             {
                 CustomStampList.Add(oldstamp);
-
                 CustomStampList stamps = Settings.Default.CustomStampList;
                 if (stamps == null)
                 {

BIN
compdfkit_demo_windows/compdfkit/compdfkit-tools/ComPDFKit.Viewer.dll


+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/BarControl/CPDFBOTABarControl.xaml.cs

@@ -346,7 +346,7 @@ namespace compdfkit_tools.PDFControl
                                     pdfBookmarkControl.InitWithPDFViewer(pdfViewer);
                                     pdfBookmarkControl.LoadBookmark(); 
                                 }
-                                SetBotaTool(pdfBookmarkControl);
+                               SetBotaTool(pdfBookmarkControl);
                             }
                             checkBtn = bookmarkButton;
                         }

+ 17 - 2
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/BaseControl/PageNumberControl.xaml.cs

@@ -56,13 +56,28 @@ namespace compdfkit_tools.Common
         private void NextPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
             SetPageRangeVisible();
-            pdfView?.GoToPage(pdfView.CurrentIndex + 1);
+            if (pdfView.ModeView == ComPDFKitViewer.ViewMode.Single || pdfView.ModeView == ComPDFKitViewer.ViewMode.SingleContinuous)
+            {
+                pdfView?.GoToPage(pdfView.CurrentIndex + 1);
+            }
+            else
+            {
+                pdfView?.GoToPage(pdfView.CurrentIndex + 2); 
+            }
+
         }
 
         private void PrevPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
             SetPageRangeVisible();
-            pdfView?.GoToPage(pdfView.CurrentIndex - 1);
+            if (pdfView.ModeView == ComPDFKitViewer.ViewMode.Single || pdfView.ModeView == ComPDFKitViewer.ViewMode.SingleContinuous)
+            {
+                pdfView?.GoToPage(pdfView.CurrentIndex - 1);
+            }
+            else
+            {
+                pdfView?.GoToPage(pdfView.CurrentIndex - 2);
+            }
         }
 
         private void PageRangeText_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

+ 1 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/PDFView/PDFScaling/PDFScalingControl/CPDFScalingControl.xaml

@@ -7,7 +7,7 @@
              xmlns:pdftoolsui="clr-namespace:compdfkit_tools.PDFControlUI"
              mc:Ignorable="d" 
              d:DesignHeight="30" d:DesignWidth="162">
-    <Grid Height="30" Width="162">
+    <Grid x:Name="CPDFPageScalingControl" Height="30" Width="162" LostFocus="CPDFPageScalingControl_LostFocus">
         <pdftoolsui:CPDFScalingUI x:Name="CPDFScalingUI" Loaded="PDFScalingControl_Loaded" Unloaded="CPDFScalingUI_Unloaded"></pdftoolsui:CPDFScalingUI>
     </Grid>
 </UserControl>

+ 5 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/PDFView/PDFScaling/PDFScalingControl/CPDFScalingControl.xaml.cs

@@ -135,5 +135,10 @@ namespace compdfkit_tools.PDFControl
         {
             CPDFScalingUI.SetZoomTextBoxText(value);
         }
+         
+        private void CPDFPageScalingControl_LostFocus(object sender, RoutedEventArgs e)
+        {
+            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
+        }
     }
 }

BIN
compdfkit_demo_windows/compdfkit/compdfkit/ComPDFKit.Viewer.dll


+ 1 - 0
compdfkit_demo_windows/compdfkit/compdfkit/MainPage.xaml.cs

@@ -140,6 +140,7 @@ namespace compdfkit
             CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
 
             InitialPDFViewControl(pdfViewControl);
+            pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
 
             FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
             BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);