ScreenAnnotationDialogViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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 = Visibility.Collapsed;
  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 is LineAnnotArgs lineAnnotArgs)
  288. {
  289. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  290. {
  291. //箭头
  292. SetBtnType(btnSharpArrow, false);
  293. break;
  294. }
  295. else
  296. {
  297. //线
  298. SetBtnType(btnSharpLine, false);
  299. break;
  300. }
  301. }
  302. }
  303. break;
  304. case AnnotArgsType.AnnotFreehand:
  305. SetBtnType(btnFreeHand, false);
  306. break;
  307. case AnnotArgsType.AnnotErase:
  308. break;
  309. case AnnotArgsType.AnnotFreeText:
  310. SetBtnType(btnAnnotFreeText, false);
  311. break;
  312. case AnnotArgsType.AnnotStamp:
  313. SetBtnType(btnAnnotStamp, false);
  314. break;
  315. case AnnotArgsType.AnnotHighlight:
  316. SetBtnType(btnHighlight, false);
  317. break;
  318. case AnnotArgsType.AnnotUnderline:
  319. SetBtnType(btnUnderLine, false);
  320. break;
  321. case AnnotArgsType.AnnotStrikeout:
  322. SetBtnType(btnAnnotStrikeout, false);
  323. break;
  324. case AnnotArgsType.AnnotSquiggly:
  325. SetBtnType(btnAnnotSquare, false);
  326. break;
  327. case AnnotArgsType.AnnotLink:
  328. SetBtnType(btnAnnotLink, false);
  329. break;
  330. case AnnotArgsType.AnnotSelectTool:
  331. break;
  332. case AnnotArgsType.SnapshotTool:
  333. break;
  334. case AnnotArgsType.SnapshotWithEditTool:
  335. break;
  336. case AnnotArgsType.WidgetViewForm:
  337. break;
  338. case AnnotArgsType.AnnotSound:
  339. break;
  340. case AnnotArgsType.AnnotMedia:
  341. break;
  342. case AnnotArgsType.AnnotRedaction:
  343. break;
  344. default:
  345. break;
  346. }
  347. }
  348. }
  349. if (arrys[12] is System.Windows.Controls.ListBox listColor)
  350. {
  351. this._ListColor = listColor;
  352. if (Colors.Count > 0)
  353. {
  354. listColor.ItemsSource = AnnotationColors;
  355. foreach (var item in AnnotationColors)
  356. {
  357. foreach (var color in Colors)
  358. {
  359. if (item.Color.ToString() == color)
  360. {
  361. ListBoxItem myListBoxItem = (ListBoxItem)(listColor.ItemContainerGenerator.ContainerFromItem(item));
  362. myListBoxItem.IsSelected = true;
  363. }
  364. }
  365. }
  366. }
  367. }
  368. if (arrys[13] is System.Windows.Controls.ListBox listAuthor)
  369. {
  370. this._ListAuthor = listAuthor;
  371. if (Authors.Count > 0)
  372. {
  373. listAuthor.ItemsSource = AnnotationAuthor;
  374. foreach (var item in AnnotationAuthor)
  375. {
  376. foreach (var author in Authors)
  377. {
  378. if (item.Name == author)
  379. {
  380. ListBoxItem myListBoxItem = (ListBoxItem)(listAuthor.ItemContainerGenerator.ContainerFromItem(item));
  381. myListBoxItem.IsSelected = true;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. /// <summary>
  389. /// 清除筛选项
  390. /// </summary>
  391. /// <param name="obj"></param>
  392. private void CleanEvent(Object obj)
  393. {
  394. //for (int i = 0; i < iconToggleBtns.Count; i++)
  395. //{
  396. // SetBtnType(iconToggleBtns[i], true);
  397. //}
  398. //if (this._ListColor != null)
  399. //{
  400. // this._ListColor.SelectedItems.Clear();
  401. //}
  402. //if (this._ListAuthor != null)
  403. //{
  404. // this._ListAuthor.SelectedItems.Clear();
  405. //}
  406. DialogParameters valuePairs = new DialogParameters();
  407. valuePairs.Add(ParameterNames.AnnotationCleanState, true);
  408. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  409. }
  410. /// <summary>
  411. /// 设置类型按钮状态
  412. /// </summary>
  413. /// <param name="btn"></param>
  414. private void SetBtnType(CustomIconToggleBtn btn, bool flag)
  415. {
  416. if (btn != null)
  417. {
  418. if (btn.IsChecked == flag)
  419. {
  420. btn.IsChecked = !flag;
  421. }
  422. }
  423. }
  424. /// <summary>
  425. /// 确认
  426. /// </summary>
  427. /// <param name="obj"></param>
  428. private void OkEvent(Object obj)
  429. {
  430. List<AnnotArgsType> styleDic = GetAnnotArgsType();
  431. //ListBox listColor = arrys[11] as ListBox;
  432. //ListBox listAuthor = arrys[12] as ListBox;
  433. List<string> colors = new List<string>();
  434. List<string> authors = new List<string>();
  435. if (this._ListColor != null)
  436. {
  437. if (this._ListColor.SelectedItems.Count > 0)
  438. {
  439. foreach (var item in this._ListColor.SelectedItems)
  440. {
  441. ColorItem color = item as ColorItem;
  442. colors.Add(color.Color.ToString());
  443. }
  444. }
  445. }
  446. if (this._ListAuthor != null)
  447. {
  448. if (this._ListAuthor.SelectedItems.Count > 0)
  449. {
  450. foreach (var item in this._ListAuthor.SelectedItems)
  451. {
  452. AuthorItem author = item as AuthorItem;
  453. authors.Add(author.Name);
  454. }
  455. }
  456. }
  457. DialogParameters valuePairs = new DialogParameters();
  458. valuePairs.Add(ParameterNames.AnnotArgsTypes, styleDic);
  459. valuePairs.Add(ParameterNames.AnnotationColors, colors);
  460. valuePairs.Add(ParameterNames.AnnotationAuthor, authors);
  461. valuePairs.Add(ParameterNames.AnnotationCleanState, false);
  462. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  463. }
  464. /// <summary>
  465. /// 获取类型按钮状态
  466. /// </summary>
  467. /// <param name="arrys"></param>
  468. /// <returns></returns>
  469. private List<AnnotArgsType> GetAnnotArgsType()
  470. {
  471. List<AnnotArgsType> styleDic = new List<AnnotArgsType>();
  472. //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
  473. //CustomIconToggleBtn btnFreeHand = arrys[1] as CustomIconToggleBtn;
  474. //CustomIconToggleBtn btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  475. //CustomIconToggleBtn btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  476. //CustomIconToggleBtn btnSharpLine = arrys[4] as CustomIconToggleBtn;
  477. //CustomIconToggleBtn btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  478. //CustomIconToggleBtn btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  479. //CustomIconToggleBtn btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  480. //CustomIconToggleBtn btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  481. //CustomIconToggleBtn btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  482. //CustomIconToggleBtn btnUnderLine = arrys[10] as CustomIconToggleBtn;
  483. GetBtnAnnotArgsTypeState(btnHighlight, styleDic, AnnotArgsType.AnnotHighlight);
  484. GetBtnAnnotArgsTypeState(btnFreeHand, styleDic, AnnotArgsType.AnnotFreehand);
  485. GetBtnAnnotArgsTypeState(btnAnnotSticky, styleDic, AnnotArgsType.AnnotSticky);
  486. GetBtnAnnotArgsTypeState(btnAnnotStamp, styleDic, AnnotArgsType.AnnotStamp);
  487. GetBtnAnnotArgsTypeState(btnSharpLine, styleDic, AnnotArgsType.AnnotLine);
  488. GetBtnAnnotArgsTypeState(btnSharpArrow, styleDic, AnnotArgsType.AnnotLine);
  489. GetBtnAnnotArgsTypeState(btnAnnotCircle, styleDic, AnnotArgsType.AnnotCircle);
  490. GetBtnAnnotArgsTypeState(btnAnnotSquare, styleDic, AnnotArgsType.AnnotSquare);
  491. GetBtnAnnotArgsTypeState(btnAnnotFreeText, styleDic, AnnotArgsType.AnnotFreeText);
  492. GetBtnAnnotArgsTypeState(btnAnnotStrikeout, styleDic, AnnotArgsType.AnnotStrikeout);
  493. GetBtnAnnotArgsTypeState(btnUnderLine, styleDic, AnnotArgsType.AnnotUnderline);
  494. GetBtnAnnotArgsTypeState(btnAnnotLink, styleDic, AnnotArgsType.AnnotLink);
  495. return styleDic;
  496. }
  497. /// <summary>
  498. /// 添加被选中的类型按钮到集合
  499. /// </summary>
  500. /// <param name="btnType"></param>
  501. /// <param name="styleDic"></param>
  502. /// <param name="annotArgsType"></param>
  503. private void GetBtnAnnotArgsTypeState(CustomIconToggleBtn btnType, List<AnnotArgsType> styleDic, AnnotArgsType annotArgsType)
  504. {
  505. if (btnType != null)
  506. {
  507. if (btnType.IsChecked == true)
  508. {
  509. if (styleDic.IndexOf(annotArgsType) == -1)
  510. {
  511. styleDic.Add(annotArgsType);
  512. }
  513. }
  514. }
  515. }
  516. private void CancelEvent()
  517. {
  518. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  519. }
  520. public bool CanCloseDialog()
  521. {
  522. return true;
  523. }
  524. public void OnDialogClosed()
  525. {
  526. }
  527. /// <summary>
  528. /// 添加筛选颜色
  529. /// </summary>
  530. /// <param name="color"></param>
  531. private void GetAnnotationColors(System.Windows.Media.Color color)
  532. {
  533. if (AnnotationColors.Count > 0)
  534. {
  535. for (int i = 0; i < AnnotationColors.Count; i++)
  536. {
  537. System.Windows.Media.Color color1 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(AnnotationColors[i].Color.ToString());
  538. if (color1.R == color.R && color1.G == color.G && color1.B == color.B
  539. && color1.A == color.A)
  540. {
  541. AnnotationColors.Remove(AnnotationColors[i]);
  542. }
  543. }
  544. }
  545. AnnotationColors.Add(new ColorItem(color));
  546. }
  547. public void OnDialogOpened(IDialogParameters parameters)
  548. {
  549. ObservableCollection<AnnotationHandlerEventArgs> list;
  550. parameters.TryGetValue<ObservableCollection<AnnotationHandlerEventArgs>>(ParameterNames.AnnotationList, out list);
  551. AnnotationListItems = list;
  552. List<string> colors = new List<string>();
  553. List<string> authors = new List<string>();
  554. List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  555. parameters.TryGetValue<List<string>>(ParameterNames.AnnotationColors, out colors);
  556. parameters.TryGetValue<List<string>>(ParameterNames.AnnotationAuthor, out authors);
  557. parameters.TryGetValue<List<AnnotArgsType>>(ParameterNames.AnnotArgsTypes, out annotArgsTypes);
  558. if (colors != null)
  559. {
  560. this.Colors = colors;
  561. }
  562. if (authors != null)
  563. {
  564. this.Authors = authors;
  565. }
  566. if (annotArgsTypes != null)
  567. {
  568. this.AnnotArgsTypes = annotArgsTypes;
  569. }
  570. if (AnnotationListItems.Count <= 0)
  571. {
  572. return;
  573. }
  574. foreach (var item in AnnotationListItems)
  575. {
  576. AnnotationAuthor.Add(new AuthorItem(item.Author));
  577. AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
  578. switch (item.EventType)
  579. {
  580. case AnnotArgsType.AnnotFreeText://文本
  581. if (data is FreeTextAnnotArgs textAnnotArgs)
  582. {
  583. GetAnnotationColors(textAnnotArgs.FontColor);
  584. }
  585. AnnotFreeTextVisibility = Visibility.Visible;
  586. break;
  587. case AnnotArgsType.AnnotHighlight://高亮
  588. if (data is TextHighlightAnnotArgs highlightAnnotArgs)
  589. {
  590. GetAnnotationColors(highlightAnnotArgs.Color);
  591. }
  592. HighlightVisibility = Visibility.Visible;
  593. break;
  594. case AnnotArgsType.AnnotFreehand://手绘
  595. if (data is FreehandAnnotArgs freehandAnnotArgs)
  596. {
  597. GetAnnotationColors(freehandAnnotArgs.InkColor);
  598. }
  599. FreeHandVisibility = Visibility.Visible;
  600. break;
  601. case AnnotArgsType.AnnotSquiggly://波浪线
  602. break;
  603. case AnnotArgsType.AnnotStamp://图章
  604. AnnotStampVisibility = Visibility.Visible;
  605. break;
  606. case AnnotArgsType.AnnotStrikeout://删除线
  607. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  608. {
  609. GetAnnotationColors(textStrikeoutAnnotArgs.Color);
  610. }
  611. AnnotStrikeoutVisibility = Visibility.Visible;
  612. break;
  613. case AnnotArgsType.AnnotSticky://便签
  614. if (data is StickyAnnotArgs stickyAnnotArgs)
  615. {
  616. GetAnnotationColors(stickyAnnotArgs.Color);
  617. }
  618. AnnotStickyVisibility = Visibility.Visible;
  619. break;
  620. case AnnotArgsType.AnnotUnderline://下划线
  621. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  622. {
  623. GetAnnotationColors(textUnderlineAnnotArgs.Color);
  624. }
  625. UnderLineVisibility = Visibility.Visible;
  626. break;
  627. case AnnotArgsType.AnnotLine:
  628. if (data is LineAnnotArgs lineAnnotArgs)
  629. {
  630. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  631. {
  632. //箭头
  633. SharpArrowVisibility = Visibility.Visible;
  634. }
  635. else
  636. {
  637. //线
  638. SharpLineVisibility = Visibility.Visible;
  639. }
  640. GetAnnotationColors(lineAnnotArgs.LineColor);
  641. }
  642. break;
  643. case AnnotArgsType.AnnotSquare://矩形
  644. if (data is SquareAnnotArgs squareAnnotArgs)
  645. {
  646. GetAnnotationColors(squareAnnotArgs.BgColor);
  647. GetAnnotationColors(squareAnnotArgs.LineColor);
  648. }
  649. AnnotSquareVisibility = Visibility.Visible;
  650. break;
  651. case AnnotArgsType.AnnotCircle://圆
  652. if (data is CircleAnnotArgs circleAnnotArgs)
  653. {
  654. GetAnnotationColors(circleAnnotArgs.BgColor);
  655. GetAnnotationColors(circleAnnotArgs.LineColor);
  656. }
  657. AnnotCircleVisibility = Visibility.Visible;
  658. break;
  659. case AnnotArgsType.AnnotLink:
  660. AnnotLinkVisible = Visibility.Visible;
  661. break;
  662. }
  663. }
  664. AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.DistinctHelper(s => s.Name));
  665. }
  666. }
  667. }