FontBoard.cs 29 KB

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