Kaynağa Gözat

compdfkit(win) - 调整form模块字体管理

liuaoran 11 ay önce
ebeveyn
işleme
77c6a6b776

+ 13 - 7
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateStampDialog.xaml

@@ -15,6 +15,7 @@
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="../../../Asset/Styles/ButtonStyle.xaml"></ResourceDictionary>
+                <ResourceDictionary Source="../../../Asset/Styles/ComboBoxStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
             <cpdfcommon:ReverseVisibilityConverter x:Key="ReverseVisibilityConverter"/>
             <cpdfcommon:PropertyPanelResourceConverter x:Key="PropertyPanelResourceConverter"></cpdfcommon:PropertyPanelResourceConverter>
@@ -349,17 +350,22 @@
                         <Grid.RowDefinitions>
                             <RowDefinition Height="20"/>
                             <RowDefinition Height="*"/>
-                            <RowDefinition Height="32"/>
-                            <RowDefinition Height="14"/>
-                            <RowDefinition Height="20"/>
-                            <RowDefinition Height="12"/>
+                            <RowDefinition Height="28"/>
+                            <RowDefinition Height="28"/>
+                            <RowDefinition Height="20"/> 
                             <RowDefinition Height="20"/>
                         </Grid.RowDefinitions>
                         <TextBlock Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Title_Preview}" FontSize="14" FontFamily="Microsoft YaHei" FontWeight="Bold"/>
                         <Image Grid.Row="1" x:Name="TextImage"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                        <StackPanel Grid.Row="2" Orientation="Horizontal" Height="32">
-                            <TextBlock Margin="18,0,23,0" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Stamp_Text}" VerticalAlignment="Center"/>
-                            <TextBox x:Name="StampText" Width="233"  Text="Stamp Text" VerticalContentAlignment="Center" TextChanged="TextBox_TextChanged"/>
+                        <StackPanel Grid.Row="2" Orientation="Horizontal" Height="28">
+                            <TextBlock Margin="0,0,10,0" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Stamp_Text}" VerticalAlignment="Center"/>
+                            <TextBox x:Name="StampText" Width="270" Margin="0,2,0,2" Text="Stamp Text" VerticalContentAlignment="Center" TextChanged="TextBox_TextChanged"/>
+                        </StackPanel>
+                        <StackPanel Grid.Row="3" Orientation="Horizontal" Height="28">
+                            <TextBlock Margin="0,0,10,0" Text="字体" VerticalAlignment="Center"/>
+                            <ComboBox x:Name="FontNameCmb" Style="{StaticResource ComboBoxStyle1}" Height="26" Width="150" SelectionChanged="FontNameCmb_SelectionChanged" SelectedIndex="0"></ComboBox>
+                            <TextBlock Margin="6,0,10,0" Text="样式" VerticalAlignment="Center"></TextBlock>
+                            <ComboBox x:Name="StyleNameCmb" Style="{StaticResource ComboBoxStyle1}" Height="26" Width="80"  SelectionChanged="StyleNameCmb_SelectionChanged"></ComboBox>
                         </StackPanel>
                         <CheckBox Grid.Row="4" Name="Date" Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Check_Date}" Checked="Date_Checked" Unchecked="Date_Unchecked"/>
                         <CheckBox Grid.Row="6" Name="Time" Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Check_Time}" Checked="Time_Checked" Unchecked="Time_Unchecked"/>

+ 18 - 0
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateStampDialog.xaml.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.PDFAnnotation;
+using ComPDFKit.PDFDocument;
 using ComPDFKit.Tool.Help;
 using Compdfkit_Tools.Data;
 using Microsoft.Win32;
@@ -95,6 +96,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                     double scale = Math.Min((double)600 / image.PixelWidth, (double)600 / image.PixelHeight);
                     scale = Math.Min(scale, 1);
                     string ext = Path.GetExtension(FilePath);
+
                     if (ext.ToUpper() == ".PNG")
                     {
                         BitmapEncoder encoder = new PngBitmapEncoder();
@@ -105,6 +107,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                         {
                             encoder.Save(stream);
                         }
+
                         if (!string.IsNullOrEmpty(SaveToPath))
                         {
                             DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(SaveToPath);
@@ -113,6 +116,7 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                                 Directory.Delete(SaveToPath, true);
                             }
                         }
+
                         SaveToPath = path;
                         ImageImage.Source = targetBitmap;
                         StampWidth = targetBitmap.PixelWidth;
@@ -338,6 +342,8 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
             PageLoaded = true;
 
             UpTextPreview();
