|
@@ -1,94 +1,54 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using ComPDFKit.PDFDocument;
|
|
|
using Compdfkit_Tools.Helper;
|
|
|
|
|
|
namespace Compdfkit_Tools.Common
|
|
|
{
|
|
|
public partial class CPDFFontUI : UserControl, INotifyPropertyChanged
|
|
|
{
|
|
|
+ internal bool lockFamilyName = false;
|
|
|
+ internal bool lockStyleName = false;
|
|
|
+
|
|
|
private string regular = LanguageHelper.PropertyPanelManager.GetString("Font_Regular");
|
|
|
private string bold = LanguageHelper.PropertyPanelManager.GetString("Font_Bold");
|
|
|
private string italic = LanguageHelper.PropertyPanelManager.GetString("Font_Oblique");
|
|
|
private string boldItalic = LanguageHelper.PropertyPanelManager.GetString("Font_BoldOblique");
|
|
|
+
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
public event EventHandler FontFamilyChanged;
|
|
|
public event EventHandler FontStyleChanged;
|
|
|
public event EventHandler FontSizeChanged;
|
|
|
public event EventHandler FontAlignChanged;
|
|
|
|
|
|
- public string FontFamilyValue
|
|
|
+ private string _familyName = string.Empty;
|
|
|
+ public string FamilyName
|
|
|
{
|
|
|
- get => FontFamilyComboBox.SelectedItem.ToString();
|
|
|
+ get => _familyName;
|
|
|
set
|
|
|
- {
|
|
|
- if (value == "Courier")
|
|
|
+ {
|
|
|
+ _familyName = value;
|
|
|
+ if (lockFamilyName && FontFamilyComboBox.Items.Contains(_familyName))
|
|
|
{
|
|
|
- FontFamilyComboBox.SelectedIndex = 0;
|
|
|
+ FontFamilyComboBox.SelectedItem = _familyName;
|
|
|
}
|
|
|
- else if (value == "Helvetica")
|
|
|
- {
|
|
|
- FontFamilyComboBox.SelectedIndex = 1;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- FontFamilyComboBox.SelectedIndex = 2;
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private bool _isBold;
|
|
|
- public bool IsBold
|
|
|
+ private string _styleName = string.Empty;
|
|
|
+ public string StyleName
|
|
|
{
|
|
|
- get => _isBold;
|
|
|
+ get => _styleName;
|
|
|
set
|
|
|
- {
|
|
|
- _isBold = value;
|
|
|
- if (_isBold && IsItalic)
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 3;
|
|
|
- }
|
|
|
- else if (_isBold && !IsItalic)
|
|
|
+ {
|
|
|
+ _styleName = value;
|
|
|
+ if (lockStyleName && FontStyleComboBox.Items.Contains(_styleName))
|
|
|
{
|
|
|
- FontStyleComboBox.SelectedIndex = 1;
|
|
|
- }
|
|
|
- else if (!_isBold && IsItalic)
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 2;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private bool _isItalic;
|
|
|
- public bool IsItalic
|
|
|
- {
|
|
|
- get => _isItalic;
|
|
|
- set
|
|
|
- {
|
|
|
- _isItalic = value;
|
|
|
- if (IsBold && _isItalic)
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 3;
|
|
|
- }
|
|
|
- else if (IsBold && !_isItalic)
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 1;
|
|
|
- }
|
|
|
- else if (!IsBold && _isItalic)
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 2;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- FontStyleComboBox.SelectedIndex = 0;
|
|
|
+ FontStyleComboBox.SelectedItem = _styleName;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -150,14 +110,8 @@ namespace Compdfkit_Tools.Common
|
|
|
|
|
|
public void InitComboBox()
|
|
|
{
|
|
|
- List<string> fontNameList = new List<string>()
|
|
|
- {
|
|
|
- {"Courier" },
|
|
|
- {"Helvetica" },
|
|
|
- {"Times" }
|
|
|
- };
|
|
|
- FontFamilyComboBox.ItemsSource = fontNameList;
|
|
|
- FontFamilyComboBox.SelectedIndex = 1;
|
|
|
+ FontFamilyComboBox.ItemsSource = CPDFFont.GetFontNameDictionary().Keys;
|
|
|
+ FontFamilyComboBox.SelectedIndex = 0;
|
|
|
|
|
|
List<string> fontStyleList = new List<string>()
|
|
|
{
|
|
@@ -166,7 +120,8 @@ namespace Compdfkit_Tools.Common
|
|
|
italic,
|
|
|
boldItalic
|
|
|
};
|
|
|
- FontStyleComboBox.ItemsSource = fontStyleList;
|
|
|
+
|
|
|
+ FontStyleComboBox.ItemsSource = CPDFFont.GetFontNameDictionary()[FontFamilyComboBox.SelectedValue.ToString()];
|
|
|
FontStyleComboBox.SelectedIndex = 0;
|
|
|
|
|
|
List<int> fontSizeList = new List<int>()
|
|
@@ -190,6 +145,7 @@ namespace Compdfkit_Tools.Common
|
|
|
};
|
|
|
FontSizeComboBox.InitPresetNumberArray(fontSizeList);
|
|
|
}
|
|
|
+
|
|
|
protected void OnPropertyChanged(string propertyName)
|
|
|
{
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
@@ -197,34 +153,29 @@ namespace Compdfkit_Tools.Common
|
|
|
|
|
|
private void FontFamilyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
- FontFamilyTextBox.Text = (sender as ComboBox).SelectedItem.ToString();
|
|
|
- FontFamilyChanged?.Invoke(this, EventArgs.Empty);
|
|
|
+ var styleNames = CPDFFont.GetFontNameDictionary()[FontFamilyComboBox.SelectedValue.ToString()];
|
|
|
+ FontStyleComboBox.ItemsSource = styleNames;
|
|
|
+ if (!lockFamilyName)
|
|
|
+ {
|
|
|
+ FamilyName = FontFamilyComboBox.SelectedValue.ToString();
|
|
|
+ if (styleNames.Count != 0)
|
|
|
+ {
|
|
|
+ FontStyleComboBox.SelectedIndex = 0;
|
|
|
+ }
|
|
|
+ FontStyleChanged?.Invoke(this, EventArgs.Empty);
|
|
|
+ }
|
|
|
+ lockFamilyName = false;
|
|
|
}
|
|
|
|
|
|
private void FontStyleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
- FontStyleTextBox.Text = (sender as ComboBox).SelectedItem.ToString();
|
|
|
- if (FontStyleTextBox.Text == regular)
|
|
|
- {
|
|
|
- IsBold = false;
|
|
|
- IsItalic = false;
|
|
|
- }
|
|
|
- else if (FontStyleTextBox.Text == italic)
|
|
|
- {
|
|
|
- IsBold = false;
|
|
|
- IsItalic = true;
|
|
|
- }
|
|
|
- else if (FontStyleTextBox.Text == bold)
|
|
|
- {
|
|
|
- IsBold = true;
|
|
|
- IsItalic = false;
|
|
|
- }
|
|
|
- else
|
|
|
+
|
|
|
+ if (!lockStyleName)
|
|
|
{
|
|
|
- IsBold = true;
|
|
|
- IsItalic = true;
|
|
|
+ StyleName = FontStyleComboBox.SelectedValue?.ToString();
|
|
|
+ FontStyleChanged?.Invoke(this, EventArgs.Empty);
|
|
|
}
|
|
|
- FontStyleChanged?.Invoke(this, EventArgs.Empty);
|
|
|
+ lockStyleName = false;
|
|
|
}
|
|
|
|
|
|
private void AlignRadioButton_Checked(object sender, RoutedEventArgs e)
|