Ver código fonte

ComPDFKit(win) - 添加水印的字体管理,修复数字签名文档保存重启发生崩溃

liuaoran 8 meses atrás
pai
commit
28f7c97171

+ 4 - 1
Demo/Examples/Compdfkit_Tools/Common/BaseControl/PageNumberControl.xaml.cs

@@ -39,7 +39,10 @@ namespace Compdfkit_Tools.Common
 
         private void PdfView_FocusPDFViewToolChanged(object sender, EventArgs e)
         {
-            PageRangeText.Text = $"{pdfView.GetCPDFViewer().CurrentRenderFrame.PageIndex+1}/{pdfView.GetCPDFViewer().GetDocument().PageCount}";
+            if (pdfView.GetCPDFViewer().CurrentRenderFrame != null)
+            {
+                PageRangeText.Text = $"{pdfView.GetCPDFViewer().CurrentRenderFrame.PageIndex + 1}/{pdfView.GetCPDFViewer().GetDocument().PageCount}"; 
+            }
         }
 
         private void PdfView_InfoChanged(object sender, EventArgs e)

+ 11 - 11
Demo/Examples/Compdfkit_Tools/Watermark/AddWatermark/WatermarkDialog.xaml

@@ -43,25 +43,24 @@
                     <Grid>
                         <Grid.RowDefinitions>
                             <RowDefinition></RowDefinition>
-                            <RowDefinition></RowDefinition>
+                            <RowDefinition Height="auto"></RowDefinition>
                         </Grid.RowDefinitions>
                         <Grid Margin="20,20,0,0">
                             <Grid.RowDefinitions>
                                 <RowDefinition Height="auto"></RowDefinition>
                                 <RowDefinition Height="auto"></RowDefinition>
                                 <RowDefinition Height="auto"></RowDefinition>
+                                <RowDefinition Height="auto"></RowDefinition>
                             </Grid.RowDefinitions>
                             <RadioButton x:Name="TextRdo" IsChecked="True" GroupName="WatermarkType" Checked="TypeRdo_Checked">
                                 <TextBlock Text="{Binding Converter={StaticResource SecurityResourceConverter}, ConverterParameter=Rdo_TextWatermark}"></TextBlock>
                             </RadioButton>
                             <TextBox Grid.Row="1" Height="28" Width="438" Text="{Binding WatermarkText, UpdateSourceTrigger=PropertyChanged}" Margin="32,6,0,0" HorizontalAlignment="Left" VerticalContentAlignment="Center" IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}"></TextBox>
                             <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="32,6,0,0" Height="30">
-                                <ComboBox x:Name="FontFamilyCbx" Style="{StaticResource ComboBoxStyle1}" Width="160" Margin="0,0,20,0" SelectionChanged="FontFamilyCbx_SelectionChanged"  IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}">
-                                    <ComboBoxItem Tag="Helvetica" IsSelected="True">Helvetica</ComboBoxItem>
-                                    <ComboBoxItem Tag="Courier New">Courier New</ComboBoxItem>
-                                    <ComboBoxItem Tag="Times New Roman" >Times New Roman</ComboBoxItem>
+                                <ComboBox x:Name="FontFamilyCmb" Style="{StaticResource ComboBoxStyle1}" Width="160" Margin="0,0,20,0" SelectionChanged="FontFamilyCmb_SelectionChanged"  IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}">
                                 </ComboBox>
-                                <ComboBox x:Name="FontSizeCbx" Style="{StaticResource ComboBoxStyle1}" Width="66" Margin="0,0,20,0" SelectionChanged="FontSizeCbx_SelectionChanged"  IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}">
+                                <ComboBox x:Name="FontStyleCmb" Style="{StaticResource ComboBoxStyle1}" Width="90" Margin="0,0,20,0" SelectionChanged="FontStyleCmb_SelectionChanged" IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}"></ComboBox>
+                                <ComboBox x:Name="FontSizeCmb" Style="{StaticResource ComboBoxStyle1}" Width="66" Margin="0,0,20,0" SelectionChanged="FontSizeCmb_SelectionChanged"  IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}">
                                     <ComboBoxItem Tag="24" >24</ComboBoxItem>
                                     <ComboBoxItem Tag="48" IsSelected="True">48</ComboBoxItem>
                                     <ComboBoxItem Tag="72" >72</ComboBoxItem>
