ScreenAnnotationDialogViewModel.cs 30 KB

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