AnnotToolContentViewModel.Command.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument.Action;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using PDF_Office.CustomControl;
  8. using PDF_Office.EventAggregators;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Properties;
  11. using PDF_Office.ViewModels.BOTA;
  12. using PDF_Office.Views.BOTA;
  13. using PDFSettings;
  14. using Prism.Mvvm;
  15. using Prism.Regions;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Controls;
  23. using System.Windows.Controls.Primitives;
  24. using System.Windows.Media;
  25. using System.Diagnostics;
  26. namespace PDF_Office.ViewModels.Tools
  27. {
  28. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  29. {
  30. #region 事件绑定和解绑
  31. private void BindingEvent()
  32. {
  33. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  34. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  35. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  36. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  37. propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
  38. propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
  39. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  40. propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  41. }
  42. private void UnBindingEvent()
  43. {
  44. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  45. propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
  46. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  47. }
  48. private void BindingPDFViewerHandler()
  49. {
  50. //来自PDFViewer的响应事件
  51. if (PDFViewer != null)
  52. {
  53. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  54. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  55. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  56. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  57. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  58. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  59. PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
  60. PDFViewer.WidgetClickHander += PDFViewer_WidgetClickHander;
  61. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  62. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  63. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  64. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  65. }
  66. }
  67. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  68. {
  69. if (action == null)
  70. {
  71. return;
  72. }
  73. switch (action.ActionType)
  74. {
  75. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  76. if (PDFViewer != null)
  77. {
  78. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  79. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  80. if (dest != null)
  81. {
  82. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  83. }
  84. }
  85. break;
  86. case C_ACTION_TYPE.ACTION_TYPE_URI:
  87. {
  88. CPDFUriAction uriAction = action as CPDFUriAction;
  89. string uri = uriAction.GetUri();
  90. try
  91. {
  92. if (!string.IsNullOrEmpty(uri))
  93. {
  94. Process.Start(uri);
  95. }
  96. }
  97. catch (Exception ex)
  98. {
  99. }
  100. }
  101. break;
  102. }
  103. }
  104. private void UnBindingPDFViewerHandler()
  105. {
  106. if (PDFViewer != null)
  107. {
  108. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  109. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  110. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  111. PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
  112. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  113. }
  114. }
  115. #endregion 事件绑定和解绑
  116. #region PDFViewer事件
  117. //选中和非选中注释,右键菜单
  118. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  119. {
  120. if (e != null)
  121. {
  122. var annot = e.AnnotItemsList[0];
  123. if (annot != null)
  124. {
  125. if (e.AnnotItemsList.Count == 1)
  126. {
  127. //IsAnnotCreateReset:是否为创建注释的状态
  128. if (e.IsAnnotCreateReset == false)
  129. {
  130. GetSelectedAnnots(e);
  131. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  132. PDFViewer.SetToolParam(annot);
  133. }
  134. else
  135. {
  136. switch (annot.EventType)
  137. {
  138. case AnnotArgsType.AnnotLink:
  139. //viewContentViewModel.IsCreateLink = false;
  140. GetLink(e.AnnotItemsList, e);
  141. PDFViewer.SetToolParam(annot);
  142. break;
  143. }
  144. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  145. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  146. annot.EventType != AnnotArgsType.AnnotUnderline &&
  147. annot.EventType != AnnotArgsType.AnnotHighlight &&
  148. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  149. annot.EventType != AnnotArgsType.AnnotLink &&
  150. annot.EventType != AnnotArgsType.AnnotFreehand &&
  151. annot.EventType != AnnotArgsType.AnnotSticky
  152. )
  153. {
  154. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  155. {
  156. foreach (var item in ToolExpandDict)
  157. {
  158. if (item.Value == e.AnnotItemsList[0].EventType)
  159. {
  160. annot = null;//新建注释时,回到默认值
  161. FindAnnotTypeKey(item.Key, ref annot);
  162. break;
  163. }
  164. }
  165. }
  166. }
  167. //else
  168. PDFViewer.SetToolParam(annot);
  169. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  170. if (isRightMenuAddAnnot)
  171. {
  172. ShowPropertyPanel(false);
  173. }
  174. else
  175. {
  176. ShowPropertyPanel();
  177. }
  178. }
  179. }
  180. else
  181. {
  182. bool isDifferentAnnotTyle = false;
  183. var lastAnnot = annot;
  184. foreach (var item in e.AnnotItemsList)
  185. {
  186. if (lastAnnot.EventType != item.EventType)
  187. {
  188. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  189. {
  190. lastAnnot = item;
  191. continue;
  192. }
  193. lastAnnot = item;
  194. isDifferentAnnotTyle = true;
  195. break;
  196. }
  197. }
  198. if (isDifferentAnnotTyle)
  199. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  200. else
  201. GetSelectedAnnots(e);
  202. }
  203. }
  204. }
  205. else
  206. {
  207. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  208. }
  209. }
  210. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  211. {
  212. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  213. annot.EventType == AnnotArgsType.AnnotSquare ||
  214. annot.EventType == AnnotArgsType.AnnotLine
  215. )
  216. {
  217. return true;
  218. }
  219. else
  220. {
  221. return false;
  222. }
  223. }
  224. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  225. {
  226. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  227. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  228. annot.EventType == AnnotArgsType.AnnotHighlight ||
  229. annot.EventType == AnnotArgsType.AnnotStrikeout
  230. )
  231. {
  232. return true;
  233. }
  234. else
  235. {
  236. return false;
  237. }
  238. }
  239. private void GetSelectedAnnots(AnnotAttribEvent e)
  240. {
  241. var annot = e.AnnotItemsList[0];
  242. switch (annot.EventType)
  243. {
  244. case AnnotArgsType.AnnotHighlight:
  245. GetHighLight(e.AnnotItemsList);
  246. break;
  247. case AnnotArgsType.AnnotUnderline:
  248. GetUnderLine(e.AnnotItemsList);
  249. break;
  250. case AnnotArgsType.AnnotStrikeout:
  251. GetStrikeout(e.AnnotItemsList);
  252. break;
  253. case AnnotArgsType.AnnotSquiggly:
  254. GetSquiggly(e.AnnotItemsList);
  255. break;
  256. case AnnotArgsType.AnnotFreehand:
  257. GetFreehand(e.AnnotItemsList);
  258. break;
  259. case AnnotArgsType.AnnotFreeText:
  260. GetFreetext(e.AnnotItemsList);
  261. break;
  262. case AnnotArgsType.AnnotSquare:
  263. GetRect(e.AnnotItemsList);
  264. break;
  265. case AnnotArgsType.AnnotCircle:
  266. GetCircle(e.AnnotItemsList);
  267. break;
  268. case AnnotArgsType.AnnotLine:
  269. bool isLine = true;
  270. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  271. {
  272. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
  273. {
  274. isLine = false;
  275. }
  276. }
  277. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  278. {
  279. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
  280. {
  281. isLine = false;
  282. }
  283. }
  284. if (isLine)
  285. GetArrowLine("Line", e.AnnotItemsList);
  286. else
  287. GetArrowLine("Arrow", e.AnnotItemsList);
  288. break;
  289. case AnnotArgsType.AnnotLink:
  290. //viewContentViewModel.IsCreateLink = false;
  291. GetLink(e.AnnotItemsList, e);
  292. break;
  293. case AnnotArgsType.AnnotSticky:
  294. GetStickyNote(e.AnnotItemsList);
  295. break;
  296. }
  297. }
  298. //在注释工具的状态下,右键菜单
  299. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  300. {
  301. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  302. return;
  303. switch (e.CommandType)
  304. {
  305. case CommandType.Context:
  306. if (e.AnnotEventArgsList.Count > 0)
  307. {
  308. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  309. {
  310. //绑定标记密文处右键菜单
  311. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  312. }
  313. else
  314. {
  315. if(e.AnnotEventArgsList.Count == 1)
  316. {
  317. var selectedAnnot = e.AnnotEventArgsList[0];
  318. switch(selectedAnnot.EventType)
  319. {
  320. case AnnotArgsType.AnnotHighlight:
  321. case AnnotArgsType.AnnotUnderline:
  322. case AnnotArgsType.AnnotStrikeout:
  323. case AnnotArgsType.AnnotSquiggly:
  324. e.PopupMenu = SelectHightAnnotMenu(sender);
  325. break;
  326. case AnnotArgsType.AnnotFreehand:
  327. e.PopupMenu = SelectFreeHandAnnotMenu(sender);
  328. break;
  329. case AnnotArgsType.AnnotFreeText:
  330. e.PopupMenu = SelectFreeTextAnnotMenu(sender);
  331. break;
  332. case AnnotArgsType.AnnotSticky:
  333. e.PopupMenu = SelectStrickNoteAnnotMenu(sender);
  334. break;
  335. case AnnotArgsType.AnnotSquare:
  336. case AnnotArgsType.AnnotLine:
  337. case AnnotArgsType.AnnotCircle:
  338. e.PopupMenu = SelectShapeAnnotMenu(sender);
  339. break;
  340. case AnnotArgsType.AnnotLink:
  341. e.PopupMenu = SelectHightAnnotMenu(sender);
  342. break;
  343. case AnnotArgsType.AnnotStamp:
  344. e.PopupMenu = SelectHightAnnotMenu(sender);
  345. break;
  346. }
  347. }
  348. else
  349. {
  350. bool isHigh = true;//是否为高亮
  351. foreach(var item in e.AnnotEventArgsList)
  352. {
  353. if(isHightAnnot(item) == false)
  354. {
  355. isHigh = false;
  356. break;
  357. }
  358. }
  359. e.PopupMenu = SelectMultiAnnotMenu(sender, isHigh);
  360. }
  361. }
  362. if (e.PopupMenu != null)
  363. {
  364. e.Handle = true;
  365. }
  366. }
  367. else
  368. {
  369. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  370. {
  371. e.PopupMenu = NoneSelectAnnotContextMenu(sender, e);
  372. if (e.PopupMenu != null)
  373. {
  374. e.Handle = true;
  375. }
  376. }
  377. else
  378. {
  379. e.PopupMenu = ViewerContextMenu();
  380. if (e.PopupMenu != null)
  381. {
  382. e.Handle = true;
  383. }
  384. }
  385. }
  386. break;
  387. }
  388. }
  389. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  390. {
  391. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  392. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  393. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  394. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  395. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  396. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  397. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  398. {
  399. e.PopupMenu = popMenu;
  400. e.Handle = true;
  401. if (popMenu != null && popMenu.Items.Count == 5)
  402. {
  403. //复制
  404. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  405. menuItem.CommandTarget = PDFViewer;
  406. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  407. //导出
  408. menuItem = popMenu.Items[1] as MenuItem;
  409. menuItem.CommandTarget = PDFViewer;
  410. if (menuItem.Items.Count == 3)
  411. {
  412. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  413. menuItem1.CommandTarget = PDFViewer;
  414. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  415. menuItem1 = menuItem.Items[1] as MenuItem;
  416. menuItem1.CommandTarget = PDFViewer;
  417. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  418. menuItem1 = menuItem.Items[2] as MenuItem;
  419. menuItem1.CommandTarget = PDFViewer;
  420. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  421. }
  422. //裁剪
  423. menuItem = popMenu.Items[2] as MenuItem;
  424. menuItem.CommandTarget = PDFViewer;
  425. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  426. //缩放至所选区域
  427. menuItem = popMenu.Items[3] as MenuItem;
  428. menuItem.CommandTarget = PDFViewer;
  429. menuItem.Visibility = Visibility.Collapsed;
  430. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  431. //打印
  432. menuItem = popMenu.Items[4] as MenuItem;
  433. menuItem.CommandTarget = PDFViewer;
  434. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  435. }
  436. }
  437. }
  438. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  439. {
  440. switch (e.Key)
  441. {
  442. case "CloseSnap":
  443. {
  444. #region to do
  445. //var item = PDFViewerTab.SelectedItem as TabItem;
  446. //if (item == null)
  447. //{
  448. // ClearSelectedToolPanel();
  449. // return;
  450. //}
  451. //Grid grid = item.Content as Grid;
  452. //if (grid == null || grid.Children.Count == 0)
  453. //{
  454. // ClearSelectedToolPanel();
  455. // return;
  456. //}
  457. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  458. //if (pdfViewer == null)
  459. //{
  460. // ClearSelectedToolPanel();
  461. // return;
  462. //}
  463. #endregion to do
  464. switch (PDFViewer.MouseMode)
  465. {
  466. case MouseModes.SelectTextTool:
  467. break;
  468. default:
  469. BtnSelecttoolIsChecked = false;
  470. BtnHandIsChecked = true;
  471. PDFViewer.EnableZoom(true);
  472. PDFViewer.EnableScroll(true);
  473. break;
  474. }
  475. }
  476. break;
  477. default:
  478. break;
  479. }
  480. }
  481. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  482. {
  483. if (e != null && e.Count > 0)
  484. {
  485. for (int i = 0; i < e.Count; i++)
  486. {
  487. AnnotEditEvent editEvent = e[i];
  488. switch (editEvent.EditAction)
  489. {
  490. case ActionType.Add:
  491. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  492. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  493. {
  494. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  495. if (viewModel != null)
  496. {
  497. int pageindex = editEvent.PageIndex;
  498. int annotindex = editEvent.AnnotIndex;
  499. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  500. }
  501. }
  502. break;
  503. case ActionType.Del:
  504. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  505. if (isTabItemAnnotation)
  506. {
  507. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  508. if (viewModel != null)
  509. {
  510. int pageindex = editEvent.PageIndex;
  511. int annotindex = editEvent.AnnotIndex;
  512. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  513. }
  514. }
  515. break;
  516. case ActionType.Modify:
  517. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  518. if (bOTAContent.TabItemAnnotation.IsSelected)
  519. {
  520. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  521. if (viewModel != null)
  522. {
  523. int pageindex = editEvent.PageIndex;
  524. int annotindex = editEvent.AnnotIndex;
  525. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  526. }
  527. }
  528. break;
  529. case ActionType.TextEdit:
  530. break;
  531. default:
  532. break;
  533. }
  534. }
  535. }
  536. }
  537. private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
  538. {
  539. }
  540. #endregion PDFViewer事件
  541. #region BindingEvent事件
  542. private void AnnotProperty_DefaultStored(object sender, object e)
  543. {
  544. }
  545. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  546. {
  547. if (e != null)
  548. {
  549. AnnotHandlerEventArgs annotArgs = null;
  550. foreach (AnnotArgsType argsType in e.Keys)
  551. {
  552. switch (argsType)
  553. {
  554. case AnnotArgsType.AnnotSquare:
  555. annotArgs = GetRect();
  556. break;
  557. case AnnotArgsType.AnnotCircle:
  558. annotArgs = GetCircle();
  559. break;
  560. case AnnotArgsType.AnnotLine:
  561. var LineTag = e[argsType] as string;
  562. annotArgs = GetArrowLine(LineTag);
  563. break;
  564. }
  565. if (annotArgs != null)
  566. {
  567. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  568. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  569. PDFViewer.SetToolParam(annotArgs);
  570. }
  571. ShowPropertyPanel();
  572. }
  573. }
  574. }
  575. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  576. {
  577. if (e != null)
  578. {
  579. foreach (AnnotArgsType argsType in e.Keys)
  580. {
  581. switch (argsType)
  582. {
  583. case AnnotArgsType.AnnotHighlight:
  584. if (e[argsType] is Color)
  585. {
  586. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  587. }
  588. if (e[argsType] is double)
  589. {
  590. HighLightOpacity = (double)e[argsType];
  591. }
  592. break;
  593. case AnnotArgsType.AnnotUnderline:
  594. if (e[argsType] is Color)
  595. {
  596. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  597. }
  598. if (e[argsType] is double)
  599. {
  600. underLineOpacity = (double)e[argsType];
  601. }
  602. break;
  603. case AnnotArgsType.AnnotSquiggly:
  604. if (e[argsType] is Color)
  605. {
  606. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  607. }
  608. if (e[argsType] is double)
  609. {
  610. SquigglyOpacity = (double)e[argsType];
  611. }
  612. break;
  613. case AnnotArgsType.AnnotStrikeout:
  614. if (e[argsType] is Color)
  615. {
  616. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  617. }
  618. if (e[argsType] is double)
  619. {
  620. StrikeoutOpacity = (double)e[argsType];
  621. }
  622. break;
  623. case AnnotArgsType.AnnotFreehand:
  624. if (e[argsType] is Color)
  625. {
  626. // FreehandPath.Fill = new SolidColorBrush((Color)e[argsType]);
  627. }
  628. if (e[argsType] is double)
  629. {
  630. // FreehandPath.Opacity = (double)e[argsType];
  631. }
  632. break;
  633. case AnnotArgsType.AnnotErase:
  634. if (e[argsType] is ToggleButton)
  635. {
  636. ToggleButton clickBtn = e[argsType] as ToggleButton;
  637. if (clickBtn.IsChecked == true)
  638. {
  639. if (clickBtn.Tag.ToString() == "PenBtn")
  640. {
  641. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  642. btn.Tag = "Freehand"; btn.IsChecked = true;
  643. BtnMyTools_Click(btn);
  644. break;
  645. }
  646. EraseArgs eraseArgs = new EraseArgs();
  647. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  648. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  649. eraseArgs.Thickness = 10;
  650. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  651. if (annotProperty != null)
  652. {
  653. eraseArgs.Thickness = annotProperty.Thickness;
  654. }
  655. PDFViewer.ClearSelectAnnots(false);
  656. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  657. PDFViewer.SetToolParam(eraseArgs);
  658. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  659. annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor;
  660. annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor;
  661. annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness;
  662. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  663. if (eraseArgs != null)
  664. eraseArgsList.Add(eraseArgs);
  665. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList, annotAttribsList);
  666. }
  667. }
  668. break;
  669. }
  670. }
  671. }
  672. }
  673. #endregion BindingEvent事件
  674. }
  675. }