+
+            FontNameCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys;
         }
 
 
@@ -505,5 +511,17 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                 }
             }
         }
+
+        private void FontNameCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            StyleNameCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontNameCmb.SelectedValue.ToString()];
+            StyleNameCmb.SelectedIndex = 0;
+
+        }
+
+        private void StyleNameCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+
+        }
     }
 }

+ 5 - 12
Demo/Examples/Compdfkit_Tools/Form/Property/ComboBoxProperty.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl" xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
              mc:Ignorable="d" 
-             d:DesignHeight="400" d:DesignWidth="300"
+             d:DesignHeight="600" d:DesignWidth="300"
              Loaded="UserControl_Loaded"
              Unloaded="UserControl_Unloaded"
              >
@@ -76,19 +76,12 @@
                         </StackPanel>
                         <StackPanel>
                             <TextBlock  Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Font}" FontSize="14" FontFamily="Microsoft YaHei" FontWeight="Bold" />
-                            <ComboBox x:Name="FontCmb" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged">
-                                <ComboBoxItem Content="Arial"/>
-                                <ComboBoxItem Content="Courier New"/>
-                                <ComboBoxItem Content="Times New Roman"/>
+                            <ComboBox x:Name="FontCmb" Height="28" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged" PreviewMouseDown="FontCmb_PreviewMouseDown">
                             </ComboBox>
-                            <StackPanel Orientation="Horizontal" >
-                                <ComboBox x:Name="FontStyleCmb"  Margin="0,8,0,0" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged">
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Regular}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Bold}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Oblique}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_BoldOblique}"/>
+                            <StackPanel Orientation="Horizontal"  Height="28" Margin="0,8,0,0">
+                                <ComboBox x:Name="FontStyleCmb" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged" PreviewMouseDown="FontStyleCmb_PreviewMouseDown">
                                 </ComboBox>
-                                <ComboBox x:Name="FontSizeCmb" Margin="4,8,0,0" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged"/>
+                                <ComboBox x:Name="FontSizeCmb" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged" Margin="12,0,0,0"/>
                             </StackPanel>
                         </StackPanel>
                     </StackPanel>

+ 79 - 75
Demo/Examples/Compdfkit_Tools/Form/Property/ComboBoxProperty.xaml.cs

@@ -14,11 +14,15 @@ using System.Windows.Media;
 using ComPDFKit.Tool.UndoManger;
 using ComPDFKitViewer.Helper;
 using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
+using System.Windows.Input;
 
 namespace Compdfkit_Tools.PDFControl
 {
     public partial class ComboBoxProperty : UserControl
     {
+        public bool isFontCmbClicked;
+        public bool isFontStyleCmbClicked;
+
         private ComboBoxParam widgetParam = null;
         private CPDFComboBoxWidget cPDFAnnotation = null;
         private PDFViewControl pdfViewerControl = null;
@@ -58,8 +62,15 @@ namespace Compdfkit_Tools.PDFControl
             BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
             BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
             TextColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.FontColor));
-            SetFontName(widgetParam.FontName);
-            SetFontStyle(widgetParam.IsItalic, widgetParam.IsBold);
+            string familyName = string.Empty;
+            string styleName = string.Empty;
+
+            CPDFFont.GetFamlyStyleName(widgetParam.FontName, ref familyName, ref styleName);
+
+            FontCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys.ToList();
+
+            SetFontName(familyName);
+            SetFontStyle(styleName);
             SetFontSize(widgetParam.FontSize);
 
             itemlists = widgetParam.OptionItems;
@@ -78,6 +89,8 @@ namespace Compdfkit_Tools.PDFControl
             TopTabControl.SelectedIndex = 2;
 
             IsLoadedData = true;
+            
+            FontCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys.ToList();
         }
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
@@ -91,39 +104,21 @@ namespace Compdfkit_Tools.PDFControl
             FontSizeCmb.SelectedIndex = index;
         }
 
-        private void SetFontStyle(bool IsItalic, bool IsBold)
+        private void SetFontStyle(string fontStyle)
         {
-            int index = 0;
-            if (IsItalic && IsBold)
-            {
-                index = 3;
-            }
-            else if (IsItalic)
-            {
-                index = 2;
-            }
-            else if (IsBold)
-            {
-                index = 1;
-            }
-            FontStyleCmb.SelectedIndex = index;
+            FontStyleCmb.SelectedValue = fontStyle;
         }
 
         private void SetFontName(string fontName)
         {
-            int index = -1;
-            List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
-            for (int i = 0; i < fontFamilyList.Count; i++)
+            FontCmb.SelectedValue = fontName;
+            if (FontCmb.SelectedValue != null)
             {
-                if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
-                    || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
-                {
-                    index = i;
-                }
+                FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
             }
-            FontCmb.SelectedIndex = index;
         }
 
