FontBoard.cs 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Master.CustomControl.CompositeControl;
  4. using PDF_Master.Model.PropertyPanel.AnnotPanel;
  5. using PDFSettings;
  6. using Prism.Mvvm;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Diagnostics;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Media;
  16. namespace PDF_Master.Model.AnnotPanel
  17. {
  18. //属性触发事件的标识
  19. public enum FontSetModeType
  20. {
  21. PresetFontStyes,
  22. FontFamilys,
  23. FontSizes,
  24. FontWeight_Style,
  25. FontColor,
  26. TextAlignment
  27. }
  28. //设置字体大小、字体内容排版、字体颜色、字体样式、字重
  29. public class FontBoard : BindableBase
  30. {
  31. #region 变量
  32. protected event EventHandler<FontSetModeType> ChangedValue;
  33. protected bool IsCanSave = false;
  34. private List<ComboDataItem> _fontFamilyItems;
  35. public List<ComboDataItem> FontFamilyItems
  36. {
  37. get { return _fontFamilyItems; }
  38. set
  39. {
  40. SetProperty(ref _fontFamilyItems, value);
  41. }
  42. }
  43. public List<ComboDataItem> FontStyleItems { get; protected set; }
  44. public List<ComboDataItem> FontSizeItems { get; protected set; }
  45. public List<ComboDataItem> PresetFontItems { get; protected set; }
  46. public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
  47. #endregion 变量
  48. #region 初始化下拉框或列表默认的数据
  49. protected void InitBaseVariable()
  50. {
  51. InitBase_PresetFontStyles();
  52. InitBase_FontFamilys();
  53. InitBase_FontStyles();
  54. InitBase_FontSize();
  55. }
  56. //预设字体大小
  57. private void InitBase_FontSize()
  58. {
  59. FontSizeItems = TextFont.GetFontSize();
  60. }
  61. //预设字体样式
  62. private void InitBase_PresetFontStyles()
  63. {
  64. PresetFontItems = new List<ComboDataItem>();
  65. PresetFontList = TextFont.GetCachePresetFontList();
  66. foreach (var item in PresetFontList)
  67. {
  68. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  69. PresetFontItems.Add(itemData);
  70. }
  71. }
  72. //字体
  73. public void InitBase_FontFamilys()
  74. {
  75. FontFamilyItems = TextFont.GetFamilyEdit();
  76. }
  77. //字重
  78. private void InitBase_FontStyles()
  79. {
  80. FontStyleItems = TextFont.GetFontStyle();
  81. }
  82. #endregion 初始化下拉框或列表默认的数据
  83. #region 属性
  84. //文字内容对齐
  85. private string _strtextAlign;
  86. public string StrTextAlign
  87. {
  88. get { return _strtextAlign; }
  89. set { SetProperty(ref _strtextAlign, value); }
  90. }
  91. /// <summary>
  92. /// 预设样式
  93. /// </summary>
  94. private int presetFontSelectedIndex;
  95. public int PresetFontSelectedIndex
  96. {
  97. get { return presetFontSelectedIndex; }
  98. set
  99. {
  100. SetProperty(ref presetFontSelectedIndex, value);
  101. }
  102. }
  103. private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
  104. public ComboDataItem CurrentPresetFont
  105. {
  106. get { return _currentPresetFont; }
  107. set
  108. {
  109. bool isChange = IsEqualStrComboData(_currentPresetFont, value);
  110. SetProperty(ref _currentPresetFont, value);
  111. if (isChange)
  112. {
  113. ChangedValue?.Invoke(_currentPresetFont.ValueStr, FontSetModeType.PresetFontStyes);
  114. }
  115. SetProperty(ref _currentPresetFont, value);
  116. switch (value.ValueStr.ToString())
  117. {
  118. case "Custom":
  119. PresetFontSelectedIndex = 0;
  120. break;
  121. case "H1":
  122. PresetFontSelectedIndex = 1;
  123. break;
  124. case "H2":
  125. PresetFontSelectedIndex = 2;
  126. break;
  127. case "H3":
  128. PresetFontSelectedIndex = 3;
  129. break;
  130. case "B1":
  131. PresetFontSelectedIndex = 4;
  132. break;
  133. case "B2":
  134. PresetFontSelectedIndex = 5;
  135. break;
  136. case "B3":
  137. PresetFontSelectedIndex = 6;
  138. break;
  139. default:
  140. PresetFontSelectedIndex = 0;
  141. break;
  142. }
  143. }
  144. }
  145. #region 字体样式
  146. //下拉框列表
  147. private ComboDataItem _currentFontFamily = new ComboDataItem("Arial", "Arial");
  148. public ComboDataItem CurrentFontFamily
  149. {
  150. get { return _currentFontFamily; }
  151. set
  152. {
  153. bool isChange = IsEqualStrComboData(_currentFontFamily, value);
  154. SetProperty(ref _currentFontFamily, value);
  155. if (isChange)
  156. {
  157. string str = _currentFontFamily.Content;
  158. if (_currentFontFamily.Content == "Times New Roman")
  159. {
  160. str = "Times-Roman";
  161. }
  162. ChangedValue?.Invoke(str, FontSetModeType.FontFamilys);
  163. }
  164. SetProperty(ref _currentFontFamily, value);
  165. if (value.Content != null)
  166. {
  167. int index = FontFamilyItems.FindIndex(item => item.Content == value.Content);
  168. FontFamilySelectedIndex = index;
  169. Trace.WriteLine(index);
  170. }
  171. else
  172. {
  173. FontFamilySelectedIndex = 0;
  174. }
  175. }
  176. }
  177. private int fontFamilySelectedIndex = -1;
  178. public int FontFamilySelectedIndex
  179. {
  180. get { return fontFamilySelectedIndex; }
  181. set
  182. {
  183. SetProperty(ref fontFamilySelectedIndex, value);
  184. }
  185. }
  186. #endregion 字体样式
  187. #region 字体大小
  188. private int fontSizeSelectedIndex;
  189. public int FontSizeSelectedIndex
  190. {
  191. get { return fontSizeSelectedIndex; }
  192. set
  193. {
  194. SetProperty(ref fontSizeSelectedIndex, value);
  195. }
  196. }
  197. //下拉框列表:字体大小
  198. private ComboDataItem _currentFontSize = new ComboDataItem(6);
  199. public ComboDataItem CurrentFontSize
  200. {
  201. get { return _currentFontSize; }
  202. set
  203. {
  204. bool isChange = IsEqualComboData(_currentFontSize, value);
  205. SetProperty(ref _currentFontSize, value);
  206. if (isChange && value.Value > 0)
  207. {
  208. ChangedValue?.Invoke(_currentFontSize.Value, FontSetModeType.FontSizes);
  209. }
  210. SetProperty(ref _currentFontSize, value);
  211. switch (value.Value)
  212. {
  213. case 8:
  214. FontSizeSelectedIndex = 0;
  215. break;
  216. case 9:
  217. FontSizeSelectedIndex = 1;
  218. break;
  219. case 10:
  220. FontSizeSelectedIndex = 2;
  221. break;
  222. case 11:
  223. FontSizeSelectedIndex = 3;
  224. break;
  225. case 12:
  226. FontSizeSelectedIndex = 4;
  227. break;
  228. case 14:
  229. FontSizeSelectedIndex = 5;
  230. break;
  231. case 16:
  232. FontSizeSelectedIndex = 6;
  233. break;
  234. case 18:
  235. FontSizeSelectedIndex = 7;
  236. break;
  237. case 20:
  238. FontSizeSelectedIndex = 8;
  239. break;
  240. case 22:
  241. FontSizeSelectedIndex = 9;
  242. break;
  243. case 24:
  244. FontSizeSelectedIndex = 10;
  245. break;
  246. case 26:
  247. FontSizeSelectedIndex = 11;
  248. break;
  249. case 28:
  250. FontSizeSelectedIndex = 12;
  251. break;
  252. case 36:
  253. FontSizeSelectedIndex = 13;
  254. break;
  255. case 48:
  256. FontSizeSelectedIndex = 14;
  257. break;
  258. case 72:
  259. FontSizeSelectedIndex = 15;
  260. break;
  261. default:
  262. //FontSizeSelectedIndex = 0;
  263. //FontSizeSelectedIndex = -1;
  264. break;
  265. }
  266. }
  267. }
  268. #endregion 字体大小
  269. //FontStyle & FontWeight
  270. private FontStyle _fontStyle;
  271. public FontStyle FontStyleItem
  272. {
  273. get { return _fontStyle; }
  274. set { SetProperty(ref _fontStyle, value); }
  275. }
  276. private FontWeight _fontWeight;
  277. public FontWeight FontWeightItem
  278. {
  279. get { return _fontWeight; }
  280. set { SetProperty(ref _fontWeight, value); }
  281. }
  282. private int fontStyleSelectedIndex = 0;
  283. public int FontStyleSelectedIndex
  284. {
  285. get { return fontStyleSelectedIndex; }
  286. set
  287. {
  288. SetProperty(ref fontStyleSelectedIndex, value);
  289. }
  290. }
  291. private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
  292. public ComboDataItem CurrrentFontWeightStyle
  293. {
  294. get { return _currrentFontWeightStyle; }
  295. set
  296. {
  297. bool isChange = IsEqualStrComboData(_currrentFontWeightStyle, value);
  298. SetProperty(ref _currrentFontWeightStyle, value);
  299. if (isChange)
  300. {
  301. ChangedValue?.Invoke(_currrentFontWeightStyle, FontSetModeType.FontWeight_Style);
  302. }
  303. SetProperty(ref _currrentFontWeightStyle, value);
  304. switch (value.Content.ToString())
  305. {
  306. case "Regular":
  307. FontStyleSelectedIndex = 0;
  308. break;
  309. case "Bold":
  310. FontStyleSelectedIndex = 1;
  311. break;
  312. case "Italic":
  313. FontStyleSelectedIndex = 2;
  314. break;
  315. case "Bold Italic":
  316. FontStyleSelectedIndex = 3;
  317. break;
  318. }
  319. }
  320. }
  321. protected void UpdateFontWeight_Style()
  322. {
  323. switch (CurrrentFontWeightStyle.ValueStr)
  324. {
  325. case "Regular":
  326. FontStyleItem = FontStyles.Normal;
  327. FontWeightItem = FontWeights.Normal;
  328. break;
  329. case "Bold":
  330. FontStyleItem = FontStyles.Normal;
  331. FontWeightItem = FontWeights.Bold;
  332. break;
  333. case "Italic":
  334. FontStyleItem = FontStyles.Italic;
  335. FontWeightItem = FontWeights.Normal;
  336. break;
  337. case "Bold Italic":
  338. FontStyleItem = FontStyles.Italic;
  339. FontWeightItem = FontWeights.Bold;
  340. break;
  341. }
  342. }
  343. private C_TEXT_ALIGNMENT _textAlignment;
  344. public C_TEXT_ALIGNMENT TextAlignmentItem
  345. {
  346. get { return _textAlignment; }
  347. set { SetProperty(ref _textAlignment, value); }
  348. }
  349. //颜色
  350. private Brush selectColor = new SolidColorBrush(Colors.Black);
  351. public Brush SelectColor
  352. {
  353. get { return selectColor; }
  354. set
  355. {
  356. SetProperty(ref selectColor, value);
  357. if (IsCanSave)
  358. {
  359. ChangedValue?.Invoke((selectColor as SolidColorBrush).Color, FontSetModeType.FontColor);
  360. }
  361. else
  362. {
  363. CurrentFontColor = selectColor;
  364. }
  365. }
  366. }
  367. private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
  368. public Brush CurrentFontColor
  369. {
  370. get { return _currentFontColor; }
  371. set
  372. {
  373. SetProperty(ref _currentFontColor, value);
  374. }
  375. }
  376. private bool IsEqualComboData(ComboDataItem oldValue, ComboDataItem newValue)
  377. {
  378. if (newValue == null || IsCanSave == false)
  379. return false;
  380. if (oldValue != null && newValue != null)
  381. {
  382. if (oldValue.Value != newValue.Value)
  383. return true;
  384. }
  385. return false;
  386. }
  387. private bool IsEqualStrComboData(ComboDataItem oldValue, ComboDataItem newValue)
  388. {
  389. if (newValue == null || string.IsNullOrEmpty(newValue.ValueStr) == true || IsCanSave == false)
  390. return false;
  391. if (oldValue != null && newValue != null)
  392. {
  393. if (oldValue.ValueStr != newValue.ValueStr)
  394. return true;
  395. }
  396. return false;
  397. }
  398. #endregion 属性
  399. #region 列表选中赋值
  400. public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights)
  401. {
  402. string strValue = "";
  403. string strContent = "";
  404. if (fontStyle == FontStyles.Normal)
  405. {
  406. if (fontWeights == FontWeights.Normal)
  407. {
  408. strValue = "Regular";
  409. strContent = "Regular";
  410. }
  411. else
  412. {
  413. strValue = "Bold";
  414. strContent = "Bold";
  415. }
  416. }
  417. else
  418. {
  419. if (fontWeights == FontWeights.Normal)
  420. {
  421. strValue = "Italic";
  422. strContent = "Italic";
  423. }
  424. else
  425. {
  426. strValue = "Bold Italic";
  427. strContent = "Bold Italic";
  428. }
  429. }
  430. CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
  431. UpdateFontWeight_Style();
  432. }
  433. protected void GetCurrentFontSize(int size)
  434. {
  435. CurrentFontSize = new ComboDataItem(size);
  436. }
  437. protected void GetCurrentFontFamily(string fontFamily, string uiStr)
  438. {
  439. //SDK捕获到的字体会是Times-Roman
  440. if (fontFamily == "Times-Roman")
  441. {
  442. uiStr = "Times New Roman";
  443. }
  444. //WPF的UI字体不包含Helvetica
  445. if (fontFamily == "Helvetica")
  446. {
  447. fontFamily = "Arial";
  448. uiStr = "Arial";
  449. }
  450. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  451. }
  452. #endregion 列表选中赋值
  453. }
  454. //设置字体大小、字体内容排版、字体颜色、字体样式、字重
  455. public class FontBoardVm : BindableBase
  456. {
  457. #region 变量
  458. public List<ComboDataItem> FontFamilyItems { get; protected set; }
  459. public List<ComboDataItem> FontStyleItems { get; protected set; }
  460. public List<ComboDataItem> FontSizeItems { get; protected set; }
  461. public List<ComboDataItem> PresetFontItems { get; protected set; }
  462. public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
  463. public FontBoardVm(bool isInitdata)
  464. {
  465. if (isInitdata)
  466. InitBaseVariable();
  467. }
  468. #endregion 变量
  469. #region 初始化下拉框或列表默认的数据
  470. protected void InitBaseVariable()
  471. {
  472. InitBase_PresetFontStyles();
  473. InitBase_FontFamilys();
  474. InitBase_FontStyles();
  475. InitBase_FontSize();
  476. }
  477. private void InitBase_FontSize()
  478. {
  479. FontSizeItems = TextFont.GetFontSize();
  480. }
  481. //预设字体样式
  482. private void InitBase_PresetFontStyles()
  483. {
  484. PresetFontItems = new List<ComboDataItem>();
  485. PresetFontList = TextFont.GetCachePresetFontList();
  486. foreach (var item in PresetFontList)
  487. {
  488. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  489. PresetFontItems.Add(itemData);
  490. }
  491. }
  492. //字体
  493. private void InitBase_FontFamilys()
  494. {
  495. FontFamilyItems = TextFont.GetFamily();
  496. }
  497. //字重
  498. private void InitBase_FontStyles()
  499. {
  500. FontStyleItems = TextFont.GetFontStyle();
  501. }
  502. #endregion 初始化下拉框或列表默认的数据
  503. #region 属性
  504. /// <summary>
  505. /// 预设样式
  506. /// </summary>
  507. private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
  508. public ComboDataItem CurrentPresetFont
  509. {
  510. get { return _currentPresetFont; }
  511. set
  512. {
  513. SetProperty(ref _currentPresetFont, value);
  514. switch (value.ValueStr.ToString())
  515. {
  516. case "Custom":
  517. PresetFontSelectedIndex = 0;
  518. break;
  519. case "H1":
  520. PresetFontSelectedIndex = 1;
  521. break;
  522. case "H2":
  523. PresetFontSelectedIndex = 2;
  524. break;
  525. case "H3":
  526. PresetFontSelectedIndex = 3;
  527. break;
  528. case "B1":
  529. PresetFontSelectedIndex = 4;
  530. break;
  531. case "B2":
  532. PresetFontSelectedIndex = 5;
  533. break;
  534. case "B3":
  535. PresetFontSelectedIndex = 6;
  536. break;
  537. default:
  538. PresetFontSelectedIndex = 0;
  539. break;
  540. }
  541. }
  542. }
  543. private int presetFontSelectedIndex;
  544. public int PresetFontSelectedIndex
  545. {
  546. get { return presetFontSelectedIndex; }
  547. set
  548. {
  549. SetProperty(ref presetFontSelectedIndex, value);
  550. }
  551. }
  552. #region 字体样式
  553. //下拉框列表
  554. private ComboDataItem _currentFontFamily = new ComboDataItem("Arial", "Arial");
  555. public ComboDataItem CurrentFontFamily
  556. {
  557. get { return _currentFontFamily; }
  558. set
  559. {
  560. SetProperty(ref _currentFontFamily, value);
  561. switch (value.Content.ToString())
  562. {
  563. case "Courier New":
  564. FontFamilySelectedIndex = 0;
  565. break;
  566. case "Arial":
  567. FontFamilySelectedIndex = 1;
  568. break;
  569. case "Times New Roman":
  570. FontFamilySelectedIndex = 2;
  571. break;
  572. case "Adobe Devanagari":
  573. FontFamilySelectedIndex = 3;
  574. break;
  575. }
  576. }
  577. }
  578. private int fontFamilySelectedIndex;
  579. public int FontFamilySelectedIndex
  580. {
  581. get { return fontFamilySelectedIndex; }
  582. set
  583. {
  584. SetProperty(ref fontFamilySelectedIndex, value);
  585. }
  586. }
  587. #endregion 字体样式
  588. #region 字体大小
  589. private int fontSizeSelectedIndex;
  590. public int FontSizeSelectedIndex
  591. {
  592. get { return fontSizeSelectedIndex; }
  593. set
  594. {
  595. SetProperty(ref fontSizeSelectedIndex, value);
  596. }
  597. }
  598. //下拉框列表:字体大小
  599. private ComboDataItem _currentFontSize = new ComboDataItem(6);
  600. public ComboDataItem CurrentFontSize
  601. {
  602. get { return _currentFontSize; }
  603. set
  604. {
  605. SetProperty(ref _currentFontSize, value);
  606. switch (value.Value)
  607. {
  608. case 8:
  609. FontSizeSelectedIndex = 0;
  610. break;
  611. case 9:
  612. FontSizeSelectedIndex = 1;
  613. break;
  614. case 10:
  615. FontSizeSelectedIndex = 2;
  616. break;
  617. case 11:
  618. FontSizeSelectedIndex = 3;
  619. break;
  620. case 12:
  621. FontSizeSelectedIndex = 4;
  622. break;
  623. case 14:
  624. FontSizeSelectedIndex = 5;
  625. break;
  626. case 16:
  627. FontSizeSelectedIndex = 6;
  628. break;
  629. case 18:
  630. FontSizeSelectedIndex = 7;
  631. break;
  632. case 20:
  633. FontSizeSelectedIndex = 8;
  634. break;
  635. case 22:
  636. FontSizeSelectedIndex = 9;
  637. break;
  638. case 24:
  639. FontSizeSelectedIndex = 10;
  640. break;
  641. case 26:
  642. FontSizeSelectedIndex = 11;
  643. break;
  644. case 28:
  645. FontSizeSelectedIndex = 12;
  646. break;
  647. case 36:
  648. FontSizeSelectedIndex = 13;
  649. break;
  650. case 48:
  651. FontSizeSelectedIndex = 14;
  652. break;
  653. case 72:
  654. FontSizeSelectedIndex = 15;
  655. break;
  656. default:
  657. //FontSizeSelectedIndex = 0;
  658. //FontSizeSelectedIndex = -1;
  659. break;
  660. }
  661. }
  662. }
  663. #endregion 字体大小
  664. //FontStyle & FontWeight
  665. private FontStyle _fontStyleItem;
  666. public FontStyle FontStyleItem
  667. {
  668. get { return _fontStyleItem; }
  669. set { SetProperty(ref _fontStyleItem, value); }
  670. }
  671. private FontWeight _fontWeight;
  672. public FontWeight FontWeightItem
  673. {
  674. get { return _fontWeight; }
  675. set { SetProperty(ref _fontWeight, value); }
  676. }
  677. private int fontStyleSelectedIndex;
  678. public int FontStyleSelectedIndex
  679. {
  680. get { return fontStyleSelectedIndex; }
  681. set
  682. {
  683. SetProperty(ref fontStyleSelectedIndex, value);
  684. }
  685. }
  686. private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
  687. public ComboDataItem CurrrentFontWeightStyle
  688. {
  689. get { return _currrentFontWeightStyle; }
  690. set
  691. {
  692. SetProperty(ref _currrentFontWeightStyle, value);
  693. switch (value.Content.ToString())
  694. {
  695. case "Regular":
  696. FontStyleSelectedIndex = 0;
  697. break;
  698. case "Bold":
  699. FontStyleSelectedIndex = 1;
  700. break;
  701. case "Italic":
  702. FontStyleSelectedIndex = 2;
  703. break;
  704. case "Bold Italic":
  705. FontStyleSelectedIndex = 3;
  706. break;
  707. }
  708. }
  709. }
  710. public void UpdateFontWeight_Style()
  711. {
  712. switch (CurrrentFontWeightStyle.ValueStr)
  713. {
  714. case "Regular":
  715. FontStyleItem = FontStyles.Normal;
  716. FontWeightItem = FontWeights.Normal;
  717. break;
  718. case "Bold":
  719. FontStyleItem = FontStyles.Normal;
  720. FontWeightItem = FontWeights.Bold;
  721. break;
  722. case "Italic":
  723. FontStyleItem = FontStyles.Italic;
  724. FontWeightItem = FontWeights.Normal;
  725. break;
  726. case "Bold Italic":
  727. FontStyleItem = FontStyles.Italic;
  728. FontWeightItem = FontWeights.Bold;
  729. break;
  730. }
  731. }
  732. //文字内容对齐
  733. private string _strtextAlign;
  734. public string StrTextAlign
  735. {
  736. get { return _strtextAlign; }
  737. set { SetProperty(ref _strtextAlign, value); }
  738. }
  739. //颜色
  740. private Brush _fontColor = new SolidColorBrush(Colors.Black);
  741. public Brush FontColor
  742. {
  743. get { return _fontColor; }
  744. set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; }
  745. }
  746. private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
  747. public Brush CurrentFontColor
  748. {
  749. get { return _currentFontColor; }
  750. set => SetProperty(ref _currentFontColor, value);
  751. }
  752. //外部UI引用,判断是否选中左对齐、居中对齐、右对齐,或都不选中
  753. public string strAglinState { get; private set; }
  754. //VM赋值
  755. public void SetStrAglinState(string str)
  756. {
  757. strAglinState = str;
  758. }
  759. #endregion 属性
  760. #region 列表选中赋值
  761. public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights)
  762. {
  763. string strValue = "";
  764. string strContent = "";
  765. if (fontStyle == FontStyles.Normal)
  766. {
  767. if (fontWeights == FontWeights.Normal)
  768. {
  769. strValue = "Regular";
  770. strContent = "Regular";
  771. }
  772. else
  773. {
  774. strValue = "Bold";
  775. strContent = "Bold";
  776. }
  777. }
  778. else
  779. {
  780. if (fontWeights == FontWeights.Normal)
  781. {
  782. strValue = "Italic";
  783. strContent = "Italic";
  784. }
  785. else
  786. {
  787. strValue = "Bold Italic";
  788. strContent = "Bold Italic";
  789. }
  790. }
  791. CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
  792. UpdateFontWeight_Style();
  793. }
  794. public void GetCurrentFontSize(int size)
  795. {
  796. CurrentFontSize = new ComboDataItem(size);
  797. }
  798. public void GetCurrentFontFamily(string fontFamily, string uiStr)
  799. {
  800. if (fontFamily == "Helvetica")
  801. {
  802. fontFamily = "Arial";
  803. uiStr = "Arial";
  804. }
  805. if (fontFamily == "Times-Roman")
  806. {
  807. uiStr = "Times New Roman";
  808. }
  809. if (fontFamily == "CourierNew")
  810. {
  811. uiStr = "Courier New";
  812. }
  813. if (fontFamily == "AdobeDevanagari")
  814. {
  815. uiStr = "Adobe Devanagari";
  816. }
  817. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  818. }
  819. public void GetCurrentPresetFont(string presetFont, string uiStr)
  820. {
  821. CurrentPresetFont = new ComboDataItem(presetFont, uiStr);
  822. }
  823. internal bool GetCurrentPresetFont(FreeTextAnnotArgs annot)
  824. {
  825. bool isExist = false;
  826. //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
  827. foreach (var item in PresetFontList)
  828. {
  829. if (annot.FontSize == item.mFontSize && annot.IsBold == (item.mFontWeight == FontWeights.Bold) && annot.IsItalic == (item.mFontStyle == FontStyles.Italic)
  830. && (annot.FontName == item.mFontFamily.Source || annot.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
  831. )
  832. {
  833. if (item.mTag != "Custom")
  834. {
  835. CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  836. isExist = true;
  837. }
  838. break;
  839. }
  840. }
  841. return isExist;
  842. }
  843. #endregion 列表选中赋值
  844. }
  845. }