FontBoard.cs 29 KB

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