FontBoard.cs 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Media;
  14. namespace PDF_Master.Model.AnnotPanel
  15. {
  16. //属性触发事件的标识
  17. public enum FontSetModeType
  18. {
  19. PresetFontStyes,
  20. FontFamilys,
  21. FontSizes,
  22. FontWeight_Style,
  23. FontColor,
  24. TextAlignment
  25. }
  26. //设置字体大小、字体内容排版、字体颜色、字体样式、字重
  27. public class FontBoard : BindableBase
  28. {
  29. #region 变量
  30. protected event EventHandler<FontSetModeType> ChangedValue;
  31. protected bool IsCanSave = false;
  32. public List<ComboDataItem> FontFamilyItems { get; protected set; }
  33. public List<ComboDataItem> FontStyleItems { get; protected set; }
  34. public List<ComboDataItem> FontSizeItems { get; protected set; }
  35. public List<ComboDataItem> PresetFontItems { get; protected set; }
  36. public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
  37. #endregion 变量
  38. #region 初始化下拉框或列表默认的数据
  39. protected void InitBaseVariable()
  40. {
  41. InitBase_PresetFontStyles();
  42. InitBase_FontFamilys();
  43. InitBase_FontStyles();
  44. InitBase_FontSize();
  45. }
  46. //预设字体大小
  47. private void InitBase_FontSize()
  48. {
  49. FontSizeItems = TextFont.GetFontSize();
  50. }
  51. //预设字体样式
  52. private void InitBase_PresetFontStyles()
  53. {
  54. PresetFontItems = new List<ComboDataItem>();
  55. PresetFontList = TextFont.GetCachePresetFontList();
  56. foreach (var item in PresetFontList)
  57. {
  58. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  59. PresetFontItems.Add(itemData);
  60. }
  61. }
  62. //字体
  63. private void InitBase_FontFamilys()
  64. {
  65. FontFamilyItems = TextFont.GetFamily();
  66. }
  67. //字重
  68. private void InitBase_FontStyles()
  69. {
  70. FontStyleItems = TextFont.GetFontStyle();
  71. }
  72. #endregion 初始化下拉框或列表默认的数据
  73. #region 属性
  74. //文字内容对齐
  75. private string _strtextAlign;
  76. public string StrTextAlign
  77. {
  78. get { return _strtextAlign; }
  79. set { SetProperty(ref _strtextAlign, value); }
  80. }
  81. /// <summary>
  82. /// 预设样式
  83. /// </summary>
  84. private int presetFontSelectedIndex;
  85. public int PresetFontSelectedIndex
  86. {
  87. get { return presetFontSelectedIndex; }
  88. set
  89. {
  90. SetProperty(ref presetFontSelectedIndex, value);
  91. }
  92. }
  93. private ComboDataItem _currentPresetFont=new ComboDataItem("Custom", "Custom");
  94. public ComboDataItem CurrentPresetFont
  95. {
  96. get { return _currentPresetFont; }
  97. set
  98. {
  99. bool isChange = IsEqualStrComboData(_currentPresetFont, value);
  100. SetProperty(ref _currentPresetFont, value);
  101. if (isChange)
  102. {
  103. ChangedValue?.Invoke(_currentPresetFont.ValueStr, FontSetModeType.PresetFontStyes);
  104. }
  105. SetProperty(ref _currentPresetFont, value);
  106. switch (value.ValueStr.ToString())
  107. {
  108. case "Custom":
  109. PresetFontSelectedIndex = 0;
  110. break;
  111. case "H1":
  112. PresetFontSelectedIndex = 1;
  113. break;
  114. case "H2":
  115. PresetFontSelectedIndex = 2;
  116. break;
  117. case "H3":
  118. PresetFontSelectedIndex = 3;
  119. break;
  120. case "B1":
  121. PresetFontSelectedIndex = 4;
  122. break;
  123. case "B2":
  124. PresetFontSelectedIndex = 5;
  125. break;
  126. case "B3":
  127. PresetFontSelectedIndex = 6;
  128. break;
  129. default:
  130. PresetFontSelectedIndex = 0;
  131. break;
  132. }
  133. }
  134. }
  135. #region 字体样式
  136. //下拉框列表
  137. private ComboDataItem _currentFontFamily = new ComboDataItem("Helvetica", "Helvetica");
  138. public ComboDataItem CurrentFontFamily
  139. {
  140. get { return _currentFontFamily; }
  141. set
  142. {
  143. bool isChange = IsEqualStrComboData(_currentFontFamily, value);
  144. SetProperty(ref _currentFontFamily, value);
  145. if (isChange)
  146. {
  147. string str= _currentFontFamily.ValueStr;
  148. if (_currentFontFamily.ValueStr== "Times")
  149. {
  150. str = "Times-Roman";
  151. }
  152. else if(_currentFontFamily.ValueStr== "Courier")
  153. {
  154. str = "Courier New";
  155. }
  156. ChangedValue?.Invoke(str, FontSetModeType.FontFamilys);
  157. }
  158. SetProperty(ref _currentFontFamily, value);
  159. if (value.Content != null)
  160. {
  161. switch (value.Content.ToString())
  162. {
  163. case "Courier New":
  164. FontFamilySelectedIndex = 0;
  165. break;
  166. case "Helvetica":
  167. case "Arial":
  168. FontFamilySelectedIndex = 1;
  169. break;
  170. case "Times New Roman":
  171. FontFamilySelectedIndex = 2;
  172. break;
  173. }
  174. }
  175. else
  176. {
  177. FontFamilySelectedIndex = 0;
  178. }
  179. }
  180. }
  181. private int fontFamilySelectedIndex = 0;
  182. public int FontFamilySelectedIndex
  183. {
  184. get { return fontFamilySelectedIndex; }
  185. set
  186. {
  187. SetProperty(ref fontFamilySelectedIndex, value);
  188. }
  189. }
  190. #endregion 字体样式
  191. #region 字体大小
  192. private int fontSizeSelectedIndex;
  193. public int FontSizeSelectedIndex
  194. {
  195. get { return fontSizeSelectedIndex; }
  196. set
  197. {
  198. SetProperty(ref fontSizeSelectedIndex, value);
  199. }
  200. }
  201. //下拉框列表:字体大小
  202. private ComboDataItem _currentFontSize = new ComboDataItem(6);
  203. public ComboDataItem CurrentFontSize
  204. {
  205. get { return _currentFontSize; }
  206. set
  207. {
  208. bool isChange = IsEqualComboData(_currentFontSize, value);
  209. SetProperty(ref _currentFontSize, value);
  210. if (isChange && value.Value > 0)
  211. {
  212. ChangedValue?.Invoke(_currentFontSize.Value, FontSetModeType.FontSizes);
  213. }
  214. SetProperty(ref _currentFontSize, value);
  215. switch (value.Value)
  216. {
  217. case 8:
  218. FontSizeSelectedIndex = 0;
  219. break;
  220. case 9:
  221. FontSizeSelectedIndex = 1;
  222. break;
  223. case 10:
  224. FontSizeSelectedIndex = 2;
  225. break;
  226. case 11:
  227. FontSizeSelectedIndex = 3;
  228. break;
  229. case 12:
  230. FontSizeSelectedIndex = 4;
  231. break;
  232. case 14:
  233. FontSizeSelectedIndex = 5;
  234. break;
  235. case 16:
  236. FontSizeSelectedIndex = 6;
  237. break;
  238. case 18:
  239. FontSizeSelectedIndex = 7;
  240. break;
  241. case 20:
  242. FontSizeSelectedIndex = 8;
  243. break;
  244. case 22:
  245. FontSizeSelectedIndex = 9;
  246. break;
  247. case 24:
  248. FontSizeSelectedIndex = 10;
  249. break;
  250. case 26:
  251. FontSizeSelectedIndex = 11;
  252. break;
  253. case 28:
  254. FontSizeSelectedIndex = 12;
  255. break;
  256. case 36:
  257. FontSizeSelectedIndex = 13;
  258. break;
  259. case 48:
  260. FontSizeSelectedIndex = 14;
  261. break;
  262. case 72:
  263. FontSizeSelectedIndex = 15;
  264. break;
  265. default:
  266. //FontSizeSelectedIndex = 0;
  267. //FontSizeSelectedIndex = -1;
  268. break;
  269. }
  270. }
  271. }
  272. #endregion 字体大小
  273. //FontStyle & FontWeight
  274. private FontStyle _fontStyle;
  275. public FontStyle FontStyleItem
  276. {
  277. get { return _fontStyle; }
  278. set { SetProperty(ref _fontStyle, value); }
  279. }
  280. private FontWeight _fontWeight;
  281. public FontWeight FontWeightItem
  282. {
  283. get { return _fontWeight; }
  284. set { SetProperty(ref _fontWeight, value); }
  285. }
  286. private int fontStyleSelectedIndex = 0;
  287. public int FontStyleSelectedIndex
  288. {
  289. get { return fontStyleSelectedIndex; }
  290. set
  291. {
  292. SetProperty(ref fontStyleSelectedIndex, value);
  293. }
  294. }
  295. private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
  296. public ComboDataItem CurrrentFontWeightStyle
  297. {
  298. get { return _currrentFontWeightStyle; }
  299. set
  300. {
  301. bool isChange = IsEqualStrComboData(_currrentFontWeightStyle, value);
  302. SetProperty(ref _currrentFontWeightStyle, value);
  303. if (isChange)
  304. {
  305. ChangedValue?.Invoke(_currrentFontWeightStyle, FontSetModeType.FontWeight_Style);
  306. }
  307. SetProperty(ref _currrentFontWeightStyle, value);
  308. switch (value.Content.ToString())
  309. {
  310. case "Regular":
  311. FontStyleSelectedIndex = 0;
  312. break;
  313. case "Bold":
  314. FontStyleSelectedIndex = 1;
  315. break;
  316. case "Italic":
  317. FontStyleSelectedIndex = 2;
  318. break;
  319. case "Bold Italic":
  320. FontStyleSelectedIndex = 3;
  321. break;
  322. }
  323. }
  324. }
  325. protected void UpdateFontWeight_Style()
  326. {
  327. switch (CurrrentFontWeightStyle.ValueStr)
  328. {
  329. case "Regular":
  330. FontStyleItem = FontStyles.Normal;
  331. FontWeightItem = FontWeights.Normal;
  332. break;
  333. case "Bold":
  334. FontStyleItem = FontStyles.Normal;
  335. FontWeightItem = FontWeights.Bold;
  336. break;
  337. case "Italic":
  338. FontStyleItem = FontStyles.Italic;
  339. FontWeightItem = FontWeights.Normal;
  340. break;
  341. case "Bold Italic":
  342. FontStyleItem = FontStyles.Italic;
  343. FontWeightItem = FontWeights.Bold;
  344. break;
  345. }
  346. }
  347. private C_TEXT_ALIGNMENT _textAlignment;
  348. public C_TEXT_ALIGNMENT TextAlignmentItem
  349. {
  350. get { return _textAlignment; }
  351. set { SetProperty(ref _textAlignment, value); }
  352. }
  353. //颜色
  354. private Brush selectColor = new SolidColorBrush(Colors.Black);
  355. public Brush SelectColor
  356. {
  357. get { return selectColor; }
  358. set
  359. {
  360. SetProperty(ref selectColor, value);
  361. if (IsCanSave)
  362. {
  363. ChangedValue?.Invoke((selectColor as SolidColorBrush).Color, FontSetModeType.FontColor);
  364. }
  365. else
  366. {
  367. CurrentFontColor = selectColor;
  368. }
  369. }
  370. }
  371. private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
  372. public Brush CurrentFontColor
  373. {
  374. get { return _currentFontColor; }
  375. set
  376. {
  377. SetProperty(ref _currentFontColor, value);
  378. }
  379. }
  380. private bool IsEqualComboData(ComboDataItem oldValue, ComboDataItem newValue)
  381. {
  382. if (newValue == null || IsCanSave == false)
  383. return false;
  384. if (oldValue != null && newValue != null)
  385. {
  386. if (oldValue.Value != newValue.Value)
  387. return true;
  388. }
  389. return false;
  390. }
  391. private bool IsEqualStrComboData(ComboDataItem oldValue, ComboDataItem newValue)
  392. {
  393. if (newValue == null || string.IsNullOrEmpty(newValue.ValueStr) == true || IsCanSave == false)
  394. return false;
  395. if (oldValue != null && newValue != null)
  396. {
  397. if (oldValue.ValueStr != newValue.ValueStr)
  398. return true;
  399. }
  400. return false;
  401. }
  402. #endregion 属性
  403. #region 列表选中赋值
  404. public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights)
  405. {
  406. string strValue = "";
  407. string strContent = "";
  408. if (fontStyle == FontStyles.Normal)
  409. {
  410. if (fontWeights == FontWeights.Normal)
  411. {
  412. strValue = "Regular";
  413. strContent = "Regular";
  414. }
  415. else
  416. {
  417. strValue = "Bold";
  418. strContent = "Bold";
  419. }
  420. }
  421. else
  422. {
  423. if (fontWeights == FontWeights.Normal)
  424. {
  425. strValue = "Italic";
  426. strContent = "Italic";
  427. }
  428. else
  429. {
  430. strValue = "Bold Italic";
  431. strContent = "Bold Italic";
  432. }
  433. }
  434. CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
  435. UpdateFontWeight_Style();
  436. }
  437. protected void GetCurrentFontSize(int size)
  438. {
  439. CurrentFontSize = new ComboDataItem(size);
  440. }
  441. protected void GetCurrentFontFamily(string fontFamily, string uiStr)
  442. {
  443. if (fontFamily == "Arial")
  444. {
  445. fontFamily = "Helvetica";
  446. uiStr = "Helvetica";
  447. }
  448. if(fontFamily == "Times-Roman")
  449. {
  450. uiStr = "Times New Roman";
  451. }
  452. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  453. }
  454. #endregion 列表选中赋值
  455. }
  456. //设置字体大小、字体内容排版、字体颜色、字体样式、字重
  457. public class FontBoardVm : BindableBase
  458. {
  459. #region 变量
  460. public List<ComboDataItem> FontFamilyItems { get; protected set; }
  461. public List<ComboDataItem> FontStyleItems { get; protected set; }
  462. public List<ComboDataItem> FontSizeItems { get; protected set; }
  463. public List<ComboDataItem> PresetFontItems { get; protected set; }
  464. public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
  465. public FontBoardVm(bool isInitdata)
  466. {
  467. if (isInitdata)
  468. InitBaseVariable();
  469. }
  470. #endregion 变量
  471. #region 初始化下拉框或列表默认的数据
  472. protected void InitBaseVariable()
  473. {
  474. InitBase_PresetFontStyles();
  475. InitBase_FontFamilys();
  476. InitBase_FontStyles();
  477. InitBase_FontSize();
  478. }
  479. private void InitBase_FontSize()
  480. {
  481. FontSizeItems = TextFont.GetFontSize();
  482. }
  483. //预设字体样式
  484. private void InitBase_PresetFontStyles()
  485. {
  486. PresetFontItems = new List<ComboDataItem>();
  487. PresetFontList = TextFont.GetCachePresetFontList();
  488. foreach (var item in PresetFontList)
  489. {
  490. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  491. PresetFontItems.Add(itemData);
  492. }
  493. }
  494. //字体
  495. private void InitBase_FontFamilys()
  496. {
  497. FontFamilyItems = TextFont.GetFamily();
  498. }
  499. //字重
  500. private void InitBase_FontStyles()
  501. {
  502. FontStyleItems = TextFont.GetFontStyle();
  503. }
  504. #endregion 初始化下拉框或列表默认的数据
  505. #region 属性
  506. /// <summary>
  507. /// 预设样式
  508. /// </summary>
  509. private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
  510. public ComboDataItem CurrentPresetFont
  511. {
  512. get { return _currentPresetFont; }
  513. set
  514. {
  515. SetProperty(ref _currentPresetFont, value);
  516. switch (value.ValueStr.ToString())
  517. {
  518. case "Custom":
  519. PresetFontSelectedIndex = 0;
  520. break;
  521. case "H1":
  522. PresetFontSelectedIndex = 1;
  523. break;
  524. case "H2":
  525. PresetFontSelectedIndex = 2;
  526. break;
  527. case "H3":
  528. PresetFontSelectedIndex = 3;
  529. break;
  530. case "B1":
  531. PresetFontSelectedIndex = 4;
  532. break;
  533. case "B2":
  534. PresetFontSelectedIndex = 5;
  535. break;
  536. case "B3":
  537. PresetFontSelectedIndex = 6;
  538. break;
  539. default:
  540. PresetFontSelectedIndex = 0;
  541. break;
  542. }
  543. }
  544. }
  545. private int presetFontSelectedIndex;
  546. public int PresetFontSelectedIndex
  547. {
  548. get { return presetFontSelectedIndex; }
  549. set
  550. {
  551. SetProperty(ref presetFontSelectedIndex, value);
  552. }
  553. }
  554. #region 字体样式
  555. //下拉框列表
  556. private ComboDataItem _currentFontFamily = new ComboDataItem("Helvetica", "Helvetica");
  557. public ComboDataItem CurrentFontFamily
  558. {
  559. get { return _currentFontFamily; }
  560. set
  561. {
  562. SetProperty(ref _currentFontFamily, value);
  563. switch (value.Content.ToString())
  564. {
  565. case "Courier New":
  566. FontFamilySelectedIndex = 0;
  567. break;
  568. case "Helvetica":
  569. case "Arial":
  570. FontFamilySelectedIndex = 1;
  571. break;
  572. case "Times New Roman":
  573. FontFamilySelectedIndex = 2;
  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 == "Arial")
  801. {
  802. fontFamily = "Helvetica";
  803. uiStr = "Helvetica";
  804. }
  805. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  806. }
  807. public void GetCurrentPresetFont(string presetFont, string uiStr)
  808. {
  809. CurrentPresetFont = new ComboDataItem(presetFont, uiStr);
  810. }
  811. internal bool GetCurrentPresetFont(FreeTextAnnotArgs annot)
  812. {
  813. bool isExist = false;
  814. //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
  815. foreach (var item in PresetFontList)
  816. {
  817. if (annot.FontSize == item.mFontSize && annot.IsBold == (item.mFontWeight==FontWeights.Bold) && annot.IsItalic == (item.mFontStyle==FontStyles.Italic)
  818. && (annot.FontName == item.mFontFamily.Source || annot.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
  819. )
  820. {
  821. if (item.mTag != "Custom")
  822. {
  823. CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  824. isExist = true;
  825. }
  826. break;
  827. }
  828. }
  829. return isExist;
  830. }
  831. #endregion 列表选中赋值
  832. }
  833. }