@@ -76,14 +75,15 @@
                                     <ComboBoxItem Tag="288" >288</ComboBoxItem>
 
                                 </ComboBox>
-                                <StackPanel Orientation="Horizontal">
-                                    <TextBlock Text="{Binding Converter={StaticResource SecurityResourceConverter}, ConverterParameter=Text_FontColor}" VerticalAlignment="Center" Margin="0,0,8,0"></TextBlock>
-                                    <common:ColorPickerControl x:Name="ColorPickerControl" ColorChanged="ColorPickerControl_ColorChanged"  IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}"></common:ColorPickerControl>
-                                </StackPanel>
+
+                            </StackPanel>
+                            <StackPanel Orientation="Horizontal" Grid.Row="3" Margin="32,0,0,0">
+                                <TextBlock Text="{Binding Converter={StaticResource SecurityResourceConverter}, ConverterParameter=Text_FontColor}" VerticalAlignment="Center" Margin="0,0,8,0"></TextBlock>
+                                <common:ColorPickerControl x:Name="ColorPickerControl" ColorChanged="ColorPickerControl_ColorChanged"  IsEnabled="{Binding Path=IsChecked, ElementName=TextRdo}"></common:ColorPickerControl>
                             </StackPanel>
                         </Grid>
 
-                        <Grid  Margin="20,20,0,0" Grid.Row="1">
+                        <Grid  Margin="20,20,0,10" Grid.Row="1">
                             <Grid.RowDefinitions>
                                 <RowDefinition Height="auto"></RowDefinition>
                                 <RowDefinition Height="auto"></RowDefinition>

+ 39 - 10
Demo/Examples/Compdfkit_Tools/Watermark/AddWatermark/WatermarkDialog.xaml.cs

@@ -1,4 +1,5 @@
-using ComPDFKit.PDFWatermark;
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFWatermark;
 using Compdfkit_Tools.Common;
 using Compdfkit_Tools.Helper;
 using System;
@@ -259,6 +260,20 @@ namespace Compdfkit_Tools.PDFControl
                 }
             }
         }
+
+        private string _postScriptName;
+        public string PostScriptName
+        {
+            get => _postScriptName;
+            set
+            {
+                if (UpdateProper<string>(ref _postScriptName, value))
+                {
+                    watermarkData.FontName = _postScriptName;
+                }
+            }
+        }
+
         public delegate void WindowClosedEventHandler(object sender, WatermarkData watermarkData); 
         public event WindowClosedEventHandler WindowClosed;
         private WeakReference weakReference;
@@ -305,16 +320,9 @@ namespace Compdfkit_Tools.PDFControl
             return true;
         }
 
-        private void FontFamilyCbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
-        {
-            var item = sender as ComboBox;
-            if (item != null)
-            {
-                FontName = (item.SelectedItem as ComboBoxItem).Tag.ToString();
-            }
-        }
 
-        private void FontSizeCbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
+
+        private void FontSizeCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             var item = sender as ComboBox;
             if (item != null)
@@ -331,6 +339,10 @@ namespace Compdfkit_Tools.PDFControl
             watermarkData.ValueChanged += 
                 (s, e) => PreviewControl.WatermarkData = watermarkData;
             weakReference = new WeakReference(this);
+
+            FontFamilyCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys;
+            FontFamilyCmb.SelectedIndex = 0;
+
         }
 
         private void InitWatermarkData(ref WatermarkData watermarkData)
@@ -497,5 +509,22 @@ namespace Compdfkit_Tools.PDFControl
                 }
             }
         }
+
+        private void FontFamilyCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontFamilyCmb.SelectedItem.ToString()];
+            FontStyleCmb.SelectedIndex = 0;
+            string postScriptName = string.Empty;
+            CPDFFont.GetPostScriptName(FontFamilyCmb.SelectedItem.ToString(), FontStyleCmb.SelectedItem.ToString(), ref postScriptName);
+            PostScriptName = postScriptName;
+        }
+
+        private void FontStyleCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            string postScriptName = string.Empty;
+            CPDFFont.GetPostScriptName(FontFamilyCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue?.ToString(), ref postScriptName);
+            PostScriptName = postScriptName;
+
+        }
     }
 }