ScreenAnnotationDialogViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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 annotSquareVisibility = Visibility.Collapsed;
  127. public Visibility AnnotSquareVisibility
  128. {
  129. get { return annotSquareVisibility; }
  130. set
  131. {
  132. SetProperty(ref annotSquareVisibility, value);
  133. }
  134. }
  135. /// <summary>
  136. /// 文本注释
  137. /// </summary>
  138. private Visibility annotFreeTextVisibility = Visibility.Collapsed;
  139. public Visibility AnnotFreeTextVisibility
  140. {
  141. get { return annotFreeTextVisibility; }
  142. set
  143. {
  144. SetProperty(ref annotFreeTextVisibility, value);
  145. }
  146. }
  147. /// <summary>
  148. /// 删除线
  149. /// </summary>
  150. private Visibility annotStrikeoutVisibility = Visibility.Collapsed;
  151. public Visibility AnnotStrikeoutVisibility
  152. {
  153. get { return annotStrikeoutVisibility; }
  154. set
  155. {
  156. SetProperty(ref annotStrikeoutVisibility, value);
  157. }
  158. }
  159. /// <summary>
  160. /// 下划线
  161. /// </summary>
  162. private Visibility underLineVisibility = Visibility.Collapsed;
  163. public Visibility UnderLineVisibility
  164. {
  165. get { return underLineVisibility; }
  166. set
  167. {
  168. SetProperty(ref underLineVisibility, value);
  169. }
  170. }
  171. #endregion 类型的显示隐藏
  172. public DelegateCommand CancelCommand { get; set; }
  173. public DelegateCommand<Object> OkCommnad { get; set; }
  174. public DelegateCommand<Object> CleanCommand { get; set; }
  175. public DelegateCommand<object> LoadedCommand { get; set; }
  176. public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems { get; set; }
  177. private ObservableCollection<ColorItem> annotationColors = new ObservableCollection<ColorItem>();
  178. public ObservableCollection<ColorItem> AnnotationColors
  179. {
  180. get { return annotationColors; }
  181. set
  182. {
  183. SetProperty(ref annotationColors, value);
  184. }
  185. }
  186. private ObservableCollection<AuthorItem> annotationAuthor = new ObservableCollection<AuthorItem>();
  187. public ObservableCollection<AuthorItem> AnnotationAuthor
  188. {
  189. get { return annotationAuthor; }
  190. set
  191. {
  192. SetProperty(ref annotationAuthor, value);
  193. }
  194. }
  195. private CustomIconToggleBtn btnHighlight = null;
  196. private CustomIconToggleBtn btnFreeHand = null;
  197. private CustomIconToggleBtn btnAnnotSticky = null;
  198. private CustomIconToggleBtn btnAnnotStamp = null;
  199. private CustomIconToggleBtn btnSharpLine = null;
  200. private CustomIconToggleBtn btnSharpArrow = null;
  201. private CustomIconToggleBtn btnAnnotCircle = null;
  202. private CustomIconToggleBtn btnAnnotSquare = null;
  203. private CustomIconToggleBtn btnAnnotFreeText = null;
  204. private CustomIconToggleBtn btnAnnotStrikeout = null;
  205. private CustomIconToggleBtn btnUnderLine = null;
  206. private ListBox _ListColor = null;
  207. private ListBox _ListAuthor = null;
  208. private List<string> colors = new List<string>();
  209. private List<string> authors = new List<string>();
  210. private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  211. public List<string> Colors { get => colors; set => colors = value; }
  212. public List<string> Authors { get => authors; set => authors = value; }
  213. public List<AnnotArgsType> AnnotArgsTypes { get => annotArgsTypes; set => annotArgsTypes = value; }
  214. public ScreenAnnotationDialogViewModel()
  215. {
  216. LoadedCommand = new DelegateCommand<object>(Loaded);
  217. CancelCommand = new DelegateCommand(CancelEvent);
  218. OkCommnad = new DelegateCommand<Object>(OkEvent);
  219. CleanCommand = new DelegateCommand<Object>(CleanEvent);
  220. }
  221. private void Loaded(object obj)
  222. {
  223. if (obj is CompositeCommandParameter composite)
  224. {
  225. if (composite.Parameter is Object[] arrys)
  226. {
  227. btnHighlight = arrys[0] as CustomIconToggleBtn;
  228. btnFreeHand = arrys[1] as CustomIconToggleBtn;
  229. btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  230. btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  231. btnSharpLine = arrys[4] as CustomIconToggleBtn;
  232. btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  233. btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  234. btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  235. btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  236. btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  237. btnUnderLine = arrys[10] as CustomIconToggleBtn;
  238. SetBtnSelectedState(arrys);
  239. }
  240. }
  241. }
  242. /// <summary>
  243. /// 记录设置按钮状态
  244. /// </summary>
  245. /// <param name="arrys"></param>
  246. private void SetBtnSelectedState(object[] arrys)
  247. {
  248. if (AnnotArgsTypes.Count > 0)
  249. {
  250. foreach (var item in AnnotArgsTypes)
  251. {
  252. switch (item)
  253. {
  254. case AnnotArgsType.AnnotNone:
  255. break;
  256. case AnnotArgsType.AnnotSquare:
  257. SetBtnType(btnAnnotSquare, false);
  258. break;
  259. case AnnotArgsType.AnnotCircle:
  260. SetBtnType(btnAnnotCircle, false);
  261. break;
  262. case AnnotArgsType.AnnotSticky:
  263. SetBtnType(btnAnnotSticky, false);
  264. break;
  265. case AnnotArgsType.AnnotLine:
  266. foreach (var annoitem in AnnotationListItems)
  267. {
  268. if ((annoitem.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (annoitem.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  269. {
  270. //箭头
  271. SetBtnType(btnSharpArrow, false);
  272. break;
  273. }
  274. else
  275. {
  276. //线
  277. SetBtnType(btnSharpLine, false);
  278. break;
  279. }
  280. }
  281. break;
  282. case AnnotArgsType.AnnotFreehand:
  283. SetBtnType(btnFreeHand, false);
  284. break;
  285. case AnnotArgsType.AnnotErase:
  286. break;
  287. case AnnotArgsType.AnnotFreeText:
  288. SetBtnType(btnAnnotFreeText, false);
  289. break;
  290. case AnnotArgsType.AnnotStamp:
  291. SetBtnType(btnAnnotStamp, false);
  292. break;
  293. case AnnotArgsType.AnnotHighlight:
  294. SetBtnType(btnHighlight, false);
  295. break;
  296. case AnnotArgsType.AnnotUnderline:
  297. SetBtnType(btnUnderLine, false);
  298. break;
  299. case AnnotArgsType.AnnotStrikeout:
  300. SetBtnType(btnAnnotStrikeout, false);
  301. break;
  302. case AnnotArgsType.AnnotSquiggly:
  303. SetBtnType(btnAnnotSquare, false);
  304. break;
  305. case AnnotArgsType.AnnotLink:
  306. break;
  307. case AnnotArgsType.AnnotSelectTool:
  308. break;
  309. case AnnotArgsType.SnapshotTool:
  310. break;
  311. case AnnotArgsType.SnapshotWithEditTool:
  312. break;
  313. case AnnotArgsType.WidgetViewForm:
  314. break;
  315. case AnnotArgsType.AnnotSound:
  316. break;
  317. case AnnotArgsType.AnnotMedia:
  318. break;
  319. case AnnotArgsType.AnnotRedaction:
  320. break;
  321. default:
  322. break;
  323. }
  324. }
  325. }
  326. if (arrys[11] is System.Windows.Controls.ListBox listColor)
  327. {
  328. this._ListColor = listColor;
  329. if (Colors.Count > 0)
  330. {
  331. listColor.ItemsSource = AnnotationColors;
  332. foreach (var item in AnnotationColors)
  333. {
  334. foreach (var color in Colors)
  335. {
  336. if (item.Color.ToString() == color)
  337. {
  338. ListBoxItem myListBoxItem = (ListBoxItem)(listColor.ItemContainerGenerator.ContainerFromItem(item));
  339. myListBoxItem.IsSelected = true;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. if (arrys[12] is System.Windows.Controls.ListBox listAuthor)
  346. {
  347. this._ListAuthor = listAuthor;
  348. if (Authors.Count > 0)
  349. {
  350. listAuthor.ItemsSource = AnnotationAuthor;
  351. foreach (var item in AnnotationAuthor)
  352. {
  353. foreach (var author in Authors)
  354. {
  355. if (item.Name == author)
  356. {
  357. ListBoxItem myListBoxItem = (ListBoxItem)(listAuthor.ItemContainerGenerator.ContainerFromItem(item));
  358. myListBoxItem.IsSelected = true;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. /// <summary>
  366. /// 清除筛选项
  367. /// </summary>
  368. /// <param name="obj"></param>
  369. private void CleanEvent(Object obj)
  370. {
  371. if (obj is Object[] arrys)
  372. {
  373. //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
  374. //CustomIconToggleBtn btnFreeHand = arrys[1] as CustomIconToggleBtn;
  375. //CustomIconToggleBtn btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  376. //CustomIconToggleBtn btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  377. //CustomIconToggleBtn btnSharpLine = arrys[4] as CustomIconToggleBtn;
  378. //CustomIconToggleBtn btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  379. //CustomIconToggleBtn btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  380. //CustomIconToggleBtn btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  381. //CustomIconToggleBtn btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  382. //CustomIconToggleBtn btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  383. //CustomIconToggleBtn btnUnderLine = arrys[10] as CustomIconToggleBtn;
  384. SetBtnType(btnHighlight, true);
  385. SetBtnType(btnFreeHand, true);
  386. SetBtnType(btnAnnotSticky, true);
  387. SetBtnType(btnAnnotStamp, true);
  388. SetBtnType(btnSharpLine, true);
  389. SetBtnType(btnSharpArrow, true);
  390. SetBtnType(btnAnnotCircle, true);
  391. SetBtnType(btnAnnotSquare, true);
  392. SetBtnType(btnAnnotFreeText, true);
  393. SetBtnType(btnAnnotStrikeout, true);
  394. SetBtnType(btnUnderLine, true);
  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. }
  408. /// <summary>
  409. /// 设置类型按钮状态
  410. /// </summary>
  411. /// <param name="btn"></param>
  412. private void SetBtnType(CustomIconToggleBtn btn, bool flag)
  413. {
  414. if (btn != null)
  415. {
  416. if (btn.IsChecked == flag)
  417. {
  418. btn.IsChecked = !flag;
  419. }
  420. }
  421. }
  422. /// <summary>
  423. /// 确认
  424. /// </summary>
  425. /// <param name="obj"></param>
  426. private void OkEvent(Object obj)
  427. {
  428. if (obj is Object[] arrys)
  429. {
  430. List<AnnotArgsType> styleDic = GetAnnotArgsType(arrys);
  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. }
  465. /// <summary>
  466. /// 获取类型按钮状态
  467. /// </summary>
  468. /// <param name="arrys"></param>
  469. /// <returns></returns>
  470. private List<AnnotArgsType> GetAnnotArgsType(object[] arrys)
  471. {
  472. List<AnnotArgsType> styleDic = new List<AnnotArgsType>();
  473. //CustomIconToggleBtn btnHighlight = arrys[0] as CustomIconToggleBtn;
  474. //CustomIconToggleBtn btnFreeHand = arrys[1] as CustomIconToggleBtn;
  475. //CustomIconToggleBtn btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
  476. //CustomIconToggleBtn btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
  477. //CustomIconToggleBtn btnSharpLine = arrys[4] as CustomIconToggleBtn;
  478. //CustomIconToggleBtn btnSharpArrow = arrys[5] as CustomIconToggleBtn;
  479. //CustomIconToggleBtn btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
  480. //CustomIconToggleBtn btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
  481. //CustomIconToggleBtn btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
  482. //CustomIconToggleBtn btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
  483. //CustomIconToggleBtn btnUnderLine = arrys[10] as CustomIconToggleBtn;
  484. GetBtnAnnotArgsTypeState(btnHighlight, styleDic, AnnotArgsType.AnnotHighlight);
  485. GetBtnAnnotArgsTypeState(btnFreeHand, styleDic, AnnotArgsType.AnnotFreehand);
  486. GetBtnAnnotArgsTypeState(btnAnnotSticky, styleDic, AnnotArgsType.AnnotSticky);
  487. GetBtnAnnotArgsTypeState(btnAnnotStamp, styleDic, AnnotArgsType.AnnotStamp);
  488. GetBtnAnnotArgsTypeState(btnSharpLine, styleDic, AnnotArgsType.AnnotLine);
  489. GetBtnAnnotArgsTypeState(btnSharpArrow, styleDic, AnnotArgsType.AnnotLine);
  490. GetBtnAnnotArgsTypeState(btnAnnotCircle, styleDic, AnnotArgsType.AnnotCircle);
  491. GetBtnAnnotArgsTypeState(btnAnnotSquare, styleDic, AnnotArgsType.AnnotSquare);
  492. GetBtnAnnotArgsTypeState(btnAnnotFreeText, styleDic, AnnotArgsType.AnnotFreeText);
  493. GetBtnAnnotArgsTypeState(btnAnnotStrikeout, styleDic, AnnotArgsType.AnnotStrikeout);
  494. GetBtnAnnotArgsTypeState(btnUnderLine, styleDic, AnnotArgsType.AnnotUnderline);
  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. AnnotStickyVisibility = 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 ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  629. {
  630. //箭头
  631. SharpArrowVisibility = Visibility.Visible;
  632. }
  633. else
  634. {
  635. //线
  636. SharpLineVisibility = Visibility.Visible;
  637. }
  638. GetAnnotationColors((item.AnnotHandlerEventArgs as LineAnnotArgs).LineColor);
  639. break;
  640. case AnnotArgsType.AnnotSquare://矩形
  641. if (data is SquareAnnotArgs squareAnnotArgs)
  642. {
  643. GetAnnotationColors(squareAnnotArgs.BgColor);
  644. GetAnnotationColors(squareAnnotArgs.LineColor);
  645. }
  646. AnnotSquareVisibility = Visibility.Visible;
  647. break;
  648. case AnnotArgsType.AnnotCircle://圆
  649. if (data is CircleAnnotArgs circleAnnotArgs)
  650. {
  651. GetAnnotationColors(circleAnnotArgs.BgColor);
  652. GetAnnotationColors(circleAnnotArgs.LineColor);
  653. }
  654. AnnotCircleVisibility = Visibility.Visible;
  655. break;
  656. }
  657. }
  658. AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.DistinctHelper(s => s.Name));
  659. }
  660. }
  661. }