123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace compdfkit_tools.Common
- {
- /// <summary>
- /// CPDFFontUI.xaml 的交互逻辑
- /// </summary>
- public partial class CPDFFontUI : UserControl, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public event EventHandler FontChanged;
- public string FontFamilyValue
- {
- get => FontFamilyComboBox.SelectedItem.ToString();
- }
- public bool IsBold
- {
- get
- {
- if (FontStyleComboBox.SelectedItem.ToString() == null || (FontStyleComboBox.SelectedItem.ToString() == "Italic"))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- public bool IsItalic
- {
- get
- {
- if (FontStyleComboBox.SelectedItem.ToString() == null || (FontStyleComboBox.SelectedItem.ToString() == "Bold"))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- public TextAlignment TextAlignment
- {
- get
- {
- if ((bool)LeftAlignRadioButton.IsChecked)
- {
- return TextAlignment.Left;
- }
- else if ((bool)CenterAlignRadioButton.IsChecked)
- {
- return TextAlignment.Center;
- }
- else
- {
- return TextAlignment.Right;
- }
- }
- }
- private int _fontSizeValue = 20;
- public int FontSizeValue
- {
- get => _fontSizeValue;
- set
- {
- _fontSizeValue = value;
- OnPropertyChanged(nameof(FontSizeValue));
- OnFontChanged();
- FontChanged?.Invoke(this, EventArgs.Empty);
- }
- }
- public CPDFFontUI()
- {
- InitializeComponent();
- InitComboBox();
- this.DataContext = this;
- }
- public void InitComboBox()
- {
- List<string> fontNameList = new List<string>()
- {
- {"Courier New" },
- {"Helvetica" },
- {"Times Roman" }
- };
- FontFamilyComboBox.ItemsSource = fontNameList;
- FontFamilyComboBox.SelectedIndex = 1;
- List<string> fontStyleList = new List<string>()
- {
- {"Common" },
- {"Bold" },
- {"Italic" },
- {"Bold and Italic" }
- };
- FontStyleComboBox.ItemsSource = fontStyleList;
- FontStyleComboBox.SelectedIndex = 0;
- List<int> fontSizeList = new List<int>()
- {
- {6},
- {8},
- {9},
- {10},
- {12},
- {14},
- {18},
- {20},
- {24},
- {26},
- {28},
- {32},
- {30},
- {32},
- {48},
- {72}
- };
- FontSizeComboBox.InitPresetNumberArray(fontSizeList);
- }
- protected void OnPropertyChanged(string propertyName)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- private void FontFamilyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- FontChanged?.Invoke(this, EventArgs.Empty);
- }
- private void FontStyleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- FontChanged?.Invoke(this, EventArgs.Empty);
- }
- private void AlignRadioButton_Checked(object sender, RoutedEventArgs e)
- {
- FontChanged?.Invoke(this, EventArgs.Empty);
- }
- private void OnFontChanged()
- {
- FontChanged?.Invoke(this, EventArgs.Empty);
- }
- }
- }
|