+
         #endregion
         private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
         {
@@ -250,22 +245,31 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
-                ComboBoxHistory history = new ComboBoxHistory();
-                history.Action = HistoryAction.Update;
-                history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
-                history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                
-                CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isBold = IsBold(cTextAttribute.FontName);
-                bool isItalic = IsItalic(cTextAttribute.FontName);
-                FontType fontType = GetFontType((sender as ComboBox).SelectedItem?.ToString());
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
-                cPDFAnnotation.SetTextAttribute(cTextAttribute);
-                cPDFAnnotation.UpdateFormAp();
-                pdfViewerControl.UpdateAnnotFrame();
-                
-                history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                if (isFontCmbClicked)
+                {
+                    FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
+                    FontStyleCmb.SelectedIndex = 0;
+
+                    ComboBoxHistory history = new ComboBoxHistory();
+                    history.Action = HistoryAction.Update;
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+
+                    CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
+                    string psFontName = string.Empty;
+                    CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                    cTextAttribute.FontName = psFontName;
+                    cPDFAnnotation.SetTextAttribute(cTextAttribute);
+                    cPDFAnnotation.UpdateFormAp();
+                    pdfViewerControl.UpdateAnnotFrame();
+
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                }
+                else
+                {
+                    FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()]; 
+                }
             }
         }
 
@@ -273,41 +277,25 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
-                ComboBoxHistory history = new ComboBoxHistory();
-                history.Action = HistoryAction.Update;
-                history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
-                history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                
-                CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isItalic = false;
-                bool isBold = false;
-                switch ((sender as ComboBox).SelectedIndex)
+                if (isFontStyleCmbClicked)
                 {
-                    case 0:
-                        break;
-                    case 1:
-                        isItalic = false;
-                        isBold = true;
-                        break;
-                    case 2:
-                        isItalic = true;
-                        isBold = false;
-                        break;
-                    case 3:
-                        isItalic = true;
-                        isBold = true;
-                        break;
-                    default:
-                        break;
+                    ComboBoxHistory history = new ComboBoxHistory();
+                    history.Action = HistoryAction.Update;
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+
+                    CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
+                    string psFontName = string.Empty;
+                    CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                    cTextAttribute.FontName = psFontName;
+
+                    cPDFAnnotation.SetTextAttribute(cTextAttribute);
+                    cPDFAnnotation.UpdateFormAp();
+                    pdfViewerControl.UpdateAnnotFrame();
+
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
                 }
-                FontType fontType = GetFontType(cTextAttribute.FontName);
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
-                cPDFAnnotation.SetTextAttribute(cTextAttribute);
-                cPDFAnnotation.UpdateFormAp();
-                pdfViewerControl.UpdateAnnotFrame();
-                
-                history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
             }
         }
 
@@ -486,5 +474,21 @@ namespace Compdfkit_Tools.PDFControl
                 UpdateListItems();
             }
         }
+
+        private void FontCmb_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontCmbClicked = true;
+            }
+        }
+
+        private void FontStyleCmb_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontStyleCmbClicked = true;
+            }
+        }
     }
 }

+ 5 - 12
Demo/Examples/Compdfkit_Tools/Form/Property/ListBoxProperty.xaml

@@ -6,7 +6,7 @@
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl" 
              xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
              mc:Ignorable="d" 
-             d:DesignHeight="400" d:DesignWidth="300"
+             d:DesignHeight="500" d:DesignWidth="300"
              Loaded="UserControl_Loaded"
              Unloaded="UserControl_Unloaded"
              >
@@ -77,19 +77,12 @@
                         </StackPanel>
                         <StackPanel>
                             <TextBlock  Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Font}" FontSize="14" FontFamily="Microsoft YaHei" FontWeight="Bold" />
-                            <ComboBox x:Name="FontCmb" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged">
-                                <ComboBoxItem Content="Arial"/>
-                                <ComboBoxItem Content="Courier New"/>
-                                <ComboBoxItem Content="Times New Roman"/>
+                            <ComboBox x:Name="FontCmb" Height="28" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged" PreviewMouseDown="FontCmb_PreviewMouseDown">
                             </ComboBox>
