FontStyleItem.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using PDF_Master.CustomControl.CompositeControl;
  2. using PDF_Master.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_Master.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. newItem.mFontFamily = cacheItem.mFontFamily;
  33. Settings.Default.PresetFontList.Add(newItem);
  34. }
  35. Settings.Default.Save();
  36. }
  37. else
  38. {
  39. foreach (var item in Settings.Default.PresetFontList)
  40. {
  41. var newItem = new PresetFontItem();
  42. newItem.mTag = item.mTag;
  43. newItem.mTagContent = item.mTagContent;
  44. newItem.mFontStyle = item.mFontStyle;
  45. newItem.mFontWeight = item.mFontWeight;
  46. newItem.mFontSize = item.mFontSize;
  47. newItem.mFontFamily = item.mFontFamily;
  48. cacheTempList.Add(newItem);
  49. }
  50. }
  51. return cacheTempList;
  52. }
  53. //保存到本地缓存数据
  54. public static void SavePresetFontList(List<PresetFontItem> list)
  55. {
  56. if (list == null) return;
  57. if(Settings.Default.PresetFontList == null)
  58. Settings.Default.PresetFontList = new PresetFontList();
  59. bool isCanSave = false;
  60. List<PresetFontItem> TempLists = new List<PresetFontItem>();
  61. foreach (var item in list)
  62. {
  63. var cacheItem = Settings.Default.PresetFontList.FirstOrDefault(temp => temp.mTag == item.mTag);
  64. if (cacheItem != null)
  65. {
  66. if(cacheItem.mFontFamily != item.mFontFamily ||
  67. cacheItem.mFontSize != item.mFontSize ||
  68. cacheItem.mFontStyle != item.mFontStyle ||
  69. cacheItem.mFontWeight != item.mFontWeight
  70. )
  71. {
  72. isCanSave = true;
  73. }
  74. break;
  75. }
  76. else
  77. {
  78. TempLists.Add(item);
  79. }
  80. }
  81. foreach(var itemTemp in TempLists)
  82. {
  83. Settings.Default.PresetFontList.Add(itemTemp);
  84. }
  85. if (isCanSave)
  86. Settings.Default.Save();
  87. }
  88. public static void BackDefaultPresetFontStyle(string tag)
  89. {
  90. bool isCanSave = false;
  91. var list = GetPresetFontStyle();
  92. var itemDefault = list.FirstOrDefault(temp => temp.mTag == tag);
  93. if (Settings.Default.PresetFontList == null)
  94. Settings.Default.PresetFontList = new PresetFontList();
  95. if(Settings.Default.PresetFontList.Count == 0)
  96. {
  97. Settings.Default.PresetFontList.Add(itemDefault);
  98. isCanSave = true;
  99. }
  100. else
  101. {
  102. foreach (var item in Settings.Default.PresetFontList)
  103. {
  104. if (item.mTag == itemDefault.mTag)
  105. {
  106. item.mTagContent = itemDefault.mTagContent;
  107. item.mFontFamily = itemDefault.mFontFamily;
  108. item.mFontWeight = itemDefault.mFontWeight;
  109. item.mFontStyle = itemDefault.mFontStyle;
  110. item.mFontSize = itemDefault.mFontSize;
  111. isCanSave = true;
  112. break;
  113. }
  114. }
  115. }
  116. if (isCanSave == true)
  117. Settings.Default.Save();
  118. }
  119. //获取拟定的预设样式
  120. public static List<PresetFontItem> GetPresetFontStyle()
  121. {
  122. List<PresetFontItem> fontStyleList = new List<PresetFontItem>();
  123. PresetFontItem custom = new PresetFontItem();
  124. custom.mTag = "custom";
  125. custom.mTagContent = "自定义";
  126. custom.mFontSize = 24;
  127. custom.mFontFamily = new FontFamily("Helvatica");
  128. custom.mFontStyle = FontStyles.Normal;
  129. custom.mFontWeight = FontWeights.Normal;
  130. PresetFontItem h1 = new PresetFontItem();
  131. h1.mTag = "H1";
  132. h1.mTagContent = "H1大标题";
  133. h1.mFontSize = 36;
  134. h1.mFontFamily = new FontFamily("Helvatica");
  135. h1.mFontStyle = FontStyles.Normal;
  136. h1.mFontWeight = FontWeights.Normal;
  137. PresetFontItem h2 = new PresetFontItem();
  138. h2.mTag = "H2";
  139. h2.mTagContent = "h2(标准)";
  140. h2.mFontSize = 24;
  141. h2.mFontFamily = new FontFamily("Helvatica");
  142. h2.mFontStyle = FontStyles.Normal;
  143. h2.mFontWeight = FontWeights.Bold;
  144. PresetFontItem h3 = new PresetFontItem();
  145. h3.mTag = "H3";
  146. h3.mTagContent = "H3小标题";
  147. h3.mFontSize = 18;
  148. h3.mFontFamily = new FontFamily("Helvatica");
  149. h3.mFontStyle = FontStyles.Normal;
  150. h3.mFontWeight = FontWeights.Bold;
  151. PresetFontItem b1 = new PresetFontItem();
  152. b1.mTag = "B1";
  153. b1.mTagContent = "B1标题";
  154. b1.mFontSize = 14;
  155. b1.mFontFamily = new FontFamily("Helvatica");
  156. b1.mFontStyle = FontStyles.Normal;
  157. b1.mFontWeight = FontWeights.Normal;
  158. PresetFontItem b2 = new PresetFontItem();
  159. b2.mTag = "B2";
  160. b2.mTagContent = "B2标题";
  161. b2.mFontSize = 12;
  162. b2.mFontFamily = new FontFamily("Helvatica");
  163. b2.mFontStyle = FontStyles.Normal;
  164. b2.mFontWeight = FontWeights.Normal;
  165. PresetFontItem b3 = new PresetFontItem();
  166. b3.mTag = "B3";
  167. b3.mTagContent = "B3标题";
  168. b3.mFontSize = 11;
  169. b3.mFontFamily = new FontFamily("Helvatica");
  170. b3.mFontStyle = FontStyles.Normal;
  171. b3.mFontWeight = FontWeights.Normal;
  172. fontStyleList.Add(custom);
  173. fontStyleList.Add(h1);
  174. fontStyleList.Add(h2);
  175. fontStyleList.Add(h3);
  176. fontStyleList.Add(b1);
  177. fontStyleList.Add(b2);
  178. fontStyleList.Add(b3);
  179. return fontStyleList;
  180. }
  181. public static List<ComboDataItem> GetFontStyle()
  182. {
  183. var FontStyleItems = new List<ComboDataItem>();
  184. ComboDataItem item = new ComboDataItem("Regular", "Regular");
  185. FontStyleItems.Add(item);
  186. item = new ComboDataItem("Bold", "Bold");
  187. FontStyleItems.Add(item);
  188. item = new ComboDataItem("Italic", "Italic");
  189. FontStyleItems.Add(item);
  190. item = new ComboDataItem("Bold Italic", "Bold Italic");
  191. FontStyleItems.Add(item);
  192. return FontStyleItems;
  193. }
  194. public static List<ComboDataItem> GetFamily()
  195. {
  196. var FontFamilyItems = new List<ComboDataItem>();
  197. ComboDataItem item = new ComboDataItem("Courier", "Courier New");
  198. FontFamilyItems.Add(item);
  199. item = new ComboDataItem("Arial", "Helvetica");
  200. FontFamilyItems.Add(item);
  201. item = new ComboDataItem(/*"Times-Roman"*/"Times", "Times New Roman");
  202. FontFamilyItems.Add(item);
  203. return FontFamilyItems;
  204. }
  205. public static List<ComboDataItem> GetDateFormats()
  206. {
  207. var dateFormatItems = new List<ComboDataItem>();
  208. foreach(var itemFormat in GetTimesFormats())
  209. {
  210. ComboDataItem item = new ComboDataItem(itemFormat, "format");
  211. dateFormatItems.Add(item);
  212. }
  213. return dateFormatItems;
  214. }
  215. private static List<string> GetTimesFormats()
  216. {
  217. List<string> TimesItems = new List<string>();
  218. TimesItems.Add("yyyy年M月d日");
  219. TimesItems.Add("M/d");
  220. TimesItems.Add("M/d/yy");
  221. TimesItems.Add("M/d/yyyy");
  222. TimesItems.Add("MM/dd/yy");
  223. TimesItems.Add("MM/dd/yyyy");
  224. TimesItems.Add("d/M/yy");
  225. TimesItems.Add("d/M/yyyy");
  226. TimesItems.Add("dd/MM/yy");
  227. TimesItems.Add("dd/MM/yyyy");
  228. TimesItems.Add("MM/yy");
  229. TimesItems.Add("MM/yyyy");
  230. TimesItems.Add("M.d.yy");
  231. TimesItems.Add("M.d.yyyy");
  232. TimesItems.Add("MM.dd.yy");
  233. TimesItems.Add("MM.dd.yyyy");
  234. TimesItems.Add("MM.yy");
  235. TimesItems.Add("MM.yyyy");
  236. TimesItems.Add("d.M.yy");
  237. TimesItems.Add("d.M.yyyy");
  238. TimesItems.Add("dd.MM.yy");
  239. TimesItems.Add("dd.MM.yyyy");
  240. TimesItems.Add("yy-MM-dd");
  241. TimesItems.Add("yyyy-MM-dd");
  242. return TimesItems;
  243. }
  244. }
  245. }