FontBoardVm.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. using ComPDFKitViewer.AnnotEvent;
  2. using PDF_Master.CustomControl.CompositeControl;
  3. using PDF_Master.Model.PropertyPanel.AnnotPanel;
  4. using PDFSettings;
  5. using Prism.Mvvm;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Media;
  13. namespace PDF_Master.Model.AnnotPanel
  14. {
  15. /// <summary>
  16. /// 注释-文本
  17. /// 设置字体大小、字体内容排版、字体颜色、字体样式、字重
  18. /// </summary>
  19. public class FontBoardVm : BindableBase
  20. {
  21. #region 变量
  22. public List<ComboDataItem> FontFamilyItems { get; protected set; }
  23. public List<ComboDataItem> FontStyleItems { get; protected set; }
  24. public List<ComboDataItem> FontSizeItems { get; protected set; }
  25. public List<ComboDataItem> PresetFontItems { get; protected set; }
  26. public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
  27. public FontBoardVm(bool isInitdata)
  28. {
  29. if (isInitdata)
  30. InitBaseVariable();
  31. }
  32. #endregion 变量
  33. #region 初始化下拉框或列表默认的数据
  34. protected void InitBaseVariable()
  35. {
  36. InitBase_PresetFontStyles();
  37. InitBase_FontFamilys();
  38. InitBase_FontStyles();
  39. InitBase_FontSize();
  40. }
  41. private void InitBase_FontSize()
  42. {
  43. FontSizeItems = TextFont.GetFontSize();
  44. }
  45. //预设字体样式
  46. private void InitBase_PresetFontStyles()
  47. {
  48. PresetFontItems = new List<ComboDataItem>();
  49. PresetFontList = TextFont.GetCachePresetFontList();
  50. foreach (var item in PresetFontList)
  51. {
  52. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  53. PresetFontItems.Add(itemData);
  54. }
  55. }
  56. //字体
  57. private void InitBase_FontFamilys()
  58. {
  59. FontFamilyItems = TextFont.GetFamily();
  60. }
  61. //字重
  62. private void InitBase_FontStyles()
  63. {
  64. FontStyleItems = TextFont.GetFontStyle();
  65. }
  66. #endregion 初始化下拉框或列表默认的数据
  67. #region 属性
  68. /// <summary>
  69. /// 预设样式
  70. /// </summary>
  71. private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
  72. public ComboDataItem CurrentPresetFont
  73. {
  74. get { return _currentPresetFont; }
  75. set
  76. {
  77. SetProperty(ref _currentPresetFont, value);
  78. switch (value.ValueStr.ToString())
  79. {
  80. case "Custom":
  81. PresetFontSelectedIndex = 0;
  82. break;
  83. case "H1":
  84. PresetFontSelectedIndex = 1;
  85. break;
  86. case "H2":
  87. PresetFontSelectedIndex = 2;
  88. break;
  89. case "H3":
  90. PresetFontSelectedIndex = 3;
  91. break;
  92. case "B1":
  93. PresetFontSelectedIndex = 4;
  94. break;
  95. case "B2":
  96. PresetFontSelectedIndex = 5;
  97. break;
  98. case "B3":
  99. PresetFontSelectedIndex = 6;
  100. break;
  101. default:
  102. PresetFontSelectedIndex = 0;
  103. break;
  104. }
  105. }
  106. }
  107. private int presetFontSelectedIndex;
  108. public int PresetFontSelectedIndex
  109. {
  110. get { return presetFontSelectedIndex; }
  111. set
  112. {
  113. SetProperty(ref presetFontSelectedIndex, value);
  114. }
  115. }
  116. #region 字体样式
  117. //下拉框列表
  118. private ComboDataItem _currentFontFamily = new ComboDataItem("Arial", "Arial");
  119. public ComboDataItem CurrentFontFamily
  120. {
  121. get { return _currentFontFamily; }
  122. set
  123. {
  124. SetProperty(ref _currentFontFamily, value);
  125. switch (value.Content.ToString())
  126. {
  127. case "Courier New":
  128. FontFamilySelectedIndex = 0;
  129. break;
  130. case "Arial":
  131. FontFamilySelectedIndex = 1;
  132. break;
  133. case "Times New Roman":
  134. FontFamilySelectedIndex = 2;
  135. break;
  136. case "Adobe Devanagari":
  137. FontFamilySelectedIndex = 3;
  138. break;
  139. }
  140. }
  141. }
  142. private int fontFamilySelectedIndex;
  143. public int FontFamilySelectedIndex
  144. {
  145. get { return fontFamilySelectedIndex; }
  146. set
  147. {
  148. SetProperty(ref fontFamilySelectedIndex, value);
  149. }
  150. }
  151. #endregion 字体样式
  152. #region 字体大小
  153. private int fontSizeSelectedIndex;
  154. public int FontSizeSelectedIndex
  155. {
  156. get { return fontSizeSelectedIndex; }
  157. set
  158. {
  159. SetProperty(ref fontSizeSelectedIndex, value);
  160. }
  161. }
  162. //下拉框列表:字体大小
  163. private ComboDataItem _currentFontSize = new ComboDataItem(6);
  164. public ComboDataItem CurrentFontSize
  165. {
  166. get { return _currentFontSize; }
  167. set
  168. {
  169. SetProperty(ref _currentFontSize, value);
  170. switch (value.Value)
  171. {
  172. case 8:
  173. FontSizeSelectedIndex = 0;
  174. break;
  175. case 9:
  176. FontSizeSelectedIndex = 1;
  177. break;
  178. case 10:
  179. FontSizeSelectedIndex = 2;
  180. break;
  181. case 11:
  182. FontSizeSelectedIndex = 3;
  183. break;
  184. case 12:
  185. FontSizeSelectedIndex = 4;
  186. break;
  187. case 14:
  188. FontSizeSelectedIndex = 5;
  189. break;
  190. case 16:
  191. FontSizeSelectedIndex = 6;
  192. break;
  193. case 18:
  194. FontSizeSelectedIndex = 7;
  195. break;
  196. case 20:
  197. FontSizeSelectedIndex = 8;
  198. break;
  199. case 22:
  200. FontSizeSelectedIndex = 9;
  201. break;
  202. case 24:
  203. FontSizeSelectedIndex = 10;
  204. break;
  205. case 26:
  206. FontSizeSelectedIndex = 11;
  207. break;
  208. case 28:
  209. FontSizeSelectedIndex = 12;
  210. break;
  211. case 36:
  212. FontSizeSelectedIndex = 13;
  213. break;
  214. case 48:
  215. FontSizeSelectedIndex = 14;
  216. break;
  217. case 72:
  218. FontSizeSelectedIndex = 15;
  219. break;
  220. default:
  221. //FontSizeSelectedIndex = 0;
  222. //FontSizeSelectedIndex = -1;
  223. break;
  224. }
  225. }
  226. }
  227. #endregion 字体大小
  228. //FontStyle & FontWeight
  229. private FontStyle _fontStyleItem;
  230. public FontStyle FontStyleItem
  231. {
  232. get { return _fontStyleItem; }
  233. set { SetProperty(ref _fontStyleItem, value); }
  234. }
  235. private FontWeight _fontWeight;
  236. public FontWeight FontWeightItem
  237. {
  238. get { return _fontWeight; }
  239. set { SetProperty(ref _fontWeight, value); }
  240. }
  241. private int fontStyleSelectedIndex;
  242. public int FontStyleSelectedIndex
  243. {
  244. get { return fontStyleSelectedIndex; }
  245. set
  246. {
  247. SetProperty(ref fontStyleSelectedIndex, value);
  248. }
  249. }
  250. private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
  251. public ComboDataItem CurrrentFontWeightStyle
  252. {
  253. get { return _currrentFontWeightStyle; }
  254. set
  255. {
  256. SetProperty(ref _currrentFontWeightStyle, value);
  257. switch (value.Content.ToString())
  258. {
  259. case "Regular":
  260. FontStyleSelectedIndex = 0;
  261. break;
  262. case "Bold":
  263. FontStyleSelectedIndex = 1;
  264. break;
  265. case "Italic":
  266. FontStyleSelectedIndex = 2;
  267. break;
  268. case "Bold Italic":
  269. FontStyleSelectedIndex = 3;
  270. break;
  271. }
  272. }
  273. }
  274. public void UpdateFontWeight_Style()
  275. {
  276. switch (CurrrentFontWeightStyle.ValueStr)
  277. {
  278. case "Regular":
  279. FontStyleItem = FontStyles.Normal;
  280. FontWeightItem = FontWeights.Normal;
  281. break;
  282. case "Bold":
  283. FontStyleItem = FontStyles.Normal;
  284. FontWeightItem = FontWeights.Bold;
  285. break;
  286. case "Italic":
  287. FontStyleItem = FontStyles.Italic;
  288. FontWeightItem = FontWeights.Normal;
  289. break;
  290. case "Bold Italic":
  291. FontStyleItem = FontStyles.Italic;
  292. FontWeightItem = FontWeights.Bold;
  293. break;
  294. }
  295. }
  296. //文字内容对齐
  297. private string _strtextAlign;
  298. public string StrTextAlign
  299. {
  300. get { return _strtextAlign; }
  301. set { SetProperty(ref _strtextAlign, value); }
  302. }
  303. //颜色
  304. private Brush _fontColor = new SolidColorBrush(Colors.Black);
  305. public Brush FontColor
  306. {
  307. get { return _fontColor; }
  308. set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; }
  309. }
  310. private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
  311. public Brush CurrentFontColor
  312. {
  313. get { return _currentFontColor; }
  314. set => SetProperty(ref _currentFontColor, value);
  315. }
  316. //外部UI引用,判断是否选中左对齐、居中对齐、右对齐,或都不选中
  317. public string strAglinState { get; private set; }
  318. //VM赋值
  319. public void SetStrAglinState(string str)
  320. {
  321. strAglinState = str;
  322. }
  323. #endregion 属性
  324. #region 列表选中赋值
  325. public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights)
  326. {
  327. string strValue = "";
  328. string strContent = "";
  329. if (fontStyle == FontStyles.Normal)
  330. {
  331. if (fontWeights == FontWeights.Normal)
  332. {
  333. strValue = "Regular";
  334. strContent = "Regular";
  335. }
  336. else
  337. {
  338. strValue = "Bold";
  339. strContent = "Bold";
  340. }
  341. }
  342. else
  343. {
  344. if (fontWeights == FontWeights.Normal)
  345. {
  346. strValue = "Italic";
  347. strContent = "Italic";
  348. }
  349. else
  350. {
  351. strValue = "Bold Italic";
  352. strContent = "Bold Italic";
  353. }
  354. }
  355. CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
  356. UpdateFontWeight_Style();
  357. }
  358. public void GetCurrentFontSize(int size)
  359. {
  360. CurrentFontSize = new ComboDataItem(size);
  361. }
  362. public void GetCurrentFontFamily(string fontFamily, string uiStr)
  363. {
  364. if (fontFamily == "Helvetica")
  365. {
  366. fontFamily = "Arial";
  367. uiStr = "Arial";
  368. }
  369. if (fontFamily == "Times-Roman")
  370. {
  371. uiStr = "Times New Roman";
  372. }
  373. if (fontFamily == "CourierNew")
  374. {
  375. uiStr = "Courier New";
  376. }
  377. if (fontFamily == "AdobeDevanagari")
  378. {
  379. uiStr = "Adobe Devanagari";
  380. }
  381. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  382. }
  383. public void GetCurrentPresetFont(string presetFont, string uiStr)
  384. {
  385. CurrentPresetFont = new ComboDataItem(presetFont, uiStr);
  386. }
  387. internal bool GetCurrentPresetFont(FreeTextAnnotArgs annot)
  388. {
  389. bool isExist = false;
  390. //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
  391. foreach (var item in PresetFontList)
  392. {
  393. if (annot.FontSize == item.mFontSize && annot.IsBold == (item.mFontWeight == FontWeights.Bold) && annot.IsItalic == (item.mFontStyle == FontStyles.Italic)
  394. && (annot.FontName == item.mFontFamily.Source || annot.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
  395. )
  396. {
  397. if (item.mTag != "Custom")
  398. {
  399. CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  400. isExist = true;
  401. }
  402. break;
  403. }
  404. }
  405. return isExist;
  406. }
  407. #endregion 列表选中赋值
  408. }
  409. }