-                            <StackPanel Orientation="Horizontal" >
-                                <ComboBox x:Name="FontStyleCmb"  Margin="0,8,0,0" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged">
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Regular}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Bold}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Oblique}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_BoldOblique}"/>
+                            <StackPanel Orientation="Horizontal"  Height="28" Margin="0,8,0,0">
+                                <ComboBox x:Name="FontStyleCmb"  Margin="0,0,0,0" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged" PreviewMouseDown="FontStyleCmb_PreviewMouseDown">
                                 </ComboBox>
-                                <ComboBox x:Name="FontSizeCmb" Margin="4,8,0,0" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged"/>
+                                <ComboBox x:Name="FontSizeCmb" Margin="4,0,0,0" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged"/>
                             </StackPanel>
                         </StackPanel>
                     </StackPanel>

+ 49 - 58
Demo/Examples/Compdfkit_Tools/Form/Property/ListBoxProperty.xaml.cs

@@ -13,11 +13,16 @@ using System.Windows.Media;
 using ComPDFKit.Tool.UndoManger;
 using ComPDFKitViewer.Helper;
 using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
+using System.Linq;
+using System.Windows.Input;
 
 namespace Compdfkit_Tools.PDFControl
 {
     public partial class ListBoxProperty : UserControl
     {
+        public bool isFontStyleCmbClicked;
+        public bool isFontCmbClicked;
+
         private ListBoxParam widgetParam = null;
         private CPDFListBoxWidget cPDFAnnotation = null;
         private PDFViewControl pdfViewerControl = null;
@@ -52,16 +57,23 @@ namespace Compdfkit_Tools.PDFControl
             SizeListbinding.Source = this;
             SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
             FontSizeCmb.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
-
-            FieldNameText.Text = widgetParam.FieldName;
+             
             FormFieldCmb.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
             BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
             BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
             TextColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.FontColor));
-            SetFontName(widgetParam.FontName);
-            SetFontStyle(widgetParam.IsItalic, widgetParam.IsBold);
-            SetFontSize(widgetParam.FontSize);
 
+            string familyName = string.Empty;
+            string styleName = string.Empty;
+
+            CPDFFont.GetFamlyStyleName(widgetParam.FontName, ref familyName, ref styleName);
+
+            FontCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys.ToList();
+
+            SetFontName(familyName);
+            SetFontStyle(styleName);
+            SetFontSize(widgetParam.FontSize);
+             
             itemlists = widgetParam.OptionItems;
 
             if (itemlists != null)
@@ -78,7 +90,7 @@ namespace Compdfkit_Tools.PDFControl
 
             TopTabControl.SelectedIndex = 2;
 
-            IsLoadedData = true;
+            IsLoadedData = true; 
         }
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
@@ -92,37 +104,18 @@ namespace Compdfkit_Tools.PDFControl
             FontSizeCmb.SelectedIndex = index;
         }
 
-        private void SetFontStyle(bool IsItalic, bool IsBold)
+        private void SetFontName(string fontName)
         {
-            int index = 0;
-            if (IsItalic && IsBold)
+            FontCmb.SelectedValue = fontName;
+            if (FontCmb.SelectedValue != null)
             {
-                index = 3;
+                FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
             }
-            else if (IsItalic)
-            {
-                index = 2;
-            }
-            else if (IsBold)
-            {
-                index = 1;
-            }
-            FontStyleCmb.SelectedIndex = index;
         }
 
-        private void SetFontName(string fontName)
+        private void SetFontStyle(string fontStyle)
         {
-            int index = -1;
-            List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
-            for (int i = 0; i < fontFamilyList.Count; i++)
-            {
-                if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
-                    || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
-                {
-                    index = i;
-                }
-            }
-            FontCmb.SelectedIndex = index;
+            FontStyleCmb.SelectedValue = fontStyle;
         }
 
         #endregion
@@ -231,16 +224,18 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
+                FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
+                FontStyleCmb.SelectedIndex = 0;
+
                 ListBoxHistory history = new ListBoxHistory();
                 history.Action = HistoryAction.Update;
                 history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
                 history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
                 
                 CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isBold = IsBold(cTextAttribute.FontName);
-                bool isItalic = IsItalic(cTextAttribute.FontName);
-                FontType fontType = GetFontType((sender as ComboBox).SelectedItem?.ToString());
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
+                string psFontName = string.Empty;
+                CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName); 
+                cTextAttribute.FontName = psFontName;
                 cPDFAnnotation.SetTextAttribute(cTextAttribute);
                 cPDFAnnotation.UpdateFormAp();
                 pdfViewerControl.UpdateAnnotFrame();
