FontStyleItem.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using PDF_Office.CustomControl.CompositeControl;
  2. using PDF_Office.Properties;
  3. using PDFSettings;
  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.Model.PropertyPanel.AnnotPanel
  12. {
  13. public class TextFont
  14. {
  15. //获取本地缓存数据
  16. public static List<PresetFontItem> GetCachePresetFontList()
  17. {
  18. List<PresetFontItem> cacheTempList = new List<PresetFontItem>();
  19. if (Settings.Default.PresetFontList == null)
  20. Settings.Default.PresetFontList = new PresetFontList();
  21. if (Settings.Default.PresetFontList.Count == 0)
  22. {
  23. cacheTempList = GetPresetFontStyle();
  24. foreach(var cacheItem in cacheTempList)
  25. {
  26. var newItem = new PresetFontItem();
  27. newItem.mTag = cacheItem.mTag;
  28. newItem.mTagContent = cacheItem.mTagContent;
  29. newItem.mFontStyle = cacheItem.mFontStyle;
  30. newItem.mFontWeight = cacheItem.mFontWeight;
  31. newItem.mFontSize = cacheItem.mFontSize;
  32. Settings.Default.PresetFontList.Add(newItem);
  33. }
  34. Settings.Default.Save();
  35. }
  36. else
  37. {
  38. foreach (var item in Settings.Default.PresetFontList)
  39. {
  40. var newItem = new PresetFontItem();
  41. newItem.mTag = item.mTag;
  42. newItem.mTagContent = item.mTagContent;
  43. newItem.mFontStyle = item.mFontStyle;
  44. newItem.mFontWeight = item.mFontWeight;
  45. newItem.mFontSize = item.mFontSize;
  46. cacheTempList.Add(newItem);
  47. }
  48. }
  49. return cacheTempList;
  50. }
  51. //保存到本地缓存数据
  52. public static void SavePresetFontList(List<PresetFontItem> list)
  53. {
  54. if (list == null) return;
  55. if(Settings.Default.PresetFontList == null)
  56. Settings.Default.PresetFontList = new PresetFontList();
  57. bool isCanSave = false;
  58. List<PresetFontItem> TempLists = new List<PresetFontItem>();
  59. foreach (var item in list)
  60. {
  61. var cacheItem = Settings.Default.PresetFontList.FirstOrDefault(temp => temp.mTag == item.mTag);
  62. if (cacheItem != null)
  63. {
  64. if(cacheItem.mFontFamily != item.mFontFamily ||
  65. cacheItem.mFontSize != item.mFontSize ||
  66. cacheItem.mFontStyle != item.mFontStyle ||
  67. cacheItem.mFontWeight != item.mFontWeight
  68. )
  69. {
  70. isCanSave = true;
  71. }
  72. break;
  73. }
  74. else
  75. {
  76. TempLists.Add(item);
  77. }
  78. }
  79. foreach(var itemTemp in TempLists)
  80. {
  81. Settings.Default.PresetFontList.Add(itemTemp);
  82. }
  83. if (isCanSave)
  84. Settings.Default.Save();
  85. }
  86. public static void BackDefaultPresetFontStyle(string tag)
  87. {
  88. bool isCanSave = false;
  89. var list = GetPresetFontStyle();
  90. var itemDefault = list.FirstOrDefault(temp => temp.mTag == tag);
  91. if (Settings.Default.PresetFontList == null)
  92. Settings.Default.PresetFontList = new PresetFontList();
  93. if(Settings.Default.PresetFontList.Count == 0)
  94. {
  95. Settings.Default.PresetFontList.Add(itemDefault);
  96. isCanSave = true;
  97. }
  98. else
  99. {
  100. foreach (var item in Settings.Default.PresetFontList)
  101. {
  102. if (item.mTag == itemDefault.mTag)
  103. {
  104. item.mFontFamily = itemDefault.mFontFamily;
  105. item.mFontWeight = itemDefault.mFontWeight;
  106. item.mFontStyle = itemDefault.mFontStyle;
  107. item.mFontSize = itemDefault.mFontSize;
  108. isCanSave = true;
  109. break;
  110. }
  111. }
  112. }
  113. if (isCanSave == true)
  114. Settings.Default.Save();
  115. }
  116. //获取拟定的预设样式
  117. private static List<PresetFontItem> GetPresetFontStyle()
  118. {
  119. List<PresetFontItem> fontStyleList = new List<PresetFontItem>();
  120. PresetFontItem custom = new PresetFontItem();
  121. custom.mTag = "custom";
  122. custom.mTagContent = "自定义";
  123. custom.mFontSize = 24;
  124. custom.mFontFamily = new FontFamily("Helvatica");
  125. custom.mFontStyle = FontStyles.Normal;
  126. custom.mFontWeight = FontWeights.Normal;
  127. PresetFontItem h1 = new PresetFontItem();
  128. h1.mTag = "H1";
  129. h1.mTagContent = "H1大标题";
  130. h1.mFontSize = 36;
  131. h1.mFontFamily = new FontFamily("Helvatica");
  132. h1.mFontStyle = FontStyles.Normal;
  133. h1.mFontWeight = FontWeights.Normal;
  134. PresetFontItem h2 = new PresetFontItem();
  135. h2.mTag = "H2";
  136. h2.mTagContent = "h2(标准)";
  137. h2.mFontSize = 24;
  138. h2.mFontFamily = new FontFamily("Helvatica");
  139. h2.mFontStyle = FontStyles.Normal;
  140. h2.mFontWeight = FontWeights.Bold;
  141. PresetFontItem h3 = new PresetFontItem();
  142. h3.mTag = "H3";
  143. h3.mTagContent = "H3小标题";
  144. h3.mFontSize = 18;
  145. h3.mFontFamily = new FontFamily("Helvatica");
  146. h3.mFontStyle = FontStyles.Normal;
  147. h3.mFontWeight = FontWeights.Bold;
  148. PresetFontItem b1 = new PresetFontItem();
  149. b1.mTag = "B1";
  150. b1.mTagContent = "B1标题";
  151. b1.mFontSize = 14;
  152. b1.mFontFamily = new FontFamily("Helvatica");
  153. b1.mFontStyle = FontStyles.Normal;
  154. b1.mFontWeight = FontWeights.Normal;
  155. PresetFontItem b2 = new PresetFontItem();
  156. b2.mTag = "B2";
  157. b2.mTagContent = "B2标题";
  158. b2.mFontSize = 12;
  159. b2.mFontFamily = new FontFamily("Helvatica");
  160. b2.mFontStyle = FontStyles.Normal;
  161. b2.mFontWeight = FontWeights.Normal;
  162. PresetFontItem b3 = new PresetFontItem();
  163. b3.mTag = "B3";
  164. b3.mTagContent = "B3标题";
  165. b3.mFontSize = 11;
  166. b3.mFontFamily = new FontFamily("Helvatica");
  167. b3.mFontStyle = FontStyles.Normal;
  168. b3.mFontWeight = FontWeights.Normal;
  169. fontStyleList.Add(custom);
  170. fontStyleList.Add(h1);
  171. fontStyleList.Add(h2);
  172. fontStyleList.Add(h3);
  173. fontStyleList.Add(b1);
  174. fontStyleList.Add(b2);
  175. fontStyleList.Add(b3);
  176. return fontStyleList;
  177. }
  178. public static List<ComboDataItem> GetFontStyle()
  179. {
  180. var FontStyleItems = new List<ComboDataItem>();
  181. ComboDataItem item = new ComboDataItem("Regular", "Regular");
  182. FontStyleItems.Add(item);
  183. item = new ComboDataItem("Bold", "Bold");
  184. FontStyleItems.Add(item);
  185. item = new ComboDataItem("Italic", "Italic");
  186. FontStyleItems.Add(item);
  187. item = new ComboDataItem("Bold Italic", "Bold Italic");
  188. FontStyleItems.Add(item);
  189. return FontStyleItems;
  190. }
  191. public static List<ComboDataItem> GetFamily()
  192. {
  193. var FontFamilyItems = new List<ComboDataItem>();
  194. ComboDataItem item = new ComboDataItem("Courier", "Courier New");
  195. FontFamilyItems.Add(item);
  196. item = new ComboDataItem("Helvetica", "Helvetica");
  197. FontFamilyItems.Add(item);
  198. item = new ComboDataItem("Times-Roman", "Times New Roman");
  199. FontFamilyItems.Add(item);
  200. return FontFamilyItems;
  201. }
  202. }
  203. }