Преглед изворни кода

compdfkit(win) - 字体调整

liuaoran пре 7 месеци
родитељ
комит
b1ac0e4b22

+ 6 - 19
Demo/Examples/Compdfkit_Tools/Annotation/CPDFAnnotationPreviewerControl.xaml.cs

@@ -1,4 +1,5 @@
-using Compdfkit_Tools.Data;
+using ComPDFKit.PDFDocument;
+using Compdfkit_Tools.Data;
 using System;
 using System.Windows;
 using System.Windows.Controls;
@@ -171,28 +172,14 @@ namespace Compdfkit_Tools.PDFControl
             CollapsedAll();
             FreeTextGrid.Visibility = Visibility.Visible;
 
-            FreeText.FontFamily = new FontFamily(freeTextData.FontFamily);
+            string fontFamily = string.Empty;
+            string fontStyle = string.Empty;
 
+            CPDFFont.GetFamlyStyleName(freeTextData.FontFamily, ref fontFamily, ref fontStyle);
+            FreeText.FontFamily = new FontFamily(fontFamily); 
             FreeText.FontSize = freeTextData.FontSize / 1.2;
             FreeText.Foreground = new SolidColorBrush(freeTextData.BorderColor);
             FreeText.Opacity = freeTextData.Opacity;
-            if (freeTextData.IsBold)
-            {
-                FreeText.FontWeight = FontWeights.Bold;
-            }
-            else
-            {
-                FreeText.FontWeight = FontWeights.Medium;
-            }
-
-            if (freeTextData.IsItalic)
-            {
-                FreeText.FontStyle = FontStyles.Italic;
-            }
-            else
-            {
-                FreeText.FontStyle = FontStyles.Normal;
-            }
         }
     }
 }

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

@@ -38,7 +38,7 @@
                 <RowDefinition></RowDefinition>
                 <RowDefinition></RowDefinition>
             </Grid.RowDefinitions>
-            <Grid Height="226">
+            <Grid Height="228">
                 <Border BorderThickness="1" BorderBrush="#33000000" Margin="32,10,0,0" VerticalAlignment="Stretch" >
                     <Grid>
                         <Grid.RowDefinitions>

+ 18 - 2
Demo/Examples/Compdfkit_Tools/Watermark/AddWatermark/WatermarkDialog.xaml.cs

@@ -341,7 +341,23 @@ namespace Compdfkit_Tools.PDFControl
             weakReference = new WeakReference(this);
 
             FontFamilyCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys;
-            FontFamilyCmb.SelectedIndex = 0; 
+            // 如果存在helvetica,arial,times,则默认选择
+            if (FontFamilyCmb.Items.Contains("Helvetica"))
+            {
+                FontFamilyCmb.SelectedItem = "Helvetica";
+            }
+            else if (FontFamilyCmb.Items.Contains("Arial"))
+            {
+                FontFamilyCmb.SelectedItem = "Arial";
+            }
+            else if (FontFamilyCmb.Items.Contains("Times"))
+            {
+                FontFamilyCmb.SelectedItem = "Times";
+            }
+            else
+            {
+                FontFamilyCmb.SelectedIndex = 0;
+            }
         }
 
         private void InitWatermarkData(ref WatermarkData watermarkData)
@@ -514,7 +530,7 @@ namespace Compdfkit_Tools.PDFControl
             FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontFamilyCmb.SelectedItem.ToString()];
             FontStyleCmb.SelectedIndex = 0;
             string postScriptName = string.Empty;
-            CPDFFont.GetPostScriptName(FontFamilyCmb.SelectedItem.ToString(), FontStyleCmb.SelectedItem.ToString(), ref postScriptName);
+            CPDFFont.GetPostScriptName(FontFamilyCmb.SelectedItem.ToString(), FontStyleCmb?.SelectedItem?.ToString(), ref postScriptName);
             PostScriptName = postScriptName;
         }
 

+ 1 - 11
Demo/Examples/PDFViewer/MainWindow.xaml.cs

@@ -48,9 +48,7 @@ namespace PDFViewer
             InitializeComponent();
             Loaded += MainWindow_Loaded;
             DataContext = this;
-        }
-
-
+        } 
 
         private void MainWindow_Loaded(object sender, RoutedEventArgs e)
         {
@@ -66,14 +64,6 @@ namespace PDFViewer
             TabControl.SelectionChanged += TabControl_SelectionChanged;
             FirstLoadFile();
             CPDFAnnotationData.Author = Properties.Settings.Default.DocumentAuthor;
-
-            Thread thread = new Thread(DoWork); 
-            thread.Start(); 
-        }
-
-        static void DoWork()
-        {
-            CPDFFont.InitFont();
         }
 
         private void FirstLoadFile()