@@ -260,29 +255,9 @@ namespace Compdfkit_Tools.PDFControl
                 history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
                 
                 CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isItalic = false;
-                bool isBold = false;
-                switch ((sender as ComboBox).SelectedIndex)
-                {
-                    case 0:
-                        break;
-                    case 1:
-                        isItalic = IsItalic(cTextAttribute.FontName);
-                        isBold = true;
-                        break;
-                    case 2:
-                        isItalic = true;
-                        isBold = IsBold(cTextAttribute.FontName);
-                        break;
-                    case 3:
-                        isItalic = true;
-                        isBold = true;
-                        break;
-                    default:
-                        break;
-                }
-                FontType fontType = GetFontType(cTextAttribute.FontName);
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
+                string psFontName = string.Empty;
+                CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                cTextAttribute.FontName = psFontName;
                 cPDFAnnotation.SetTextAttribute(cTextAttribute);
                 cPDFAnnotation.UpdateFormAp();
                 pdfViewerControl.UpdateAnnotFrame();
@@ -469,5 +444,21 @@ namespace Compdfkit_Tools.PDFControl
                 UpdateListItems();
             }
         }
+
+        private void FontCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontCmbClicked = true;
+            }
+        }
+
+        private void FontStyleCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontStyleCmbClicked = true;
+            }
+        }
     }
 }

+ 6 - 13
Demo/Examples/Compdfkit_Tools/Form/Property/PushButtonProperty.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl" xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
              mc:Ignorable="d" 
-             d:DesignHeight="400" d:DesignWidth="300"
+             d:DesignHeight="500" d:DesignWidth="300"
              Loaded="UserControl_Loaded"
              Unloaded="UserControl_Unloaded"
              >
@@ -93,22 +93,15 @@
                         </StackPanel>
                         <StackPanel>
                             <TextBlock  Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Font}" FontSize="14" FontFamily="Microsoft YaHei" FontWeight="Bold" />
-                            <ComboBox x:Name="FontCmb" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged">
-                                <ComboBoxItem Content="Arial"/>
-                                <ComboBoxItem Content="Courier New"/>
-                                <ComboBoxItem Content="Times New Roman"/>
+                            <ComboBox x:Name="FontCmb" Height="28" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" PreviewMouseDown="FontCmb_PreviewMouseDown" SelectionChanged="FontCmb_SelectionChanged">
                             </ComboBox>
-                            <StackPanel Orientation="Horizontal" >
-                                <ComboBox x:Name="FontStyleCmb"  Margin="0,8,0,0" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged">
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Regular}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Bold}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Oblique}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_BoldOblique}"/>
+                            <StackPanel Orientation="Horizontal"  Height="28" Margin="0,8,0,0">
+                                <ComboBox x:Name="FontStyleCmb" Width="148" Style="{StaticResource ComboBoxStyle1}" PreviewMouseDown="FontStyleCmb_PreviewMouseDown" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged">
                                 </ComboBox>
-                                <ComboBox x:Name="FontSizeCmb" Margin="4,8,0,0" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged"/>
+                                <ComboBox x:Name="FontSizeCmb" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged" Margin="12,0,0,0"/>
                             </StackPanel>
                         </StackPanel>
-                    </StackPanel>
+                    </StackPanel> 
                 </Grid>
             </TabItem>
             <TabItem Height="32" Style="{DynamicResource TabItemStyle1}" Header="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Title_Preferences}">

+ 85 - 64
Demo/Examples/Compdfkit_Tools/Form/Property/PushButtonProperty.xaml.cs

@@ -20,11 +20,15 @@ using ComPDFKit.Tool.UndoManger;
 using ComPDFKitViewer.Helper;
 using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
+using System.Linq;
 
 namespace Compdfkit_Tools.PDFControl
 {
     public partial class PushButtonProperty : UserControl,INotifyPropertyChanged
     {
+        public bool isFontStyleCmbClicked;
+        public bool isFontCmbClicked;
+
         private PushButtonParam widgetParam = null;
         private CPDFPushButtonWidget cPDFAnnotation = null;
         private PDFViewControl pdfViewerControl = null;
@@ -48,8 +52,8 @@ namespace Compdfkit_Tools.PDFControl
             DataContext = this;
         }
 
-        #region Loaded
 
+        #region Loaded 
         public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
         {
             widgetParam = (PushButtonParam)annotParam;
@@ -65,18 +69,28 @@ namespace Compdfkit_Tools.PDFControl
             SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
             FontSizeCmb.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
 
-            TopTabControl.SelectedIndex = 2;
-            FieldNameText.Text = widgetParam.FieldName;
+            TopTabControl.SelectedIndex = 2; 
+
             FormFieldCmb.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
             BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
             BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
             TextColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.FontColor));
