CPDFTextStyleUI.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace compdfkit_tools.Edit
  16. {
  17. /// <summary>
  18. /// CPDFFontStyleUI.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class CPDFTextStyleUI : UserControl
  21. {
  22. public event EventHandler<string> TextFontChanged;
  23. public event EventHandler<bool> TextBoldChanged;
  24. public event EventHandler<bool> TextItalicChanged;
  25. public CPDFTextStyleUI()
  26. {
  27. InitializeComponent();
  28. }
  29. public Orientation Orientation
  30. {
  31. get
  32. {
  33. return TextStyleUI.Orientation;
  34. }
  35. set
  36. {
  37. TextStyleUI.Orientation = value;
  38. }
  39. }
  40. public void SetFontNames(List<string> fontNames)
  41. {
  42. FontNameComboBox.Items?.Clear();
  43. if (fontNames != null && fontNames.Count > 0)
  44. {
  45. List<ComboBoxItem> fontNameList = new List<ComboBoxItem>();
  46. foreach (string fontName in fontNames)
  47. {
  48. fontNameList.Add(new ComboBoxItem()
  49. {
  50. Content = fontName
  51. });
  52. }
  53. FontNameComboBox.ItemsSource = fontNameList;
  54. }
  55. }
  56. public void SelectFontName(string fontName)
  57. {
  58. if(string.IsNullOrEmpty(fontName))
  59. {
  60. return;
  61. }
  62. List<ComboBoxItem> fontNameList = FontNameComboBox.ItemsSource as List<ComboBoxItem>;
  63. if (fontNameList != null && fontNameList.Count>0)
  64. {
  65. int selectIndex = -1;
  66. for(int i=0;i<fontNameList.Count; i++)
  67. {
  68. ComboBoxItem checkItem= fontNameList[i];
  69. if(checkItem.Content!=null && checkItem.Content.ToString().ToLower()==fontName.ToLower() )
  70. {
  71. selectIndex=i;
  72. break;
  73. }
  74. }
  75. FontNameComboBox.SelectedIndex = selectIndex;
  76. }
  77. }
  78. public void SetFontBold(bool isBold)
  79. {
  80. FontBoldBtn.IsChecked = isBold;
  81. }
  82. public void SetFontItalic(bool isItalic)
  83. {
  84. FontItalicBtn.IsChecked= isItalic;
  85. }
  86. private void FontNameComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  87. {
  88. if(FontNameComboBox.SelectedIndex==-1)
  89. {
  90. TextFontChanged?.Invoke(this,string.Empty);
  91. return;
  92. }
  93. ComboBoxItem selectItem= FontNameComboBox.SelectedItem as ComboBoxItem;
  94. if(selectItem != null && selectItem.Content != null)
  95. {
  96. TextFontChanged?.Invoke(this, selectItem.Content.ToString());
  97. }
  98. }
  99. private void FontBoldBtn_CheckChanged(object sender, RoutedEventArgs e)
  100. {
  101. TextBoldChanged?.Invoke(this, FontBoldBtn.IsChecked==true);
  102. }
  103. private void FontItalicBtn_CheckChanged(object sender, RoutedEventArgs e)
  104. {
  105. TextItalicChanged?.Invoke(this, FontItalicBtn.IsChecked == true);
  106. }
  107. }
  108. }