CPDFFontUI.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace compdfkit_tools.Common
  17. {
  18. /// <summary>
  19. /// CPDFFontUI.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class CPDFFontUI : UserControl, INotifyPropertyChanged
  22. {
  23. public event PropertyChangedEventHandler PropertyChanged;
  24. public event EventHandler FontChanged;
  25. public string FontFamilyValue
  26. {
  27. get => FontFamilyComboBox.SelectedItem.ToString();
  28. }
  29. public bool IsBold
  30. {
  31. get
  32. {
  33. if (FontStyleComboBox.SelectedItem.ToString() == null || (FontStyleComboBox.SelectedItem.ToString() == "Italic"))
  34. {
  35. return false;
  36. }
  37. else
  38. {
  39. return true;
  40. }
  41. }
  42. }
  43. public bool IsItalic
  44. {
  45. get
  46. {
  47. if (FontStyleComboBox.SelectedItem.ToString() == null || (FontStyleComboBox.SelectedItem.ToString() == "Bold"))
  48. {
  49. return false;
  50. }
  51. else
  52. {
  53. return true;
  54. }
  55. }
  56. }
  57. public TextAlignment TextAlignment
  58. {
  59. get
  60. {
  61. if ((bool)LeftAlignRadioButton.IsChecked)
  62. {
  63. return TextAlignment.Left;
  64. }
  65. else if ((bool)CenterAlignRadioButton.IsChecked)
  66. {
  67. return TextAlignment.Center;
  68. }
  69. else
  70. {
  71. return TextAlignment.Right;
  72. }
  73. }
  74. }
  75. private int _fontSizeValue = 20;
  76. public int FontSizeValue
  77. {
  78. get => _fontSizeValue;
  79. set
  80. {
  81. _fontSizeValue = value;
  82. OnPropertyChanged(nameof(FontSizeValue));
  83. OnFontChanged();
  84. FontChanged?.Invoke(this, EventArgs.Empty);
  85. }
  86. }
  87. public CPDFFontUI()
  88. {
  89. InitializeComponent();
  90. InitComboBox();
  91. this.DataContext = this;
  92. }
  93. public void InitComboBox()
  94. {
  95. List<string> fontNameList = new List<string>()
  96. {
  97. {"Courier New" },
  98. {"Helvetica" },
  99. {"Times Roman" }
  100. };
  101. FontFamilyComboBox.ItemsSource = fontNameList;
  102. FontFamilyComboBox.SelectedIndex = 1;
  103. List<string> fontStyleList = new List<string>()
  104. {
  105. {"Common" },
  106. {"Bold" },
  107. {"Italic" },
  108. {"Bold and Italic" }
  109. };
  110. FontStyleComboBox.ItemsSource = fontStyleList;
  111. FontStyleComboBox.SelectedIndex = 0;
  112. List<int> fontSizeList = new List<int>()
  113. {
  114. {6},
  115. {8},
  116. {9},
  117. {10},
  118. {12},
  119. {14},
  120. {18},
  121. {20},
  122. {24},
  123. {26},
  124. {28},
  125. {32},
  126. {30},
  127. {32},
  128. {48},
  129. {72}
  130. };
  131. FontSizeComboBox.InitPresetNumberArray(fontSizeList);
  132. }
  133. protected void OnPropertyChanged(string propertyName)
  134. {
  135. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  136. }
  137. private void FontFamilyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  138. {
  139. FontChanged?.Invoke(this, EventArgs.Empty);
  140. }
  141. private void FontStyleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  142. {
  143. FontChanged?.Invoke(this, EventArgs.Empty);
  144. }
  145. private void AlignRadioButton_Checked(object sender, RoutedEventArgs e)
  146. {
  147. FontChanged?.Invoke(this, EventArgs.Empty);
  148. }
  149. private void OnFontChanged()
  150. {
  151. FontChanged?.Invoke(this, EventArgs.Empty);
  152. }
  153. }
  154. }