-            SetFontName(widgetParam.FontName);
-            SetFontStyle(widgetParam.IsItalic, widgetParam.IsBold);
+
+            string familyName = string.Empty;
+            string styleName = string.Empty;
+
+            CPDFFont.GetFamlyStyleName(widgetParam.FontName,ref familyName,ref styleName);
+
+            FontCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys.ToList();
+
+            SetFontName(familyName);
+            SetFontStyle(styleName); 
             SetFontSize(widgetParam.FontSize);
+            
             ItemText.Text = widgetParam.Text;
             SetActionContext();
             IsLoadedData = true;
+
         }
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
@@ -130,19 +144,17 @@ namespace Compdfkit_Tools.PDFControl
 
         private void SetFontName(string fontName)
         {
-            int index = -1;
-            List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
-            for (int i = 0; i < fontFamilyList.Count; i++)
+            FontCmb.SelectedValue = fontName;
+            if (FontCmb.SelectedValue != null)
             {
-                if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
-                    || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
-                {
-                    index = i;
-                }
+                FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
             }
-            FontCmb.SelectedIndex = index;
         }
 
+        private void SetFontStyle(string fontStyle)
+        {
+            FontStyleCmb.SelectedValue = fontStyle;
+        }
         #endregion
 
         #region Updata
@@ -254,22 +266,32 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
-                PushButtonHistory history = new PushButtonHistory();
-                history.Action = HistoryAction.Update;
-                history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
-                history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                
-                CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isBold = IsBold(cTextAttribute.FontName);
-                bool isItalic = IsItalic(cTextAttribute.FontName);
-                FontType fontType = GetFontType((sender as ComboBox).SelectedItem?.ToString());
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
-                cPDFAnnotation.SetTextAttribute(cTextAttribute);
-                cPDFAnnotation.UpdateFormAp();
-                pdfViewerControl.UpdateAnnotFrame();
-                
-                history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                if (isFontCmbClicked)
+                {
+                    FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
+                    FontStyleCmb.SelectedIndex = 0;
+
+                    PushButtonHistory history = new PushButtonHistory();
+                    history.Action = HistoryAction.Update;
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+
+                    CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
+                    string psFontName = string.Empty;
+                    CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                    cTextAttribute.FontName = psFontName;
+                    cPDFAnnotation.SetTextAttribute(cTextAttribute);
+                    cPDFAnnotation.UpdateFormAp();
+                    pdfViewerControl.UpdateAnnotFrame();
+
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                }
+                else
+                {
+                    FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
+                }
+                isFontCmbClicked = false;
             }
         }
 
@@ -277,42 +299,25 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
-                PushButtonHistory history = new PushButtonHistory();
-                history.Action = HistoryAction.Update;
-                history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
-                history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                
-                CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isItalic = false;
-                bool isBold = false;
-                switch ((sender as ComboBox).SelectedIndex)
+                if (isFontStyleCmbClicked)
                 {
-                    case 0:
-                        break;
-                    case 1:
-                        isItalic = IsItalic(cTextAttribute.FontName);
-                        isBold = true;
-                        break;
-                    case 2:
-                        isItalic = true;
-                        isBold = IsBold(cTextAttribute.FontName);
-                        break;
-                    case 3:
-                        isItalic = true;
-                        isBold = true;
-                        break;
-                    default:
-                        break;
+                    PushButtonHistory history = new PushButtonHistory();
+                    history.Action = HistoryAction.Update;
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+
+                    CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
+                    string psFontName = string.Empty;
+                    CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                    cTextAttribute.FontName = psFontName;
+                    cPDFAnnotation.SetTextAttribute(cTextAttribute);
+                    cPDFAnnotation.UpdateFormAp();
+                    pdfViewerControl.UpdateAnnotFrame();
+
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
                 }
-
-                FontType fontType = GetFontType(cTextAttribute.FontName);
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
-                cPDFAnnotation.SetTextAttribute(cTextAttribute);
-                cPDFAnnotation.UpdateFormAp();
-                pdfViewerControl.UpdateAnnotFrame();
-                
-                history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
-                pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                isFontStyleCmbClicked = false;
             }
         }
 
