FontBoard.cs 31 KB

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