FontBoard.cs 29 KB

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