ScreenAnnotationDialogViewModel.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using Dropbox.Api.Users;
  4. using DryIoc;
  5. using ImTools;
  6. using Microsoft.Office.Interop.Word;
  7. using PDF_Office.CustomControl;
  8. using PDF_Office.CustomControl.CompositeControl;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Model;
  11. using PDF_Office.Model.BOTA;
  12. using Prism.Commands;
  13. using Prism.Common;
  14. using Prism.Mvvm;
  15. using Prism.Services.Dialogs;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Collections.ObjectModel;
  19. using System.Drawing;
  20. using System.Linq;
  21. using System.Runtime.CompilerServices;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. using System.Windows;
  25. using System.Windows.Annotations;
  26. using System.Windows.Controls;
  27. using System.Windows.Documents;
  28. using System.Windows.Forms;
  29. using System.Windows.Media;
  30. using DialogResult = Prism.Services.Dialogs.DialogResult;
  31. using ListBox = System.Windows.Controls.ListBox;
  32. namespace PDF_Office.ViewModels.Dialog.BOTA
  33. {
  34. internal class ScreenAnnotationDialogViewModel : BindableBase, IDialogAware
  35. {
  36. public string Title => "";
  37. public event Action<IDialogResult> RequestClose;
  38. #region 类型的显示隐藏
  39. /// <summary>
  40. /// 高亮字体
  41. /// </summary>
  42. private Visibility highlightVisibility = Visibility.Collapsed;
  43. public Visibility HighlightVisibility
  44. {
  45. get { return highlightVisibility; }
  46. set
  47. {
  48. SetProperty(ref highlightVisibility, value);
  49. }
  50. }
  51. /// <summary>
  52. /// 手绘
  53. /// </summary>
  54. private Visibility freeHandVisibility = Visibility.Collapsed;
  55. public Visibility FreeHandVisibility
  56. {
  57. get { return freeHandVisibility; }
  58. set
  59. {
  60. SetProperty(ref freeHandVisibility, value);
  61. }
  62. }
  63. /// <summary>
  64. /// 便签
  65. /// </summary>
  66. private Visibility annotStickyVisibility = Visibility.Collapsed;
  67. public Visibility AnnotStickyVisibility
  68. {
  69. get { return annotStickyVisibility; }
  70. set
  71. {
  72. SetProperty(ref annotStickyVisibility, value);
  73. }
  74. }
  75. /// <summary>
  76. /// 图章
  77. /// </summary>
  78. private Visibility annotStampVisibility = Visibility.Collapsed;
  79. public Visibility AnnotStampVisibility
  80. {
  81. get { return annotStampVisibility; }
  82. set
  83. {
  84. SetProperty(ref annotStampVisibility, value);
  85. }
  86. }
  87. /// <summary>
  88. /// 线
  89. /// </summary>
  90. private Visibility sharpLineVisibility = Visibility.Collapsed;
  91. public Visibility SharpLineVisibility
  92. {
  93. get { return sharpLineVisibility; }
  94. set
  95. {
  96. SetProperty(ref sharpLineVisibility, value);
  97. }
  98. }
  99. /// <summary>
  100. /// 箭头
  101. /// </summary>
  102. private Visibility sharpArrowVisibility = Visibility.Collapsed;
  103. public Visibility SharpArrowVisibility
  104. {
  105. get { return sharpArrowVisibility; }
  106. set
  107. {
  108. SetProperty(ref sharpArrowVisibility, value);
  109. }
  110. }
  111. /// <summary>
  112. /// 圆
  113. /// </summary>
  114. private Visibility annotCircleVisibility = Visibility.Collapsed;
  115. public Visibility AnnotCircleVisibility
  116. {
  117. get { return annotCircleVisibility; }
  118. set
  119. {
  120. SetProperty(ref annotCircleVisibility, value);
  121. }
  122. }
  123. /// <summary>
  124. /// 链接
  125. /// </summary>
  126. private Visibility annotLinkVisible;
  127. public Visibility AnnotLinkVisible
  128. {
  129. get { return annotLinkVisible; }
  130. set
  131. {
  132. SetProperty(ref annotLinkVisible, value);
  133. }
  134. }
  135. /// <summary>
  136. /// 矩形
  137. /// </summary>
  138. private Visibility annotSquareVisibility = Visibility.Collapsed;
  139. public Visibility AnnotSquareVisibility
  140. {
  141. get { return annotSquareVisibility; }
  142. set
  143. {
  144. SetProperty(ref annotSquareVisibility, value);
  145. }
  146. }
  147. /// <summary>
  148. /// 文本注释
  149. /// </summary>
  150. private Visibility annotFreeTextVisibility = Visibility.Collapsed;
  151. public Visibility AnnotFreeTextVisibility
  152. {
  153. get { return annotFreeTextVisibility; }
  154. set
  155. {
  156. SetProperty(ref annotFreeTextVisibility, value);
  157. }
  158. }
  159. /// <summary>
  160. /// 删除线
  161. /// </summary>
  162. private Visibility annotStrikeoutVisibility = Visibility.Collapsed;
  163. public Visibility AnnotStrikeoutVisibility
  164. {
  165. get { return annotStrikeoutVisibility; }
  166. set
  167. {
  168. SetProperty(ref annotStrikeoutVisibility, value);
  169. }
  170. }
  171. /// <summary>
  172. /// 下划线
  173. /// </summary>
  174. private Visibility underLineVisibility = Visibility.Collapsed;
  175. public Visibility UnderLineVisibility
  176. {
  177. get { return underLineVisibility; }
  178. set
  179. {
  180. SetProperty(ref underLineVisibility, value);
  181. }
  182. }
  183. #endregion 类型的显示隐藏
  184. public DelegateCommand CancelCommand { get; set; }
  185. public DelegateCommand<Object> OkCommnad { get; set; }
  186. public DelegateCommand<Object> CleanCommand { get; set; }
  187. public DelegateCommand<object> LoadedCommand { get; set; }
  188. public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems { get; set; }
  189. private ObservableCollection<ColorItem> annotationColors = new ObservableCollection<ColorItem>();
  190. public ObservableCollection<ColorItem> AnnotationColors
  191. {
  192. get { return annotationColors; }
  193. set
  194. {
  195. SetProperty(ref annotationColors, value);
  196. }
  197. }
  198. private ObservableCollection<AuthorItem> annotationAuthor = new ObservableCollection<AuthorItem>();
  199. public ObservableCollection<AuthorItem> AnnotationAuthor
  200. {
  201. get { return annotationAuthor; }
  202. set
  203. {
  204. SetProperty(ref annotationAuthor, value);
  205. }
  206. }
  207. private CustomIconToggleBtn btnHighlight = null;
  208. private CustomIconToggleBtn btnFreeHand = null;
  209. private CustomIconToggleBtn btnAnnotSticky = null;
  210. private CustomIconToggleBtn btnAnnotStamp = null;
  211. private CustomIconToggleBtn btnSharpLine = null;
  212. private CustomIconToggleBtn btnSharpArrow = null;
  213. private CustomIconToggleBtn btnAnnotCircle = null;
  214. private CustomIconToggleBtn btnAnnotSquare = null;
  215. private CustomIconToggleBtn btnAnnotFreeText = null;
  216. private CustomIconToggleBtn btnAnnotStrikeout = null;
  217. private CustomIconToggleBtn btnUnderLine = null;
  218. private CustomIconToggleBtn btnAnnotLink = null;
  219. private ListBox _ListColor = null;
  220. private ListBox _ListAuthor = null;
  221. private List<CustomIconToggleBtn> iconToggleBtns = new List<CustomIconToggleBtn>();
  222. private List<string> colors = new List<string>();
  223. private List<string> authors = new List<string>();
  224. private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  225. public List<string> Colors { get => colors; set => colors = value; }
  226. public List<string> Authors { get => authors; set => authors = value; }
  227. public List<AnnotArgsType> AnnotArgsTypes { get => annotArgsTypes; set => annotArgsTypes = value; }
  228. public ScreenAnnotationDialogViewModel()
  229. {
  230. LoadedCommand = new DelegateCommand<object>(Loaded);
  231. CancelCommand = new DelegateCommand(CancelEvent);
  232. OkCommnad = new DelegateCommand<Object>(OkEvent);
  233. CleanCommand = new DelegateCommand<Object>(CleanEvent);
  234. }
  235. private void Loaded(object obj)
  236. {
  237. if (obj is CompositeCommandParameter composite)
  238. {
  239. if (composite.Parameter is Object[] arrys)
  240. {
  241. btnHighlight = arrys[0] as CustomIconToggleBtn;
  242. btnFreeHand = arrys[1] as CustomIconToggleBtn;
  243. btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  244. btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  245. btnSharpLine = arrys[4] as CustomIconToggleBtn;
  246. btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  247. btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  248. btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  249. btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  250. btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  251. btnUnderLine = arrys[10] as CustomIconToggleBtn;
  252. btnAnnotLink = arrys[11] as CustomIconToggleBtn;
  253. for (int i = 0; i < arrys.Length - 2; i++)
  254. {
  255. iconToggleBtns.Add(arrys[i] as CustomIconToggleBtn);
  256. }
  257. SetBtnSelectedState(arrys);
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// 记录设置按钮状态
  263. /// </summary>
  264. /// <param name="arrys"></param>
  265. private void SetBtnSelectedState(object[] arrys)
  266. {
  267. if (AnnotArgsTypes.Count > 0)
  268. {
  269. foreach (var item in AnnotArgsTypes)
  270. {
  271. switch (item)
  272. {
  273. case AnnotArgsType.AnnotNone:
  274. break;
  275. case AnnotArgsType.AnnotSquare:
  276. SetBtnType(btnAnnotSquare, false);
  277. break;
  278. case AnnotArgsType.AnnotCircle:
  279. SetBtnType(btnAnnotCircle, false);
  280. break;
  281. case AnnotArgsType.AnnotSticky:
  282. SetBtnType(btnAnnotSticky, false);
  283. break;
  284. case AnnotArgsType.AnnotLine:
  285. foreach (var annoitem in AnnotationListItems)
  286. {
  287. if ((annoitem.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (annoitem.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  288. {
  289. //箭头
  290. SetBtnType(btnSharpArrow, false);
  291. break;
  292. }
  293. else
  294. {
  295. //线
  296. SetBtnType(btnSharpLine, false);
  297. break;
  298. }
  299. }
  300. break;
  301. case AnnotArgsType.AnnotFreehand:
  302. SetBtnType(btnFreeHand, false);
  303. break;
  304. case AnnotArgsType.AnnotErase:
  305. break;
  306. case AnnotArgsType.AnnotFreeText:
  307. SetBtnType(btnAnnotFreeText, false);
  308. break;
  309. case AnnotArgsType.AnnotStamp:
  310. SetBtnType(btnAnnotStamp, false);
  311. break;
  312. case AnnotArgsType.AnnotHighlight:
  313. SetBtnType(btnHighlight, false);
  314. break;
  315. case AnnotArgsType.AnnotUnderline:
  316. SetBtnType(btnUnderLine, false);
  317. break;
  318. case AnnotArgsType.AnnotStrikeout:
  319. SetBtnType(btnAnnotStrikeout, false);
  320. break;
  321. case AnnotArgsType.AnnotSquiggly:
  322. SetBtnType(btnAnnotSquare, false);
  323. break;
  324. case AnnotArgsType.AnnotLink:
  325. SetBtnType(btnAnnotLink, false);
  326. break;
  327. case AnnotArgsType.AnnotSelectTool:
  328. break;
  329. case AnnotArgsType.SnapshotTool:
  330. break;
  331. case AnnotArgsType.SnapshotWithEditTool:
  332. break;
  333. case AnnotArgsType.WidgetViewForm:
  334. break;
  335. case AnnotArgsType.AnnotSound:
  336. break;
  337. case AnnotArgsType.AnnotMedia:
  338. break;
  339. case AnnotArgsType.AnnotRedaction:
  340. break;
  341. default:
  342. break;
  343. }
  344. }
  345. }
  346. if (arrys[12] is System.Windows.Controls.ListBox listColor)
  347. {
  348. this._ListColor = listColor;
  349. if (Colors.Count > 0)
  350. {
  351. listColor.ItemsSource = AnnotationColors;
  352. foreach (var item in AnnotationColors)
  353. {
  354. foreach (var color in Colors)
  355. {
  356. if (item.Color.ToString() == color)
  357. {
  358. ListBoxItem myListBoxItem = (ListBoxItem)(listColor.ItemContainerGenerator.ContainerFromItem(item));
  359. myListBoxItem.IsSelected = true;
  360. }
  361. }
  362. }
  363. }
  364. }
  365. if (arrys[13] is System.Windows.Controls.ListBox listAuthor)
  366. {
  367. this._ListAuthor = listAuthor;
  368. if (Authors.Count > 0)
  369. {
  370. listAuthor.ItemsSource = AnnotationAuthor;
  371. foreach (var item in AnnotationAuthor)
  372. {
  373. foreach (var author in Authors)
  374. {
  375. if (item.Name == author)
  376. {
  377. ListBoxItem myListBoxItem = (ListBoxItem)(listAuthor.ItemContainerGenerator.ContainerFromItem(item));
  378. myListBoxItem.IsSelected = true;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. }
  385. /// <summary>
  386. /// 清除筛选项
  387. /// </summary>
  388. /// <param name="obj"></param>
  389. private void CleanEvent(Object obj)
  390. {
  391. //for (int i = 0; i < iconToggleBtns.Count; i++)
  392. //{
  393. // SetBtnType(iconToggleBtns[i], true);
  394. //}
  395. //if (this._ListColor != null)
  396. //{
  397. // this._ListColor.SelectedItems.Clear();
  398. //}
  399. //if (this._ListAuthor != null)
  400. //{
  401. // this._ListAuthor.SelectedItems.Clear();
  402. //}
  403. DialogParameters valuePairs = new DialogParameters();
  404. valuePairs.Add(ParameterNames.AnnotationCleanState, true);
  405. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  406. }
  407. /// <summary>
  408. /// 设置类型按钮状态
  409. /// </summary>
  410. /// <param name="btn"></param>
  411. private void SetBtnType(CustomIconToggleBtn btn, bool flag)
  412. {
  413. if (btn != null)
  414. {
  415. if (btn.IsChecked == flag)
  416. {
  417. btn.IsChecked = !flag;
  418. }
  419. }
  420. }
  421. /// <summary>
  422. /// 确认
  423. /// </summary>
  424. /// <param name="obj"></param>
  425. private void OkEvent(Object obj)
  426. {
  427. List<AnnotArgsType> styleDic = GetAnnotArgsType();
  428. //ListBox listColor = arrys[11] as ListBox;
  429. //ListBox listAuthor = arrys[12] as ListBox;
  430. List<string> colors = new List<string>();
  431. List<string> authors = new List<string>();
  432. if (this._ListColor != null)
  433. {
  434. if (this._ListColor.SelectedItems.Count > 0)
  435. {
  436. foreach (var item in this._ListColor.SelectedItems)
  437. {
  438. ColorItem color = item as ColorItem;
  439. colors.Add(color.Color.ToString());
  440. }
  441. }
  442. }
  443. if (this._ListAuthor != null)
  444. {
  445. if (this._ListAuthor.SelectedItems.Count > 0)
  446. {
  447. foreach (var item in this._ListAuthor.SelectedItems)
  448. {
  449. AuthorItem author = item as AuthorItem;
  450. authors.Add(author.Name);
  451. }
  452. }
  453. }
  454. DialogParameters valuePairs = new DialogParameters();
  455. valuePairs.Add(ParameterNames.AnnotArgsTypes, styleDic);
  456. valuePairs.Add(ParameterNames.AnnotationColors, colors);
  457. valuePairs.Add(ParameterNames.AnnotationAuthor, authors);
  458. valuePairs.Add(ParameterNames.AnnotationCleanState, false);
  459. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  460. }
  461. /// <summary>
  462. /// 获取类型按钮状态
  463. /// </summary>
  464. /// <param name="arrys"></param>
  465. /// <returns></returns>
  466. private List<AnnotArgsType> GetAnnotArgsType()
  467. {
  468. List<AnnotArgsType> styleDic = new List<AnnotArgsType>();
  469. //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
  470. //CustomIconToggleBtn btnFreeHand = arrys[1] as CustomIconToggleBtn;
  471. //CustomIconToggleBtn btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  472. //CustomIconToggleBtn btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  473. //CustomIconToggleBtn btnSharpLine = arrys[4] as CustomIconToggleBtn;
  474. //CustomIconToggleBtn btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  475. //CustomIconToggleBtn btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  476. //CustomIconToggleBtn btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  477. //CustomIconToggleBtn btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  478. //CustomIconToggleBtn btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  479. //CustomIconToggleBtn btnUnderLine = arrys[10] as CustomIconToggleBtn;
  480. GetBtnAnnotArgsTypeState(btnHighlight, styleDic, AnnotArgsType.AnnotHighlight);
  481. GetBtnAnnotArgsTypeState(btnFreeHand, styleDic, AnnotArgsType.AnnotFreehand);
  482. GetBtnAnnotArgsTypeState(btnAnnotSticky, styleDic, AnnotArgsType.AnnotSticky);
  483. GetBtnAnnotArgsTypeState(btnAnnotStamp, styleDic, AnnotArgsType.AnnotStamp);
  484. GetBtnAnnotArgsTypeState(btnSharpLine, styleDic, AnnotArgsType.AnnotLine);
  485. GetBtnAnnotArgsTypeState(btnSharpArrow, styleDic, AnnotArgsType.AnnotLine);
  486. GetBtnAnnotArgsTypeState(btnAnnotCircle, styleDic, AnnotArgsType.AnnotCircle);
  487. GetBtnAnnotArgsTypeState(btnAnnotSquare, styleDic, AnnotArgsType.AnnotSquare);
  488. GetBtnAnnotArgsTypeState(btnAnnotFreeText, styleDic, AnnotArgsType.AnnotFreeText);
  489. GetBtnAnnotArgsTypeState(btnAnnotStrikeout, styleDic, AnnotArgsType.AnnotStrikeout);
  490. GetBtnAnnotArgsTypeState(btnUnderLine, styleDic, AnnotArgsType.AnnotUnderline);
  491. GetBtnAnnotArgsTypeState(btnAnnotLink, styleDic, AnnotArgsType.AnnotLink);
  492. return styleDic;
  493. }
  494. /// <summary>
  495. /// 添加被选中的类型按钮到集合
  496. /// </summary>
  497. /// <param name="btnType"></param>
  498. /// <param name="styleDic"></param>
  499. /// <param name="annotArgsType"></param>
  500. private void GetBtnAnnotArgsTypeState(CustomIconToggleBtn btnType, List<AnnotArgsType> styleDic, AnnotArgsType annotArgsType)
  501. {
  502. if (btnType != null)
  503. {
  504. if (btnType.IsChecked == true)
  505. {
  506. if (styleDic.IndexOf(annotArgsType) == -1)
  507. {
  508. styleDic.Add(annotArgsType);
  509. }
  510. }
  511. }
  512. }
  513. private void CancelEvent()
  514. {
  515. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  516. }
  517. public bool CanCloseDialog()
  518. {
  519. return true;
  520. }
  521. public void OnDialogClosed()
  522. {
  523. }
  524. /// <summary>
  525. /// 添加筛选颜色
  526. /// </summary>
  527. /// <param name="color"></param>
  528. private void GetAnnotationColors(System.Windows.Media.Color color)
  529. {
  530. if (AnnotationColors.Count > 0)
  531. {
  532. for (int i = 0; i < AnnotationColors.Count; i++)
  533. {
  534. System.Windows.Media.Color color1 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(AnnotationColors[i].Color.ToString());
  535. if (color1.R == color.R && color1.G == color.G && color1.B == color.B
  536. && color1.A == color.A)
  537. {
  538. AnnotationColors.Remove(AnnotationColors[i]);
  539. }
  540. }
  541. }
  542. AnnotationColors.Add(new ColorItem(color));
  543. }
  544. public void OnDialogOpened(IDialogParameters parameters)
  545. {
  546. ObservableCollection<AnnotationHandlerEventArgs> list;
  547. parameters.TryGetValue<ObservableCollection<AnnotationHandlerEventArgs>>(ParameterNames.AnnotationList, out list);
  548. AnnotationListItems = list;
  549. List<string> colors = new List<string>();
  550. List<string> authors = new List<string>();
  551. List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  552. parameters.TryGetValue<List<string>>(ParameterNames.AnnotationColors, out colors);
  553. parameters.TryGetValue<List<string>>(ParameterNames.AnnotationAuthor, out authors);
  554. parameters.TryGetValue<List<AnnotArgsType>>(ParameterNames.AnnotArgsTypes, out annotArgsTypes);
  555. if (colors != null)
  556. {
  557. this.Colors = colors;
  558. }
  559. if (authors != null)
  560. {
  561. this.Authors = authors;
  562. }
  563. if (annotArgsTypes != null)
  564. {
  565. this.AnnotArgsTypes = annotArgsTypes;
  566. }
  567. if (AnnotationListItems.Count <= 0)
  568. {
  569. return;
  570. }
  571. foreach (var item in AnnotationListItems)
  572. {
  573. AnnotationAuthor.Add(new AuthorItem(item.Author));
  574. AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
  575. switch (item.EventType)
  576. {
  577. case AnnotArgsType.AnnotFreeText://文本
  578. if (data is FreeTextAnnotArgs textAnnotArgs)
  579. {
  580. GetAnnotationColors(textAnnotArgs.FontColor);
  581. }
  582. AnnotFreeTextVisibility = Visibility.Visible;
  583. break;
  584. case AnnotArgsType.AnnotHighlight://高亮
  585. if (data is TextHighlightAnnotArgs highlightAnnotArgs)
  586. {
  587. GetAnnotationColors(highlightAnnotArgs.Color);
  588. }
  589. HighlightVisibility = Visibility.Visible;
  590. break;
  591. case AnnotArgsType.AnnotFreehand://手绘
  592. if (data is FreehandAnnotArgs freehandAnnotArgs)
  593. {
  594. GetAnnotationColors(freehandAnnotArgs.InkColor);
  595. }
  596. FreeHandVisibility = Visibility.Visible;
  597. break;
  598. case AnnotArgsType.AnnotSquiggly://波浪线
  599. break;
  600. case AnnotArgsType.AnnotStamp://图章
  601. AnnotStampVisibility = Visibility.Visible;
  602. break;
  603. case AnnotArgsType.AnnotStrikeout://删除线
  604. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  605. {
  606. GetAnnotationColors(textStrikeoutAnnotArgs.Color);
  607. }
  608. AnnotStickyVisibility = Visibility.Visible;
  609. break;
  610. case AnnotArgsType.AnnotSticky://便签
  611. if (data is StickyAnnotArgs stickyAnnotArgs)
  612. {
  613. GetAnnotationColors(stickyAnnotArgs.Color);
  614. }
  615. AnnotStickyVisibility = Visibility.Visible;
  616. break;
  617. case AnnotArgsType.AnnotUnderline://下划线
  618. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  619. {
  620. GetAnnotationColors(textUnderlineAnnotArgs.Color);
  621. }
  622. UnderLineVisibility = Visibility.Visible;
  623. break;
  624. case AnnotArgsType.AnnotLine:
  625. if ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  626. {
  627. //箭头
  628. SharpArrowVisibility = Visibility.Visible;
  629. }
  630. else
  631. {
  632. //线
  633. SharpLineVisibility = Visibility.Visible;
  634. }
  635. GetAnnotationColors((item.AnnotHandlerEventArgs as LineAnnotArgs).LineColor);
  636. break;
  637. case AnnotArgsType.AnnotSquare://矩形
  638. if (data is SquareAnnotArgs squareAnnotArgs)
  639. {
  640. GetAnnotationColors(squareAnnotArgs.BgColor);
  641. GetAnnotationColors(squareAnnotArgs.LineColor);
  642. }
  643. AnnotSquareVisibility = Visibility.Visible;
  644. break;
  645. case AnnotArgsType.AnnotCircle://圆
  646. if (data is CircleAnnotArgs circleAnnotArgs)
  647. {
  648. GetAnnotationColors(circleAnnotArgs.BgColor);
  649. GetAnnotationColors(circleAnnotArgs.LineColor);
  650. }
  651. AnnotCircleVisibility = Visibility.Visible;
  652. break;
  653. case AnnotArgsType.AnnotLink:
  654. AnnotLinkVisible = Visibility.Visible;
  655. break;
  656. }
  657. }
  658. AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.DistinctHelper(s => s.Name));
  659. }
  660. }
  661. }