TextEditPropertyViewModel.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using ComPDFKitViewer.PdfViewer;
  4. using Microsoft.Win32;
  5. using PDF_Master.CustomControl.CompositeControl;
  6. using PDF_Master.Helper;
  7. using PDF_Master.Model;
  8. using PDF_Master.Model.AnnotPanel;
  9. using PDF_Master.Model.PropertyPanel.AnnotPanel;
  10. using PDF_Master.ViewModels.Tools.AnnotManager;
  11. using PDFSettings;
  12. using Prism.Commands;
  13. using Prism.Mvvm;
  14. using Prism.Regions;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
  25. {
  26. public class TextEditPropertyViewModel : PDFEditVM, INavigationAware
  27. {
  28. #region 属性
  29. public event EventHandler ClearCheckedAglin;
  30. public TextEditPropertyViewModel()
  31. {
  32. InitVariable();
  33. InitCommand();
  34. }
  35. private void InitVariable()
  36. {
  37. InitBaseVariable();
  38. }
  39. private bool isSelectedEmpty;
  40. public bool IsSelectedEmpty
  41. {
  42. get { return isSelectedEmpty; }
  43. set { SetProperty(ref isSelectedEmpty, value); }
  44. }
  45. private string title;
  46. public string Title
  47. {
  48. get { return title; }
  49. set
  50. {
  51. SetProperty(ref title, value);
  52. }
  53. }
  54. private FontBoardVm _fontVm = new FontBoardVm(true);
  55. public FontBoardVm FontVm
  56. {
  57. get { return _fontVm; }
  58. set { SetProperty(ref _fontVm, value); }
  59. }
  60. private ComPDFKit.PDFPage.Edit.TextAlignType _textAlign;
  61. public ComPDFKit.PDFPage.Edit.TextAlignType TextAlign
  62. {
  63. get { return _textAlign; }
  64. set { _textAlign = value; }
  65. }
  66. #endregion
  67. #region Command
  68. public DelegateCommand AddTextCommand { get; set; }
  69. public DelegateCommand AddImgCommand { get; set; }
  70. public DelegateCommand<object> SelectedColorCommand { get; set; }
  71. public DelegateCommand<object> SelectedFontStyleCommand { get; set; }
  72. public DelegateCommand<object> FontSizeChangedCommand { get; set; }
  73. public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
  74. //进入属性面板编辑
  75. public DelegateCommand EditTextModeCommand { get; set; }
  76. public DelegateCommand FontFamilyChangedCommand { get; set; }
  77. public DelegateCommand CustomFontStyleCommand { get; set; }
  78. public DelegateCommand FontStyleWeightChangedCommand { get; set; }
  79. public DelegateCommand SelectedPresetFontCommand { get; set; }
  80. //重定义
  81. public DelegateCommand ReDefineFontStyleCommand { get; set; }
  82. public DelegateCommand RestoreDefaultStyleCommand { get; set; }
  83. public DelegateCommand<object> LayoutAlignCheckedCommand { get; set; }
  84. #endregion
  85. #region 初始化
  86. private void InitCommand()
  87. {
  88. //预设文本样式
  89. SelectedPresetFontCommand = new DelegateCommand(SelectedPresetFont);
  90. //字体
  91. FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged);
  92. //文本字重、字体
  93. FontStyleWeightChangedCommand = new DelegateCommand(FontStyleWeightChanged);
  94. //添加文本
  95. AddTextCommand = new DelegateCommand(AddText);
  96. //添加图片
  97. AddImgCommand = new DelegateCommand(AddImg);
  98. //选择颜色
  99. SelectedColorCommand = new DelegateCommand<object>(SelectedColor);
  100. //选择字体样式
  101. SelectedFontStyleCommand = new DelegateCommand<object>(SelectedFontStyle);
  102. //大小
  103. FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged);
  104. //内容对齐
  105. TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
  106. //编辑模式
  107. EditTextModeCommand = new DelegateCommand(EditTextMode);
  108. //自定义
  109. CustomFontStyleCommand = new DelegateCommand(CustomFontStyle);
  110. //重新定义
  111. ReDefineFontStyleCommand = new DelegateCommand(ReDefineFontStyle);
  112. //恢复默认
  113. RestoreDefaultStyleCommand = new DelegateCommand(RestoreDefaultStyle);
  114. //文本对齐
  115. LayoutAlignCheckedCommand = new DelegateCommand<object>(LayoutAlignChecked);
  116. }
  117. #endregion
  118. #region 文本处理逻辑
  119. private void AddText()
  120. {
  121. //设置对应创建模式
  122. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
  123. }
  124. private void AddImg()
  125. {
  126. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
  127. }
  128. private void EditTextMode()
  129. {
  130. }
  131. /// <summary>
  132. /// 从预设样式设置文本
  133. /// </summary>
  134. private void SelectedPresetFont()
  135. {
  136. if (CurrentPresetFont != null)
  137. {
  138. var itemComboxItem = CurrentPresetFont;
  139. var item = PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
  140. if (item != null)
  141. {
  142. if (item.mTag != "Custom")
  143. {
  144. GetCurrentFontSize(item.mFontSize);
  145. if (item.mFontFamily != null)
  146. {
  147. GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  148. }
  149. GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
  150. CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
  151. CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
  152. FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
  153. FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
  154. }
  155. }
  156. }
  157. }
  158. /// <summary>
  159. /// 自定义文字样式
  160. /// </summary>
  161. private void CustomFontStyle()
  162. {
  163. if (CurrentPresetFont != null)
  164. {
  165. ContextMenu menu;
  166. if (CurrentPresetFont.ValueStr == "Custom")
  167. {
  168. menu = SelectAnnotContextMenu(false);
  169. }
  170. else
  171. {
  172. menu = SelectAnnotContextMenu(false);
  173. var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
  174. if (currentItem.mTag != "Custom")
  175. {
  176. if (FontWeightItem != currentItem.mFontWeight ||
  177. FontStyleItem != currentItem.mFontStyle ||
  178. CurrentFontSize.Value != currentItem.mFontSize ||
  179. CurrentFontFamily.ValueStr != currentItem.mFontFamily.Source)
  180. {
  181. menu = SelectAnnotContextMenu(true);
  182. }
  183. }
  184. }
  185. if (menu != null)
  186. {
  187. menu.IsOpen = true;
  188. }
  189. }
  190. }
  191. //设置字体样式
  192. private void FontFamilyChanged()
  193. {
  194. if (CurrentPresetFont != null)
  195. {
  196. var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
  197. if (currentItem.mTag != "Custom")
  198. {
  199. foreach (var item in PresetFontList)
  200. {
  201. if (item.mTag == currentItem.mTag)
  202. {
  203. if (CurrentFontFamily.ValueStr != item.mFontFamily.Source)
  204. {
  205. string txt = string.Format($" * {currentItem.mTagContent}");
  206. if (Title == txt)
  207. {
  208. Title = "";
  209. }
  210. Title = txt;
  211. break;
  212. }
  213. else
  214. {
  215. if (FontWeightItem == item.mFontWeight && FontStyleItem == item.mFontStyle && CurrentFontSize.Value == item.mFontSize && CurrentFontFamily.ValueStr == item.mFontFamily.Source)
  216. {
  217. string txt = currentItem.mTagContent;
  218. if (Title == txt)
  219. {
  220. Title = "";
  221. }
  222. Title = txt;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 设置文本字重、样式
  232. /// </summary>
  233. private void FontStyleWeightChanged()
  234. {
  235. if (CurrrentFontWeightStyle != null)
  236. {
  237. UpdateFontWeight_Style();
  238. FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
  239. FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
  240. if (CurrentPresetFont != null)
  241. {
  242. var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
  243. if (currentItem.mTag != "Custom")
  244. {
  245. foreach (var item in PresetFontList)
  246. {
  247. if (item.mTag == currentItem.mTag)
  248. {
  249. if (FontWeightItem != item.mFontWeight || FontStyleItem != item.mFontStyle)
  250. {
  251. string txt = string.Format($" * {currentItem.mTagContent}");
  252. if (Title == txt)
  253. {
  254. Title = "";
  255. }
  256. Title = txt;
  257. break;
  258. }
  259. else
  260. {
  261. if (FontWeightItem == item.mFontWeight && FontStyleItem == item.mFontStyle && CurrentFontSize.Value == item.mFontSize && CurrentFontFamily.ValueStr == item.mFontFamily.Source)
  262. {
  263. string txt = currentItem.mTagContent;
  264. if (Title == txt)
  265. {
  266. Title = "";
  267. }
  268. Title = txt;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. /// <summary>
  278. /// 用所选部分重新定义
  279. /// </summary>
  280. private void ReDefineFontStyle()
  281. {
  282. var item = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
  283. if (item == null) return;
  284. item.mFontFamily = new FontFamily(CurrentFontFamily.ValueStr);
  285. if (CurrrentFontWeightStyle.ValueStr == "Bold")
  286. {
  287. item.mFontStyle = FontStyles.Normal;
  288. item.mFontWeight = FontWeights.Bold;
  289. }
  290. else if (CurrrentFontWeightStyle.ValueStr == "Regular")
  291. {
  292. item.mFontStyle = FontStyles.Normal;
  293. item.mFontWeight = FontWeights.Normal;
  294. }
  295. else if (CurrrentFontWeightStyle.ValueStr == "Italic")
  296. {
  297. item.mFontStyle = FontStyles.Italic;
  298. item.mFontWeight = FontWeights.Normal;
  299. }
  300. else
  301. {
  302. item.mFontStyle = FontStyles.Italic;
  303. item.mFontWeight = FontWeights.Bold;
  304. }
  305. item.mFontSize = (int)CurrentFontSize.Value;
  306. CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  307. SelectedPresetFont();
  308. }
  309. //重置定义
  310. private void RestoreDefaultStyle()
  311. {
  312. var defaultlists = TextFont.GetPresetFontStyle();
  313. if (CurrentPresetFont.ValueStr != "Custom")
  314. {
  315. var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag ==CurrentPresetFont.ValueStr);
  316. if (defaulItem != null)
  317. {
  318. var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
  319. if (currentItem != null)
  320. {
  321. currentItem.mTagContent = defaulItem.mTagContent;
  322. currentItem.mFontStyle = defaulItem.mFontStyle;
  323. currentItem.mFontWeight = defaulItem.mFontWeight;
  324. currentItem.mFontFamily = defaulItem.mFontFamily;
  325. currentItem.mFontSize = defaulItem.mFontSize;
  326. GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
  327. GetCurrentFontSize(currentItem.mFontSize);
  328. GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
  329. CurrentPresetFont = new ComboDataItem(defaulItem.mTag, defaulItem.mTagContent);
  330. SelectedPresetFont();
  331. }
  332. }
  333. }
  334. }
  335. //设置多选对齐方式
  336. private void LayoutAlignChecked(object obj)
  337. {
  338. if (obj != null)
  339. {
  340. if (obj != null)
  341. {
  342. switch ((string)obj)
  343. {
  344. case "AlignLeft":
  345. PDFViewer.SetPDFEditAligment(AlignModes.AlignLeft);
  346. break;
  347. case "AlignHorizonCenter":
  348. PDFViewer.SetPDFEditAligment(AlignModes.AlignHorizonCenter);
  349. break;
  350. case "AlignRight":
  351. PDFViewer.SetPDFEditAligment(AlignModes.AlignRight);
  352. break;
  353. case "DistributeHorizontal":
  354. PDFViewer.SetPDFEditAligment(AlignModes.DistributeHorizontal);
  355. break;
  356. case "AlignTop":
  357. PDFViewer.SetPDFEditAligment(AlignModes.AlignTop);
  358. break;
  359. case "AlignVerticalCenter":
  360. PDFViewer.SetPDFEditAligment(AlignModes.AlignVerticalCenter);
  361. break;
  362. case "AlignBottom":
  363. PDFViewer.SetPDFEditAligment(AlignModes.AlignBottom);
  364. break;
  365. case "DistributeVertical":
  366. PDFViewer.SetPDFEditAligment(AlignModes.DistributeVertical);
  367. break;
  368. }
  369. }
  370. }
  371. }
  372. //设置文本框内对齐方式
  373. private void TextAlignChecked(object obj)
  374. {
  375. if ((string)obj != null && TextEditEvent != null)
  376. {
  377. switch ((string)obj)
  378. {
  379. case "AlignLeft":
  380. GetAnnotAlign(TextAlignment.Left);
  381. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignLeft;
  382. break;
  383. case "AlignCenter":
  384. GetAnnotAlign(TextAlignment.Center);
  385. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignMiddle;
  386. break;
  387. case "AlignRight":
  388. GetAnnotAlign(TextAlignment.Right);
  389. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignRight;
  390. break;
  391. case "Align":
  392. GetAnnotAlign(TextAlignment.Justify);
  393. TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignNone;
  394. break;
  395. }
  396. TextAlign = TextEditEvent.TextAlign;
  397. TextEditEvent.UpdatePDFEditByEventArgs();
  398. }
  399. }
  400. //设置文本内容对齐属性面板显示
  401. private void GetAnnotAlign(TextAlignment align)
  402. {
  403. switch (align)
  404. {
  405. case TextAlignment.Left:
  406. StrTextAlign = "Left";
  407. break;
  408. case TextAlignment.Center:
  409. StrTextAlign = "Center";
  410. break;
  411. case TextAlignment.Right:
  412. StrTextAlign = "Right";
  413. break;
  414. case TextAlignment.Justify:
  415. StrTextAlign = "Justify";
  416. break;
  417. default:
  418. StrTextAlign = "None";
  419. break;
  420. }
  421. }
  422. //设置文本颜色
  423. private void SelectedColor(object obj)
  424. {
  425. if (obj != null)
  426. {
  427. var colorValue = (Color)obj;
  428. if (colorValue != null)
  429. {
  430. SelectColor = new SolidColorBrush(colorValue);
  431. }
  432. }
  433. }
  434. //设置文本样式
  435. private void SelectedFontStyle(object obj)
  436. {
  437. if (obj != null && (PresetFontItem)obj != null)
  438. {
  439. var item = (PresetFontItem)obj;
  440. }
  441. }
  442. //设置字体大小
  443. private void FontSizeChanged(object obj)
  444. {
  445. if (CurrentFontSize != null)
  446. {
  447. CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
  448. }
  449. if (CurrentPresetFont != null)
  450. {
  451. var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
  452. if (currentItem.mTag != "Custom")
  453. {
  454. foreach (var item in PresetFontList)
  455. {
  456. if (item.mTag == currentItem.mTag)
  457. {
  458. if (CurrentFontSize.Value != item.mFontSize)
  459. {
  460. string txt = string.Format($" * {currentItem.mTagContent}");
  461. if (Title == txt)
  462. {
  463. Title = "";
  464. }
  465. Title = txt;
  466. break;
  467. }
  468. else
  469. {
  470. if (FontWeightItem == item.mFontWeight && FontStyleItem == item.mFontStyle && CurrentFontSize.Value == item.mFontSize && CurrentFontFamily.ValueStr == item.mFontFamily.Source)
  471. {
  472. string txt = currentItem.mTagContent;
  473. if (Title == txt)
  474. {
  475. Title = "";
  476. }
  477. Title = txt;
  478. }
  479. }
  480. }
  481. }
  482. }
  483. }
  484. }
  485. #endregion
  486. #region 右键菜单
  487. //点击空白处时
  488. private ContextMenu EmptyStateMenu(object sender)
  489. {
  490. var popMenu = App.Current.FindResource("NoneMenu") as ContextMenu;
  491. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  492. //粘贴
  493. customMenu.SetMenuBinding(0, ApplicationCommands.Paste);
  494. //添加文本
  495. customMenu.SetMenuBinding(1, AddTextCommand);
  496. //添加图像
  497. customMenu.SetMenuBinding(2, AddImgCommand);
  498. return popMenu;
  499. }
  500. #endregion
  501. #region 编辑PDF内容触发的事件
  502. /// <summary>
  503. /// 右键菜单的事件
  504. /// </summary>
  505. private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
  506. {
  507. if (e == null)
  508. return;
  509. switch (e.CommandType)
  510. {
  511. case CommandType.Context:
  512. if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
  513. {
  514. e.PopupMenu = EmptyStateMenu(sender);
  515. }
  516. break;
  517. default:
  518. e.DoCommand();
  519. break;
  520. }
  521. if (e.PopupMenu != null)
  522. {
  523. e.Handle = true;
  524. }
  525. }
  526. /// <summary>
  527. /// 更多菜单
  528. /// </summary>
  529. /// <param name="isEnable"></param>
  530. /// <returns></returns>
  531. private ContextMenu SelectAnnotContextMenu(bool isEnable)
  532. {
  533. var popMenu = App.Current.FindResource("CustomFontStyleFlyoutMenu") as ContextMenu;
  534. if (popMenu != null && popMenu.Items.Count == 2)
  535. {
  536. //用所选部分重新定义
  537. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  538. menuItem.IsEnabled = isEnable;
  539. menuItem.Command = ReDefineFontStyleCommand;
  540. //恢复默认预设样式
  541. menuItem = popMenu.Items[1] as MenuItem;
  542. menuItem.IsEnabled = isEnable;
  543. menuItem.Command = RestoreDefaultStyleCommand;
  544. }
  545. return popMenu;
  546. }
  547. #endregion
  548. protected List<PDFEditEvent> TextEditEventList;
  549. public void OnNavigatedTo(NavigationContext navigationContext)
  550. {
  551. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  552. navigationContext.Parameters.TryGetValue<List<PDFEditEvent>>(ParameterNames.AnnotEvent, out TextEditEventList);
  553. if (PDFViewer != null)
  554. {
  555. if (TextEditEventList != null && TextEditEventList.Count > 0)
  556. {
  557. TextEditEvent = TextEditEventList[0];
  558. GetPDFEdit();
  559. if (TextEditEventList.Count > 1)
  560. IsSelectedEmpty = true;
  561. else
  562. IsSelectedEmpty = false;
  563. if (TextEditEventList.Count == 2)
  564. {
  565. IsLayoutAlign = true;
  566. IsLayoutAvgAlign = false;
  567. }
  568. else if (TextEditEventList.Count > 2)
  569. {
  570. IsLayoutAlign = true;
  571. IsLayoutAvgAlign = true;
  572. }
  573. else
  574. {
  575. IsLayoutAlign = false;
  576. IsLayoutAvgAlign = false;
  577. }
  578. }
  579. PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
  580. PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
  581. ChangedValue -= FontMode_ChangedValue;
  582. ChangedValue += FontMode_ChangedValue;
  583. IsCanSave = true;
  584. }
  585. }
  586. //文本内容改变触发
  587. private void FontMode_ChangedValue(object sender, FontSetModeType e)
  588. {
  589. if (sender != null)
  590. {
  591. switch (e)
  592. {
  593. case FontSetModeType.PresetFontStyes:
  594. if (PresetFontList != null && sender is string == true)
  595. {
  596. var item = PresetFontList.FirstOrDefault(temp => temp.mTag == (string)sender);
  597. if (item != null && TextEditEvent != null)
  598. {
  599. if (TextEditEventList.Count == 1 && IsSelectedEmpty == false)
  600. {
  601. TextEditEvent.FontName = item.mFontFamily != null ? item.mFontFamily.Source : string.Empty;
  602. TextEditEvent.FontSize = item.mFontSize;
  603. TextEditEvent.IsBold = item.mFontWeight == FontWeights.Bold;
  604. TextEditEvent.IsItalic = item.mFontStyle == FontStyles.Italic;
  605. TextEditEvent.UpdatePDFEditByEventArgs();
  606. }
  607. else
  608. {
  609. foreach (var itemlist in TextEditEventList)
  610. {
  611. itemlist.FontName = item.mFontFamily != null ? item.mFontFamily.Source : string.Empty;
  612. itemlist.FontSize = item.mFontSize;
  613. itemlist.IsBold = item.mFontWeight == FontWeights.Bold;
  614. itemlist.IsItalic = item.mFontStyle == FontStyles.Italic;
  615. itemlist.UpdatePDFEditByEventArgs();
  616. }
  617. }
  618. }
  619. }
  620. break;
  621. case FontSetModeType.FontFamilys:
  622. if (sender is string == true)
  623. {
  624. TextEditEvent.FontName = (string)sender;
  625. TextEditEvent.UpdatePDFEditByEventArgs();
  626. }
  627. break;
  628. case FontSetModeType.FontSizes:
  629. if (sender is double == true && (double)sender > 0 && TextEditEvent.FontSize > 0)
  630. {
  631. TextEditEvent.FontSize = (double)sender;
  632. TextEditEvent.UpdatePDFEditByEventArgs();
  633. }
  634. break;
  635. case FontSetModeType.FontWeight_Style:
  636. UpdateFontWeight_Style();
  637. TextEditEvent.IsBold = FontWeightItem == FontWeights.Bold;
  638. TextEditEvent.IsItalic = FontStyleItem == FontStyles.Italic;
  639. TextEditEvent.UpdatePDFEditByEventArgs();
  640. break;
  641. case FontSetModeType.FontColor:
  642. if (sender is Color == true)
  643. {
  644. var setColor = (Color)sender;
  645. var eventColor = TextEditEvent.FontColor;
  646. bool isok = eventColor.A != setColor.A || eventColor.B != setColor.B ||
  647. eventColor.G != setColor.G || eventColor.R != setColor.R;
  648. if (isok)
  649. {
  650. TextEditEvent.FontColor = setColor;
  651. TextEditEvent.UpdatePDFEditByEventArgs();
  652. }
  653. }
  654. break;
  655. case FontSetModeType.TextAlignment:
  656. break;
  657. }
  658. }
  659. }
  660. //获取文本参数
  661. private void GetPDFEdit()
  662. {
  663. SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
  664. CurrentFontSize =new ComboDataItem(TextEditEvent.FontSize);
  665. CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
  666. FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
  667. FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
  668. GetFontWeights_Style(FontStyleItem, FontWeightItem);
  669. //判断样式列表中是否存在对应样式
  670. bool isExist = false;
  671. foreach (var item in PresetFontList)
  672. {
  673. if (TextEditEvent.FontSize == item.mFontSize && TextEditEvent.IsBold == (item.mFontWeight == FontWeights.Bold) && TextEditEvent.IsItalic == (item.mFontStyle == FontStyles.Italic)
  674. && (TextEditEvent.FontName == item.mFontFamily.Source || TextEditEvent.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
  675. )
  676. {
  677. if (item.mTag != "Custom")
  678. {
  679. CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  680. isExist = true;
  681. }
  682. break;
  683. }
  684. }
  685. if (isExist == false)
  686. {
  687. FontVm.CurrentPresetFont = new ComboDataItem("Custom", "Custom");
  688. CurrentPresetFont = new ComboDataItem("Custom", "Custom");
  689. GetCurrentFontSize((int)TextEditEvent.FontSize);
  690. if (TextEditEvent.FontName == ""|| TextEditEvent.FontName == null)
  691. {
  692. GetCurrentFontFamily("Helvetica", "Helvetica");
  693. }
  694. else
  695. {
  696. GetCurrentFontFamily(TextEditEvent.FontName, TextEditEvent.FontName);
  697. }
  698. GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
  699. }
  700. else
  701. {
  702. if (CurrentPresetFont != null)
  703. {
  704. var itemComboxItem = CurrentPresetFont;
  705. var item = PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
  706. if (item != null)
  707. {
  708. if (item.mTag != "Custom")
  709. {
  710. GetCurrentFontSize(item.mFontSize);
  711. if (item.mFontFamily != null)
  712. {
  713. GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  714. }
  715. GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
  716. }
  717. }
  718. }
  719. }
  720. //初始化传入的对齐方式
  721. switch (TextEditEvent.TextAlign.ToString())
  722. {
  723. case "AlignLeft":
  724. GetAnnotAlign(TextAlignment.Left);
  725. break;
  726. case "AlignCenter":
  727. GetAnnotAlign(TextAlignment.Center);
  728. break;
  729. case "AlignRight":
  730. GetAnnotAlign(TextAlignment.Right);
  731. break;
  732. case "Align":
  733. GetAnnotAlign(TextAlignment.Justify);
  734. break;
  735. }
  736. TextAlign = TextEditEvent.TextAlign;
  737. TextEditEvent.UpdatePDFEditByEventArgs();
  738. }
  739. public bool IsNavigationTarget(NavigationContext navigationContext) { return true; }
  740. public void OnNavigatedFrom(NavigationContext navigationContext)
  741. {
  742. IsCanSave = false;
  743. TextEditEvent = null;
  744. IsSelectedEmpty = false;
  745. ClearCheckedAglin?.Invoke(null, null);
  746. PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
  747. ChangedValue -= FontMode_ChangedValue;
  748. }
  749. }
  750. }