FontSetModeVM.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using PDF_Office.CustomControl.CompositeControl;
  2. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Media;
  11. namespace PDF_Office.ViewModels.PropertyPanel
  12. {
  13. //属性触发事件的标识
  14. public enum FontSetModeType
  15. {
  16. PresetFontStyes,
  17. FontFamilys,
  18. FontSizes,
  19. FontWeight_Style,
  20. FontColor
  21. }
  22. public class FontSetMode : BindableBase
  23. {
  24. #region 变量
  25. public event EventHandler<FontSetModeType> ChangedValue;
  26. public List<ComboDataItem> FontFamilyItems { get; protected set; }
  27. public List<ComboDataItem> FontStyleItems { get; protected set; }
  28. public List<ComboDataItem> PresetTextItems { get; protected set; }
  29. public List<FontStyleItem> FontStyleList = new List<FontStyleItem>();
  30. #endregion
  31. #region 初始化下拉框或列表默认的数据
  32. protected void InitBaseVariable()
  33. {
  34. InitBase_PresetFontStyles();
  35. InitBase_FontFamilys();
  36. InitBase_FontStyles();
  37. }
  38. //预设字体样式
  39. private void InitBase_PresetFontStyles()
  40. {
  41. PresetTextItems = new List<ComboDataItem>();
  42. FontStyleList = TextFont.GetPresetFontStyle();
  43. foreach (var item in FontStyleList)
  44. {
  45. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  46. PresetTextItems.Add(itemData);
  47. }
  48. }
  49. //字体
  50. private void InitBase_FontFamilys()
  51. {
  52. FontFamilyItems = TextFont.GetFamily();
  53. }
  54. //字重
  55. private void InitBase_FontStyles()
  56. {
  57. FontStyleItems = TextFont.GetFontStyle();
  58. }
  59. #endregion
  60. #region 属性
  61. private ComboDataItem _presetTextData;
  62. public ComboDataItem PresetTextData
  63. {
  64. get { return _presetTextData; }
  65. set
  66. {
  67. SetProperty(ref _presetTextData, value);
  68. if (_presetTextData != null)
  69. {
  70. ChangedValue?.Invoke(_presetTextData.ValueStr, FontSetModeType.PresetFontStyes);
  71. }
  72. }
  73. }
  74. //字体样式
  75. private ComboDataItem _fontFamilyData;
  76. public ComboDataItem FontFamilyData
  77. {
  78. get { return _fontFamilyData; }
  79. set
  80. {
  81. SetProperty(ref _fontFamilyData, value);
  82. if(_fontFamilyData != null)
  83. {
  84. ChangedValue?.Invoke(_fontFamilyData.ValueStr, FontSetModeType.FontFamilys);
  85. }
  86. }
  87. }
  88. //字体大小
  89. private ComboDataItem _fontSizeData = new ComboDataItem(6);
  90. public ComboDataItem FontSizeData
  91. {
  92. get { return _fontSizeData; }
  93. set
  94. {
  95. SetProperty(ref _fontSizeData, value);
  96. if(_fontSizeData != null)
  97. {
  98. ChangedValue?.Invoke(_fontSizeData.Value, FontSetModeType.FontSizes);
  99. }
  100. }
  101. }
  102. //FontStyle & FontWeight
  103. private FontStyle _fontStyle;
  104. public FontStyle FontStyleItem
  105. {
  106. get { return _fontStyle; }
  107. set { SetProperty(ref _fontStyle, value); }
  108. }
  109. private FontWeight _fontWeight;
  110. public FontWeight FontWeightItem
  111. {
  112. get { return _fontWeight; }
  113. set { SetProperty(ref _fontWeight, value); }
  114. }
  115. private ComboDataItem _fontWeightStyleItem;
  116. public ComboDataItem FontWeightStyleItem
  117. {
  118. get { return _fontWeightStyleItem; }
  119. set
  120. {
  121. SetProperty(ref _fontWeightStyleItem, value);
  122. if (_fontWeightStyleItem.ValueStr != null && string.IsNullOrEmpty((string)_fontWeightStyleItem.ValueStr) == false)
  123. {
  124. if(_fontWeightStyleItem != null)
  125. {
  126. ChangedValue?.Invoke(null, FontSetModeType.FontWeight_Style);
  127. }
  128. }
  129. }
  130. }
  131. protected void UpdateFontWeight_Style()
  132. {
  133. switch (FontWeightStyleItem.ValueStr)
  134. {
  135. case "Regular":
  136. FontStyleItem = FontStyles.Normal;
  137. FontWeightItem = FontWeights.Normal;
  138. break;
  139. case "Bold":
  140. FontStyleItem = FontStyles.Normal;
  141. FontWeightItem = FontWeights.Bold;
  142. break;
  143. case "Italic":
  144. FontStyleItem = FontStyles.Italic;
  145. FontWeightItem = FontWeights.Normal;
  146. break;
  147. case "Bold Italic":
  148. FontStyleItem = FontStyles.Italic;
  149. FontWeightItem = FontWeights.Bold;
  150. break;
  151. }
  152. }
  153. //颜色
  154. private Brush selectColor = new SolidColorBrush(Colors.Black);
  155. public Brush SelectColor
  156. {
  157. get { return selectColor; }
  158. set
  159. {
  160. SetProperty(ref selectColor, value);
  161. ChangedValue?.Invoke((selectColor as SolidColorBrush).Color, FontSetModeType.FontColor);
  162. }
  163. }
  164. #endregion
  165. }
  166. }