@@ -467,5 +472,21 @@ namespace Compdfkit_Tools.PDFControl
             OnPropertyChanged(propertyName);
             return true;
         }
+
+        private void FontCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontCmbClicked = true;
+            }
+        } 
+
+        private void FontStyleCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontStyleCmbClicked = true;
+            }
+        }
     }
 }

+ 5 - 12
Demo/Examples/Compdfkit_Tools/Form/Property/TextFieldProperty.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl" xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
              mc:Ignorable="d"
-             d:DesignHeight="400" d:DesignWidth="300"
+             d:DesignHeight="500" d:DesignWidth="300"
              Loaded="UserControl_Loaded"
              Unloaded="UserControl_Unloaded"
              >
@@ -76,19 +76,12 @@
                         </StackPanel>
                         <StackPanel>
                             <TextBlock  Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Font}" FontSize="14" FontFamily="Microsoft YaHei" FontWeight="Bold" />
-                            <ComboBox x:Name="FontCmb" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged">
-                                <ComboBoxItem Content="Arial"/>
-                                <ComboBoxItem Content="Courier New"/>
-                                <ComboBoxItem Content="Times New Roman"/>
+                            <ComboBox x:Name="FontCmb" Height="28" Margin="0,8,0,0" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontCmb_SelectionChanged" PreviewMouseDown="FontCmb_PreviewMouseDown">
                             </ComboBox>
-                            <StackPanel Orientation="Horizontal" >
-                                <ComboBox x:Name="FontStyleCmb"  Margin="0,8,0,0" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged">
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Regular}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Bold}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_Oblique}"/>
-                                    <ComboBoxItem Content="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Font_BoldOblique}"/>
+                            <StackPanel Orientation="Horizontal"  Height="28" Margin="0,8,0,0">
+                                <ComboBox x:Name="FontStyleCmb" Width="148" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontStyleCmb_SelectionChanged" PreviewMouseDown="FontStyleCmb_PreviewMouseDown">
                                 </ComboBox>
-                                <ComboBox x:Name="FontSizeCmb" Margin="4,8,0,0" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged"/>
+                                <ComboBox x:Name="FontSizeCmb" Width="72" Style="{StaticResource ComboBoxStyle1}" SelectedIndex="0" SelectionChanged="FontSizeCmb_SelectionChanged" Margin="12,0,0,0"/>
                             </StackPanel>
                         </StackPanel>
                     </StackPanel>

+ 71 - 64
Demo/Examples/Compdfkit_Tools/Form/Property/TextFieldProperty.xaml.cs

@@ -13,11 +13,16 @@ using System.Windows.Media;
 using ComPDFKit.Tool.UndoManger;
 using ComPDFKitViewer.Helper;
 using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
+using System.Linq;
+using System.Windows.Input;
 
 namespace Compdfkit_Tools.PDFControl
 {
     public partial class TextFieldProperty : UserControl
     {
+        public bool isFontCmbClicked;
+        public bool isFontStyleCmbClicked;
+
         private TextBoxParam widgetParam = null;
         private CPDFTextWidget cPDFAnnotation = null;
         private PDFViewControl pdfViewerControl = null;
@@ -56,13 +61,22 @@ namespace Compdfkit_Tools.PDFControl
             BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
             BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
             TextColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.FontColor));
-            SetFontName(widgetParam.FontName);
-            SetFontStyle(widgetParam.IsItalic, widgetParam.IsBold);
+            string familyName = string.Empty;
+            string styleName = string.Empty;
+
+            CPDFFont.GetFamlyStyleName(widgetParam.FontName, ref familyName, ref styleName);
+
+            FontCmb.ItemsSource = CPDFFont.GetFontNameDictionary().Keys.ToList();
+
+            SetFontName(familyName);
+            SetFontStyle(styleName);
             SetFontSize(widgetParam.FontSize);
+             
             TextAlignmentCmb.SelectedIndex = (int)widgetParam.Alignment;
             DefaultText.Text = widgetParam.Text;
             chkMutiline.IsChecked = widgetParam.IsMultiLine;
             IsLoadedData = true;
+
         }
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)
@@ -76,37 +90,18 @@ namespace Compdfkit_Tools.PDFControl
             FontSizeCmb.SelectedIndex = index;
         }
 
