FontBoard.cs 29 KB

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