FontBoard.cs 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  449. }
  450. #endregion 列表选中赋值
  451. }
  452. //设置字体大小、字体内容排版、字体颜色、字体样式、字重
  453. public class FontBoardVm : BindableBase
  454. {
  455. #region 变量
  456. public List<ComboDataItem> FontFamilyItems { get; protected set; }
  457. public List<ComboDataItem> FontStyleItems { get; protected set; }
  458. public List<ComboDataItem> FontSizeItems { get; protected set; }
  459. public List<ComboDataItem> PresetFontItems { get; protected set; }
  460. public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
  461. public FontBoardVm(bool isInitdata)
  462. {
  463. if (isInitdata)
  464. InitBaseVariable();
  465. }
  466. #endregion 变量
  467. #region 初始化下拉框或列表默认的数据
  468. protected void InitBaseVariable()
  469. {
  470. InitBase_PresetFontStyles();
  471. InitBase_FontFamilys();
  472. InitBase_FontStyles();
  473. InitBase_FontSize();
  474. }
  475. private void InitBase_FontSize()
  476. {
  477. FontSizeItems = TextFont.GetFontSize();
  478. }
  479. //预设字体样式
  480. private void InitBase_PresetFontStyles()
  481. {
  482. PresetFontItems = new List<ComboDataItem>();
  483. PresetFontList = TextFont.GetCachePresetFontList();
  484. foreach (var item in PresetFontList)
  485. {
  486. ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
  487. PresetFontItems.Add(itemData);
  488. }
  489. }
  490. //字体
  491. private void InitBase_FontFamilys()
  492. {
  493. FontFamilyItems = TextFont.GetFamily();
  494. }
  495. //字重
  496. private void InitBase_FontStyles()
  497. {
  498. FontStyleItems = TextFont.GetFontStyle();
  499. }
  500. #endregion 初始化下拉框或列表默认的数据
  501. #region 属性
  502. /// <summary>
  503. /// 预设样式
  504. /// </summary>
  505. private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
  506. public ComboDataItem CurrentPresetFont
  507. {
  508. get { return _currentPresetFont; }
  509. set
  510. {
  511. SetProperty(ref _currentPresetFont, value);
  512. switch (value.ValueStr.ToString())
  513. {
  514. case "Custom":
  515. PresetFontSelectedIndex = 0;
  516. break;
  517. case "H1":
  518. PresetFontSelectedIndex = 1;
  519. break;
  520. case "H2":
  521. PresetFontSelectedIndex = 2;
  522. break;
  523. case "H3":
  524. PresetFontSelectedIndex = 3;
  525. break;
  526. case "B1":
  527. PresetFontSelectedIndex = 4;
  528. break;
  529. case "B2":
  530. PresetFontSelectedIndex = 5;
  531. break;
  532. case "B3":
  533. PresetFontSelectedIndex = 6;
  534. break;
  535. default:
  536. PresetFontSelectedIndex = 0;
  537. break;
  538. }
  539. }
  540. }
  541. private int presetFontSelectedIndex;
  542. public int PresetFontSelectedIndex
  543. {
  544. get { return presetFontSelectedIndex; }
  545. set
  546. {
  547. SetProperty(ref presetFontSelectedIndex, value);
  548. }
  549. }
  550. #region 字体样式
  551. //下拉框列表
  552. private ComboDataItem _currentFontFamily = new ComboDataItem("Helvetica", "Helvetica");
  553. public ComboDataItem CurrentFontFamily
  554. {
  555. get { return _currentFontFamily; }
  556. set
  557. {
  558. SetProperty(ref _currentFontFamily, value);
  559. switch (value.Content.ToString())
  560. {
  561. case "Courier New":
  562. FontFamilySelectedIndex = 0;
  563. break;
  564. case "Helvetica":
  565. case "Arial":
  566. FontFamilySelectedIndex = 1;
  567. break;
  568. case "Times New Roman":
  569. FontFamilySelectedIndex = 2;
  570. break;
  571. }
  572. }
  573. }
  574. private int fontFamilySelectedIndex;
  575. public int FontFamilySelectedIndex
  576. {
  577. get { return fontFamilySelectedIndex; }
  578. set
  579. {
  580. SetProperty(ref fontFamilySelectedIndex, value);
  581. }
  582. }
  583. #endregion 字体样式
  584. #region 字体大小
  585. private int fontSizeSelectedIndex;
  586. public int FontSizeSelectedIndex
  587. {
  588. get { return fontSizeSelectedIndex; }
  589. set
  590. {
  591. SetProperty(ref fontSizeSelectedIndex, value);
  592. }
  593. }
  594. //下拉框列表:字体大小
  595. private ComboDataItem _currentFontSize = new ComboDataItem(6);
  596. public ComboDataItem CurrentFontSize
  597. {
  598. get { return _currentFontSize; }
  599. set
  600. {
  601. SetProperty(ref _currentFontSize, value);
  602. switch (value.Value)
  603. {
  604. case 8:
  605. FontSizeSelectedIndex = 0;
  606. break;
  607. case 9:
  608. FontSizeSelectedIndex = 1;
  609. break;
  610. case 10:
  611. FontSizeSelectedIndex = 2;
  612. break;
  613. case 11:
  614. FontSizeSelectedIndex = 3;
  615. break;
  616. case 12:
  617. FontSizeSelectedIndex = 4;
  618. break;
  619. case 14:
  620. FontSizeSelectedIndex = 5;
  621. break;
  622. case 16:
  623. FontSizeSelectedIndex = 6;
  624. break;
  625. case 18:
  626. FontSizeSelectedIndex = 7;
  627. break;
  628. case 20:
  629. FontSizeSelectedIndex = 8;
  630. break;
  631. case 22:
  632. FontSizeSelectedIndex = 9;
  633. break;
  634. case 24:
  635. FontSizeSelectedIndex = 10;
  636. break;
  637. case 26:
  638. FontSizeSelectedIndex = 11;
  639. break;
  640. case 28:
  641. FontSizeSelectedIndex = 12;
  642. break;
  643. case 36:
  644. FontSizeSelectedIndex = 13;
  645. break;
  646. case 48:
  647. FontSizeSelectedIndex = 14;
  648. break;
  649. case 72:
  650. FontSizeSelectedIndex = 15;
  651. break;
  652. default:
  653. //FontSizeSelectedIndex = 0;
  654. //FontSizeSelectedIndex = -1;
  655. break;
  656. }
  657. }
  658. }
  659. #endregion 字体大小
  660. //FontStyle & FontWeight
  661. private FontStyle _fontStyleItem;
  662. public FontStyle FontStyleItem
  663. {
  664. get { return _fontStyleItem; }
  665. set { SetProperty(ref _fontStyleItem, value); }
  666. }
  667. private FontWeight _fontWeight;
  668. public FontWeight FontWeightItem
  669. {
  670. get { return _fontWeight; }
  671. set { SetProperty(ref _fontWeight, value); }
  672. }
  673. private int fontStyleSelectedIndex;
  674. public int FontStyleSelectedIndex
  675. {
  676. get { return fontStyleSelectedIndex; }
  677. set
  678. {
  679. SetProperty(ref fontStyleSelectedIndex, value);
  680. }
  681. }
  682. private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
  683. public ComboDataItem CurrrentFontWeightStyle
  684. {
  685. get { return _currrentFontWeightStyle; }
  686. set
  687. {
  688. SetProperty(ref _currrentFontWeightStyle, value);
  689. switch (value.Content.ToString())
  690. {
  691. case "Regular":
  692. FontStyleSelectedIndex = 0;
  693. break;
  694. case "Bold":
  695. FontStyleSelectedIndex = 1;
  696. break;
  697. case "Italic":
  698. FontStyleSelectedIndex = 2;
  699. break;
  700. case "Bold Italic":
  701. FontStyleSelectedIndex = 3;
  702. break;
  703. }
  704. }
  705. }
  706. public void UpdateFontWeight_Style()
  707. {
  708. switch (CurrrentFontWeightStyle.ValueStr)
  709. {
  710. case "Regular":
  711. FontStyleItem = FontStyles.Normal;
  712. FontWeightItem = FontWeights.Normal;
  713. break;
  714. case "Bold":
  715. FontStyleItem = FontStyles.Normal;
  716. FontWeightItem = FontWeights.Bold;
  717. break;
  718. case "Italic":
  719. FontStyleItem = FontStyles.Italic;
  720. FontWeightItem = FontWeights.Normal;
  721. break;
  722. case "Bold Italic":
  723. FontStyleItem = FontStyles.Italic;
  724. FontWeightItem = FontWeights.Bold;
  725. break;
  726. }
  727. }
  728. //文字内容对齐
  729. private string _strtextAlign;
  730. public string StrTextAlign
  731. {
  732. get { return _strtextAlign; }
  733. set { SetProperty(ref _strtextAlign, value); }
  734. }
  735. //颜色
  736. private Brush _fontColor = new SolidColorBrush(Colors.Black);
  737. public Brush FontColor
  738. {
  739. get { return _fontColor; }
  740. set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; }
  741. }
  742. private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
  743. public Brush CurrentFontColor
  744. {
  745. get { return _currentFontColor; }
  746. set => SetProperty(ref _currentFontColor, value);
  747. }
  748. //外部UI引用,判断是否选中左对齐、居中对齐、右对齐,或都不选中
  749. public string strAglinState { get; private set; }
  750. //VM赋值
  751. public void SetStrAglinState(string str)
  752. {
  753. strAglinState = str;
  754. }
  755. #endregion 属性
  756. #region 列表选中赋值
  757. public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights)
  758. {
  759. string strValue = "";
  760. string strContent = "";
  761. if (fontStyle == FontStyles.Normal)
  762. {
  763. if (fontWeights == FontWeights.Normal)
  764. {
  765. strValue = "Regular";
  766. strContent = "Regular";
  767. }
  768. else
  769. {
  770. strValue = "Bold";
  771. strContent = "Bold";
  772. }
  773. }
  774. else
  775. {
  776. if (fontWeights == FontWeights.Normal)
  777. {
  778. strValue = "Italic";
  779. strContent = "Italic";
  780. }
  781. else
  782. {
  783. strValue = "Bold Italic";
  784. strContent = "Bold Italic";
  785. }
  786. }
  787. CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
  788. UpdateFontWeight_Style();
  789. }
  790. public void GetCurrentFontSize(int size)
  791. {
  792. CurrentFontSize = new ComboDataItem(size);
  793. }
  794. public void GetCurrentFontFamily(string fontFamily, string uiStr)
  795. {
  796. if (fontFamily == "Arial")
  797. {
  798. fontFamily = "Helvetica";
  799. uiStr = "Helvetica";
  800. }
  801. CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
  802. }
  803. public void GetCurrentPresetFont(string presetFont, string uiStr)
  804. {
  805. CurrentPresetFont = new ComboDataItem(presetFont, uiStr);
  806. }
  807. internal bool GetCurrentPresetFont(FreeTextAnnotArgs annot)
  808. {
  809. bool isExist = false;
  810. //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
  811. foreach (var item in PresetFontList)
  812. {
  813. if (annot.FontSize == item.mFontSize && annot.IsBold == (item.mFontWeight==FontWeights.Bold) && annot.IsItalic == (item.mFontStyle==FontStyles.Italic)
  814. && (annot.FontName == item.mFontFamily.Source || annot.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
  815. )
  816. {
  817. if (item.mTag != "Custom")
  818. {
  819. CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  820. isExist = true;
  821. }
  822. break;
  823. }
  824. }
  825. return isExist;
  826. }
  827. #endregion 列表选中赋值
  828. }
  829. }