-        private void SetFontStyle(bool IsItalic, bool IsBold)
+        private void SetFontStyle(string fontStyle)
         {
-            int index = 0;
-            if (IsItalic && IsBold)
-            {
-                index = 3;
-            }
-            else if (IsItalic)
-            {
-                index = 2;
-            }
-            else if (IsBold)
-            {
-                index = 1;
-            }
-            FontStyleCmb.SelectedIndex = index;
+            FontStyleCmb.SelectedValue = fontStyle;
         }
 
         private void SetFontName(string fontName)
         {
-            int index = -1;
-            List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
-            for (int i = 0; i < fontFamilyList.Count; i++)
+            FontCmb.SelectedValue = fontName;
+            if (FontCmb.SelectedValue != null)
             {
-                if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
-                    || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
-                {
-                    index = i;
-                }
+                FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
             }
-            FontCmb.SelectedIndex = index;
         }
 
         #endregion
@@ -190,12 +185,16 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
+                FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
+                FontStyleCmb.SelectedIndex = 0;
+
                 var history = GetNewHistory();
                 CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isBold = IsBold(cTextAttribute.FontName);
-                bool isItalic = IsItalic(cTextAttribute.FontName);
-                FontType fontType = GetFontType((sender as ComboBox).SelectedItem?.ToString());
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
+
+                string psFontName = string.Empty;
+                CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                cTextAttribute.FontName = psFontName;
+
                 cPDFAnnotation.SetTextAttribute(cTextAttribute);
                 cPDFAnnotation.UpdateFormAp();
                 pdfViewerControl.UpdateAnnotFrame();
@@ -207,35 +206,23 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
-                var history = GetNewHistory();
-                CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                bool isItalic = false;
-                bool isBold = false;
-                switch ((sender as ComboBox).SelectedIndex)
+                if (isFontCmbClicked)
                 {
-                    case 0:
-                        break;
-                    case 1:
-                        isItalic = false;
-                        isBold = true;
-                        break;
-                    case 2:
-                        isItalic = true;
-                        isBold = false;
-                        break;
-                    case 3:
-                        isItalic = true;
-                        isBold = true;
-                        break;
-                    default:
-                        break;
+                    var history = GetNewHistory();
+                    CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
+                    string psFontName = string.Empty;
+                    CPDFFont.GetPostScriptName(FontCmb.SelectedValue.ToString(), FontStyleCmb.SelectedValue.ToString(), ref psFontName);
+                    cTextAttribute.FontName = psFontName;
+                    cPDFAnnotation.SetTextAttribute(cTextAttribute);
+                    cPDFAnnotation.UpdateFormAp();
+                    pdfViewerControl.UpdateAnnotFrame();
+                    AddHistory(history);
                 }
-                FontType fontType = GetFontType(cTextAttribute.FontName);
-                cTextAttribute.FontName = ObtainFontName(fontType, isBold, isItalic);
-                cPDFAnnotation.SetTextAttribute(cTextAttribute);
-                cPDFAnnotation.UpdateFormAp();
-                pdfViewerControl.UpdateAnnotFrame();
-                AddHistory(history);
+                else
+                {
+                    FontStyleCmb.ItemsSource = CPDFFont.GetFontNameDictionary()[FontCmb.SelectedValue.ToString()];
+                }
+                isFontCmbClicked = false;
             }
         }
 
@@ -243,13 +230,17 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (IsLoadedData)
             {
-                var history = GetNewHistory();
-                CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
-                cTextAttribute.FontSize = Convert.ToSingle((sender as ComboBox).SelectedItem);
-                cPDFAnnotation.SetTextAttribute(cTextAttribute);
-                cPDFAnnotation.UpdateFormAp();
-                pdfViewerControl.UpdateAnnotFrame();
-                AddHistory(history);
+                if (isFontStyleCmbClicked)
+                {
+                    var history = GetNewHistory();
+                    CTextAttribute cTextAttribute = cPDFAnnotation.GetTextAttribute();
+                    cTextAttribute.FontSize = Convert.ToSingle((sender as ComboBox).SelectedItem);
+                    cPDFAnnotation.SetTextAttribute(cTextAttribute);
+                    cPDFAnnotation.UpdateFormAp();
+                    pdfViewerControl.UpdateAnnotFrame();
+                    AddHistory(history);
+                }
+                isFontStyleCmbClicked = false;
             }
         }
 
@@ -314,5 +305,21 @@ namespace Compdfkit_Tools.PDFControl
         }
 
         #endregion
+
+        private void FontCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontCmbClicked = true;
+            }
+        }
+
+        private void FontStyleCmb_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Pressed && sender is ComboBox)
+            {
+                isFontStyleCmbClicked = true;
+            }
+        }
     }
 }