AnnotToolContentViewModel.Command.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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_Master.CustomControl;
  8. using PDF_Master.EventAggregators;
  9. using PDF_Master.Helper;
  10. using PDF_Master.Properties;
  11. using PDF_Master.ViewModels.BOTA;
  12. using PDF_Master.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. using PDF_Master.Model.AnnotPanel;
  27. using System.Windows.Input;
  28. using PDF_Master.ViewModels.Tools.AnnotManager;
  29. using ComPDFKit.Import;
  30. using System.Windows.Markup;
  31. namespace PDF_Master.ViewModels.Tools
  32. {
  33. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  34. {
  35. #region 事件绑定和解绑
  36. private void BindingEvent()
  37. {
  38. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  39. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  40. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  41. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  42. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  43. propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  44. //快捷键
  45. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  46. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  47. }
  48. private void UnBindingEvent()
  49. {
  50. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  51. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  52. //快捷盘解绑
  53. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  54. }
  55. private void BindingPDFViewerHandler()
  56. {
  57. //来自PDFViewer的响应事件
  58. if (PDFViewer != null)
  59. {
  60. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  61. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  62. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  63. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  64. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  65. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  66. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  67. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  68. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  69. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  70. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  71. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  72. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  73. PDFViewer.PreviewMouseLeftButtonDown += PDFViewer_PreviewMouseLeftButtonDown;
  74. }
  75. }
  76. private void UnBindingPDFViewerHandler()
  77. {
  78. if (PDFViewer != null)
  79. {
  80. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  81. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  82. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  83. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  84. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  85. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  86. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  87. }
  88. }
  89. #endregion 事件绑定和解绑
  90. #region 与触发事件调用相关的函数
  91. //鼠标左键双击注释
  92. private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  93. {
  94. if (e.ClickCount == 1)
  95. {
  96. //if (sender is CPDFViewer pDFViewer)
  97. //{
  98. // if (pDFViewer.ToolManager.CurrentAnnotArgs != null)
  99. // {
  100. // if (pDFViewer.ToolManager.CurrentAnnotArgs is FreehandAnnotArgs freehand)
  101. // {
  102. // PDFViewer.SelectAnnotation(freehand.PageIndex, freehand.AnnotIndex);
  103. // }
  104. // }
  105. //}
  106. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemBookMark");
  107. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemBookMark.IsSelected == true)
  108. {
  109. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  110. }
  111. }
  112. if (e.ClickCount == 2)
  113. {
  114. if (CurrentSelectedAnnot != null)
  115. {
  116. var type = CurrentSelectedAnnot.EventType;
  117. if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
  118. type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline && type != AnnotArgsType.AnnotStrikeout)
  119. {
  120. int dpi = DpiHelpers.Dpi;
  121. var rect = CurrentSelectedAnnot.ClientRect;
  122. rect = new Rect(
  123. rect.Left * PDFViewer.ZoomFactor,
  124. rect.Top * PDFViewer.ZoomFactor,
  125. rect.Width * PDFViewer.ZoomFactor,
  126. rect.Height * PDFViewer.ZoomFactor);
  127. var ui = PDFViewer.Parent as ContentControl;
  128. if (ui != null)
  129. {
  130. var point = e.GetPosition(ui);
  131. int pageIndex = 0;
  132. Point pagePoint = new Point(0, 0);
  133. //Todo:等黎总需要更新ComPDFKit.dll
  134. //PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
  135. if (pagePoint.X >= rect.Left && pagePoint.X <= rect.Right && pagePoint.Y >= rect.Top && pagePoint.Y <= rect.Bottom)
  136. PopAnnotNoteText(CurrentSelectedAnnot);
  137. }
  138. }
  139. if (type == AnnotArgsType.AnnotSticky)
  140. {
  141. (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
  142. }
  143. }
  144. }
  145. }
  146. //超链接跳转
  147. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  148. {
  149. if (action == null)
  150. {
  151. return;
  152. }
  153. switch (action.ActionType)
  154. {
  155. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  156. if (PDFViewer != null)
  157. {
  158. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  159. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  160. if (dest != null)
  161. {
  162. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  163. }
  164. }
  165. break;
  166. case C_ACTION_TYPE.ACTION_TYPE_URI:
  167. {
  168. CPDFUriAction uriAction = action as CPDFUriAction;
  169. string uri = uriAction.GetUri();
  170. try
  171. {
  172. if (!string.IsNullOrEmpty(uri))
  173. {
  174. Process.Start(uri);
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. }
  180. }
  181. break;
  182. }
  183. }
  184. private void GetSelectedAnnots(AnnotAttribEvent e)
  185. {
  186. var annot = e.AnnotItemsList[0];
  187. switch (annot.EventType)
  188. {
  189. case AnnotArgsType.AnnotHighlight:
  190. GetHighLight(e.AnnotItemsList);
  191. break;
  192. case AnnotArgsType.AnnotUnderline:
  193. GetUnderLine(e.AnnotItemsList);
  194. break;
  195. case AnnotArgsType.AnnotStrikeout:
  196. GetStrikeout(e.AnnotItemsList);
  197. break;
  198. case AnnotArgsType.AnnotSquiggly:
  199. GetSquiggly(e.AnnotItemsList);
  200. break;
  201. case AnnotArgsType.AnnotFreehand:
  202. GetFreehand(e.AnnotItemsList);
  203. break;
  204. case AnnotArgsType.AnnotFreeText:
  205. GetFreetext(e.AnnotItemsList);
  206. break;
  207. case AnnotArgsType.AnnotSquare:
  208. GetRect(e.AnnotItemsList);
  209. break;
  210. case AnnotArgsType.AnnotCircle:
  211. GetCircle(e.AnnotItemsList);
  212. break;
  213. case AnnotArgsType.AnnotLine:
  214. bool isLine = true;
  215. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  216. {
  217. 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)
  218. {
  219. isLine = false;
  220. }
  221. }
  222. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  223. {
  224. 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)
  225. {
  226. isLine = false;
  227. }
  228. }
  229. if (isLine)
  230. GetArrowLine("Line", e.AnnotItemsList);
  231. else
  232. GetArrowLine("Arrow", e.AnnotItemsList);
  233. break;
  234. case AnnotArgsType.AnnotLink:
  235. //viewContentViewModel.IsCreateLink = false;
  236. //e.IsAnnotCreateReset= true;
  237. if (BtnLinkIsChecked == false)
  238. {
  239. propertyPanel.IsAddLink = false;
  240. }
  241. GetLink(e.AnnotItemsList, e);
  242. break;
  243. case AnnotArgsType.AnnotSticky:
  244. GetStickyNote(e.AnnotItemsList);
  245. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  246. customStickyPopup.GetPDFViewer = PDFViewer;
  247. break;
  248. case AnnotArgsType.AnnotStamp:
  249. GetStamp();
  250. break;
  251. }
  252. }
  253. private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
  254. {
  255. if (annotlist == null || annotlist.Count == 0)
  256. return;
  257. var annot = annotlist[0];
  258. if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
  259. return;
  260. if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
  261. return;
  262. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  263. if (signAnnot == null)
  264. {
  265. if (annot.EventType == AnnotArgsType.AnnotStamp)
  266. {
  267. StrAnnotToolChecked = "Stamp";
  268. }
  269. //else
  270. //{
  271. // StrAnnotToolChecked = "";
  272. //}
  273. }
  274. else
  275. {
  276. GetSignature();
  277. StrAnnotToolChecked = "Signature";
  278. }
  279. }
  280. private void AddAnnotSignature(AnnotHandlerEventArgs annot)
  281. {
  282. if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
  283. (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
  284. if (StrAnnotToolChecked == "Signature")
  285. {
  286. if (viewContentViewModel.AnnotSignatures == null)
  287. viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
  288. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  289. if (signAnnot == null)
  290. {
  291. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
  292. }
  293. }
  294. }
  295. #endregion 与触发事件调用相关的函数
  296. #region PDFViewer事件
  297. private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
  298. //选中和非选中注释
  299. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  300. {
  301. if (e != null)
  302. {
  303. CurrentSelectedAnnot = null;
  304. var annot = e.AnnotItemsList[0];
  305. if (annot != null)
  306. {
  307. if (e.AnnotItemsList.Count == 1)
  308. {
  309. //IsAnnotCreateReset:是否为创建注释的状态
  310. if (e.IsAnnotCreateReset == false)
  311. {
  312. GetSelectedAnnots(e);
  313. SelectedSignature(e.AnnotItemsList);
  314. CurrentSelectedAnnot = annot;
  315. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
  316. ShowPropertyPanel(true);
  317. }
  318. else
  319. {
  320. switch (annot.EventType)
  321. {
  322. case AnnotArgsType.AnnotFreeText:
  323. GetFreetext(e.AnnotItemsList);
  324. PDFViewer.SetToolParam(annot);
  325. break;
  326. case AnnotArgsType.AnnotSticky:
  327. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  328. customStickyPopup.GetPDFViewer = PDFViewer;
  329. break;
  330. case AnnotArgsType.AnnotLink:
  331. //viewContentViewModel.IsCreateLink = false;
  332. GetLink(e.AnnotItemsList, e);
  333. PDFViewer.SetToolParam(annot);
  334. break;
  335. }
  336. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  337. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  338. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  339. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  340. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  341. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  342. //annot.EventType != AnnotArgsType.AnnotLink &&
  343. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  344. //annot.EventType != AnnotArgsType.AnnotSticky &&
  345. //)
  346. //{
  347. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  348. // {
  349. // var strLineAnnotTag = "";
  350. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  351. // {
  352. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  353. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  354. // {
  355. // strLineAnnotTag = "Line";
  356. // }
  357. // else
  358. // {
  359. // strLineAnnotTag = "Arrow";
  360. // }
  361. // }
  362. // foreach (var item in ToolExpandDict)
  363. // {
  364. // if (item.Value == e.AnnotItemsList[0].EventType)
  365. // {
  366. // annot = null;//新建注释时,回到默认值
  367. // if (string.IsNullOrEmpty(strLineAnnotTag))
  368. // {
  369. // FindAnnotTypeKey(item.Key, ref annot);
  370. // break;
  371. // }
  372. // else
  373. // {
  374. // if (strLineAnnotTag == item.Key)
  375. // {
  376. // FindAnnotTypeKey(item.Key, ref annot);
  377. // break;
  378. // }
  379. // }
  380. // }
  381. // }
  382. // PDFViewer.SetToolParam(annot);
  383. // }
  384. //}
  385. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  386. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  387. //{
  388. // ShowPropertyPanel(false);
  389. //}
  390. //else
  391. //{
  392. // ShowPropertyPanel();
  393. //}
  394. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  395. }
  396. }
  397. else
  398. {
  399. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  400. if (isDifferentAnnotTyle)
  401. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  402. else
  403. GetSelectedAnnots(e);
  404. }
  405. }
  406. //注释列表同步选中
  407. var list = e.GetPageAnnotsIndex();
  408. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  409. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  410. {
  411. if (list.Keys.Count == 0)
  412. {
  413. return;
  414. }
  415. var pageindex = new List<int>(list.Keys);
  416. List<int> annotes = new List<int>();
  417. list.TryGetValue(pageindex[0], out annotes);
  418. int annoteindex = annotes[0];
  419. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  420. if (viewModel != null)
  421. {
  422. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  423. }
  424. }
  425. }
  426. else
  427. {
  428. if (BtnLinkIsChecked == false)
  429. {
  430. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  431. {
  432. if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  433. {
  434. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  435. }
  436. }
  437. else
  438. {
  439. if (propertyPanel.IsMultiSelected)
  440. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  441. }
  442. }
  443. }
  444. }
  445. //在注释工具的状态下,右键菜单
  446. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  447. {
  448. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  449. return;
  450. if ((UIElement)sender != null)
  451. {
  452. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  453. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  454. }
  455. switch (e.CommandType)
  456. {
  457. case CommandType.Context:
  458. if (e.AnnotEventArgsList.Count > 0)
  459. {
  460. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  461. {
  462. //绑定标记密文处右键菜单
  463. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  464. }
  465. else
  466. {
  467. if (e.AnnotEventArgsList.Count == 1)
  468. {
  469. var selectedAnnot = e.AnnotEventArgsList[0];
  470. PopMenuCheckedLineDash(selectedAnnot);
  471. PopMenuCheckedFontFamily(selectedAnnot);
  472. PopMenuCheckedTextAglin(selectedAnnot);
  473. switch (selectedAnnot.EventType)
  474. {
  475. case AnnotArgsType.AnnotHighlight:
  476. case AnnotArgsType.AnnotUnderline:
  477. case AnnotArgsType.AnnotStrikeout:
  478. case AnnotArgsType.AnnotSquiggly:
  479. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  480. {
  481. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  482. }
  483. else
  484. {
  485. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  486. }
  487. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  488. break;
  489. case AnnotArgsType.AnnotFreehand:
  490. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  491. break;
  492. case AnnotArgsType.AnnotFreeText:
  493. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  494. break;
  495. case AnnotArgsType.AnnotSticky:
  496. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  497. break;
  498. case AnnotArgsType.AnnotSquare:
  499. case AnnotArgsType.AnnotCircle:
  500. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  501. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  502. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  503. break;
  504. case AnnotArgsType.AnnotLine:
  505. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  506. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  507. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  508. break;
  509. case AnnotArgsType.AnnotLink:
  510. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  511. break;
  512. case AnnotArgsType.AnnotStamp:
  513. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  514. break;
  515. }
  516. }
  517. else
  518. {
  519. bool isHigh = true;//是否为高亮
  520. foreach (var item in e.AnnotEventArgsList)
  521. {
  522. if (AnnotTransfer.IsHightAnnot(item) == false)
  523. {
  524. isHigh = false;
  525. break;
  526. }
  527. }
  528. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  529. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  530. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  531. }
  532. }
  533. if (e.PopupMenu != null)
  534. {
  535. e.Handle = true;
  536. }
  537. }
  538. else
  539. {
  540. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  541. {
  542. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  543. if (e.PopupMenu != null)
  544. {
  545. e.Handle = true;
  546. }
  547. }
  548. else
  549. {
  550. e.PopupMenu = ViewerContextMenu(sender);
  551. if (e.PopupMenu != null)
  552. {
  553. e.Handle = true;
  554. }
  555. }
  556. }
  557. break;
  558. }
  559. }
  560. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  561. {
  562. if (e.Command == ApplicationCommands.Copy)
  563. {
  564. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsPrinting, dialogs);
  565. if (result.IsDiscryptied)
  566. {
  567. if (result.Password != null)
  568. {
  569. string filePath = PDFViewer.Document.FilePath;
  570. var unlockresult = PDFViewer.Document.UnlockWithPassword(result.Password);
  571. }
  572. }
  573. else
  574. {
  575. e.Handled = true;
  576. }
  577. }
  578. }
  579. //右键菜单,选中字体样式按钮状态
  580. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  581. {
  582. if (annot != null)
  583. {
  584. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  585. {
  586. var freeText = annot as FreeTextAnnotArgs;
  587. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  588. }
  589. }
  590. }
  591. //右键菜单,选中文本内容对齐按钮状态
  592. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  593. {
  594. if (annot != null)
  595. {
  596. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  597. {
  598. var freeText = annot as FreeTextAnnotArgs;
  599. switch (freeText.Align)
  600. {
  601. case TextAlignment.Left:
  602. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  603. break;
  604. case TextAlignment.Center:
  605. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  606. break;
  607. case TextAlignment.Right:
  608. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  609. break;
  610. case TextAlignment.Justify:
  611. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  612. break;
  613. default:
  614. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  615. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  616. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  617. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  618. break;
  619. }
  620. }
  621. }
  622. }
  623. //右键菜单,选中虚实线按钮状态
  624. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  625. {
  626. if (annot != null)
  627. {
  628. bool isSolidLineDash = true;
  629. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  630. {
  631. var freeHand = annot as FreehandAnnotArgs;
  632. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  633. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  634. }
  635. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  636. {
  637. var square = annot as SquareAnnotArgs;
  638. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  639. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  640. }
  641. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  642. {
  643. var circle = annot as CircleAnnotArgs;
  644. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  645. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  646. }
  647. else if (annot.EventType == AnnotArgsType.AnnotLine)
  648. {
  649. var line = annot as LineAnnotArgs;
  650. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  651. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  652. }
  653. }
  654. }
  655. /// <summary>
  656. /// 内容选择工具
  657. /// </summary>
  658. /// <param name="sender"></param>
  659. /// <param name="e"></param>
  660. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  661. {
  662. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  663. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  664. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  665. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  666. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  667. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  668. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  669. {
  670. e.PopupMenu = popMenu;
  671. e.Handle = true;
  672. if (popMenu != null && popMenu.Items.Count == 5)
  673. {
  674. //复制
  675. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  676. menuItem.CommandTarget = PDFViewer;
  677. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  678. //导出
  679. menuItem = popMenu.Items[1] as MenuItem;
  680. menuItem.CommandTarget = PDFViewer;
  681. if (menuItem.Items.Count == 3)
  682. {
  683. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  684. menuItem1.CommandTarget = PDFViewer;
  685. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  686. menuItem1 = menuItem.Items[1] as MenuItem;
  687. menuItem1.CommandTarget = PDFViewer;
  688. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  689. menuItem1 = menuItem.Items[2] as MenuItem;
  690. menuItem1.CommandTarget = PDFViewer;
  691. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  692. }
  693. //裁剪
  694. menuItem = popMenu.Items[2] as MenuItem;
  695. menuItem.CommandTarget = PDFViewer;
  696. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  697. //缩放至所选区域
  698. menuItem = popMenu.Items[3] as MenuItem;
  699. menuItem.CommandTarget = PDFViewer;
  700. menuItem.Visibility = Visibility.Collapsed;
  701. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  702. //打印
  703. menuItem = popMenu.Items[4] as MenuItem;
  704. menuItem.CommandTarget = PDFViewer;
  705. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  706. }
  707. }
  708. }
  709. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  710. {
  711. switch (e.Key)
  712. {
  713. case "CloseSnap":
  714. {
  715. #region to do
  716. //var item = PDFViewerTab.SelectedItem as TabItem;
  717. //if (item == null)
  718. //{
  719. // ClearSelectedToolPanel();
  720. // return;
  721. //}
  722. //Grid grid = item.Content as Grid;
  723. //if (grid == null || grid.Children.Count == 0)
  724. //{
  725. // ClearSelectedToolPanel();
  726. // return;
  727. //}
  728. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  729. //if (pdfViewer == null)
  730. //{
  731. // ClearSelectedToolPanel();
  732. // return;
  733. //}
  734. #endregion to do
  735. switch (PDFViewer.MouseMode)
  736. {
  737. case MouseModes.SelectTextTool:
  738. break;
  739. default:
  740. BtnSelecttoolIsChecked = false;
  741. BtnHandIsChecked = true;
  742. PDFViewer.EnableZoom(true);
  743. PDFViewer.EnableScroll(true);
  744. break;
  745. }
  746. }
  747. break;
  748. default:
  749. break;
  750. }
  751. }
  752. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  753. {
  754. if (e != null && e.Count > 0)
  755. {
  756. MultipleSelectionAnnot(e);
  757. for (int i = 0; i < e.Count; i++)
  758. {
  759. AnnotEditEvent editEvent = e[i];
  760. switch (editEvent.EditAction)
  761. {
  762. case ActionType.Add:
  763. //BOTA
  764. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  765. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  766. {
  767. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  768. if (viewModel != null)
  769. {
  770. int pageindex = editEvent.PageIndex;
  771. int annotindex = editEvent.AnnotIndex;
  772. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  773. }
  774. }
  775. //添加书签注释,用于未保存前跟图章手绘注释的区分
  776. if (StrAnnotToolChecked == "Signature")
  777. {
  778. AddAnnotSignature(editEvent.EditAnnotArgs);
  779. }
  780. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  781. {
  782. (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  783. }
  784. break;
  785. case ActionType.Del:
  786. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  787. if (isTabItemAnnotation)
  788. {
  789. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  790. if (viewModel != null)
  791. {
  792. int pageindex = editEvent.PageIndex;
  793. int annotindex = editEvent.AnnotIndex;
  794. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  795. }
  796. }
  797. break;
  798. case ActionType.Modify:
  799. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  800. if (bOTAContent.TabItemAnnotation.IsSelected)
  801. {
  802. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  803. if (viewModel != null)
  804. {
  805. int pageindex = editEvent.PageIndex;
  806. int annotindex = editEvent.AnnotIndex;
  807. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  808. }
  809. }
  810. break;
  811. case ActionType.TextEdit:
  812. break;
  813. default:
  814. break;
  815. }
  816. }
  817. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  818. if (IsNoSelectMenu)
  819. {
  820. IsNoSelectMenu = false;
  821. PDFViewer.SetMouseMode(MouseModes.PanTool);
  822. }
  823. }
  824. }
  825. //复制多个注释,粘贴后,默认注释未选中状态
  826. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  827. {
  828. bool isAdd = false;
  829. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  830. foreach (var item in e)
  831. {
  832. if (item.EditAction == ActionType.Add /*|| item.EditAction == ActionType.Modify*/)
  833. {
  834. var annot = item.EditAnnotArgs;
  835. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  836. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
  837. {
  838. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  839. {
  840. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  841. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  842. }
  843. else
  844. {
  845. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  846. }
  847. isAdd = true;
  848. }
  849. }
  850. }
  851. if (isAdd)
  852. {
  853. PDFViewer.ClearSelectAnnots();
  854. PDFViewer.SelectAnnotation(selectAnnotDicts);
  855. }
  856. }
  857. //阅读页悬浮相应
  858. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  859. {
  860. if (e != null && e.DrawContext != null)
  861. {
  862. Rect hoverRect = new Rect(
  863. e.PaintRect.Left - 2,
  864. e.PaintRect.Top - 2,
  865. e.PaintRect.Width + 4,
  866. e.PaintRect.Height + 4);
  867. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  868. hoverPen.DashStyle = DashStyles.Dash;
  869. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  870. //便签,显示ToolTip内容
  871. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  872. {
  873. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  874. return;
  875. }
  876. }
  877. CloseAnnotToolTip();
  878. }
  879. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  880. {
  881. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  882. {
  883. //鼠标移到注释之外,关闭ToolTip浮窗
  884. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  885. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  886. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  887. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  888. {
  889. CloseAnnotToolTip();
  890. }
  891. }
  892. }
  893. private Rect oldRect = new Rect(0, 0, 0, 0);
  894. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  895. {
  896. //便签,显示ToolTip内容
  897. if (PDFViewer.ToolTip == null)
  898. {
  899. if (string.IsNullOrEmpty(content) == false)
  900. {
  901. ToolTip TipChild = new ToolTip();
  902. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  903. TipChild.MaxWidth = 246;
  904. TipChild.Content = content;
  905. TipChild.Visibility = Visibility.Visible;
  906. TipChild.IsOpen = true;
  907. TipChild.Placement = PlacementMode.Right;
  908. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  909. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  910. TipChild.Placement = PlacementMode.MousePoint;
  911. PDFViewer.ToolTip = TipChild;
  912. oldRect = hoverRect;
  913. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  914. PDFViewer.MouseMove += PDFViewer_MouseMove;
  915. }
  916. }
  917. }
  918. //关闭ToolTip
  919. private void CloseAnnotToolTip()
  920. {
  921. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  922. {
  923. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  924. oldTips.IsOpen = false;
  925. oldTips.Visibility = Visibility.Collapsed;
  926. PDFViewer.ToolTip = null;
  927. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  928. oldRect = new Rect(0, 0, 0, 0);
  929. }
  930. }
  931. #endregion PDFViewer事件
  932. #region BindingEvent事件
  933. //同一属性面板,不同的注释类型
  934. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  935. {
  936. if (e != null)
  937. {
  938. AnnotHandlerEventArgs annotArgs = null;
  939. propertyPanel.SaveLastAnnot();
  940. foreach (AnnotArgsType argsType in e.Keys)
  941. {
  942. if (propertyPanel.annot.EventType != argsType)
  943. {
  944. PDFViewer.SetMouseMode(MouseModes.PanTool);
  945. }
  946. switch (argsType)
  947. {
  948. case AnnotArgsType.AnnotSquare:
  949. annotArgs = GetRect();
  950. break;
  951. case AnnotArgsType.AnnotCircle:
  952. annotArgs = GetCircle();
  953. break;
  954. case AnnotArgsType.AnnotLine:
  955. var LineTag = e[argsType] as string;
  956. annotArgs = GetArrowLine(LineTag);
  957. break;
  958. }
  959. ShowPropertyPanel();
  960. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  961. {
  962. PDFViewer.SetMouseMode(MouseModes.PanTool);
  963. return;
  964. }
  965. if (annotArgs != null)
  966. {
  967. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  968. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  969. PDFViewer.SetToolParam(annotArgs);
  970. }
  971. }
  972. }
  973. }
  974. //来自属性面板的事件,更改颜色等属性而触发
  975. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  976. {
  977. if (e != null)
  978. {
  979. foreach (AnnotArgsType argsType in e.Keys)
  980. {
  981. switch (argsType)
  982. {
  983. case AnnotArgsType.AnnotHighlight:
  984. if (e[argsType] is Color)
  985. {
  986. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  987. }
  988. if (e[argsType] is double)
  989. {
  990. HighLightOpacity = (double)e[argsType];
  991. }
  992. //创建注释后,修改注释属性,可用于下次创建的注释
  993. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  994. {
  995. PDFViewer.SetToolParam(propertyPanel.annot);
  996. }
  997. break;
  998. case AnnotArgsType.AnnotUnderline:
  999. if (e[argsType] is Color)
  1000. {
  1001. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1002. }
  1003. if (e[argsType] is double)
  1004. {
  1005. underLineOpacity = (double)e[argsType];
  1006. }
  1007. //创建注释后,修改注释属性,可用于下次创建的注释
  1008. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1009. {
  1010. PDFViewer.SetToolParam(propertyPanel.annot);
  1011. }
  1012. break;
  1013. case AnnotArgsType.AnnotSquiggly:
  1014. if (e[argsType] is Color)
  1015. {
  1016. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1017. }
  1018. if (e[argsType] is double)
  1019. {
  1020. SquigglyOpacity = (double)e[argsType];
  1021. }
  1022. //创建注释后,修改注释属性,可用于下次创建的注释
  1023. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1024. {
  1025. PDFViewer.SetToolParam(propertyPanel.annot);
  1026. }
  1027. break;
  1028. case AnnotArgsType.AnnotStrikeout:
  1029. if (e[argsType] is Color)
  1030. {
  1031. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1032. }
  1033. if (e[argsType] is double)
  1034. {
  1035. StrikeoutOpacity = (double)e[argsType];
  1036. }
  1037. //创建注释后,修改注释属性,可用于下次创建的注释
  1038. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1039. {
  1040. PDFViewer.SetToolParam(propertyPanel.annot);
  1041. }
  1042. break;
  1043. case AnnotArgsType.AnnotFreehand:
  1044. if (e[argsType] is FreehandAnnotArgs)
  1045. {
  1046. var annot = e[argsType] as FreehandAnnotArgs;
  1047. if (annot != null)
  1048. {
  1049. if (propertyPanel != null)
  1050. {
  1051. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1052. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1053. propertyPanel.AnnotEvent = AnnotEvent;
  1054. var AnnotEvents = new List<AnnotAttribEvent>();
  1055. AnnotEvents.Add(AnnotEvent);
  1056. propertyPanel.AnnotEvents = AnnotEvents;
  1057. propertyPanel.annot = annot;
  1058. //手绘注释工具按钮的属性
  1059. // FreehandPath.Opacity = annot.Transparency;
  1060. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1061. }
  1062. PDFViewer.SetToolParam(annot);
  1063. }
  1064. }
  1065. break;
  1066. case AnnotArgsType.AnnotErase:
  1067. if (e[argsType] is ToggleButton)
  1068. {
  1069. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1070. if (clickBtn.IsChecked == true)
  1071. {
  1072. if (clickBtn.Tag.ToString() == "PenBtn")
  1073. {
  1074. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1075. btn.Tag = "Freehand"; btn.IsChecked = true;
  1076. BtnMyTools_Click(btn);
  1077. break;
  1078. }
  1079. CreateEraseArgs();
  1080. }
  1081. }
  1082. break;
  1083. case AnnotArgsType.AnnotSquare:
  1084. case AnnotArgsType.AnnotCircle:
  1085. case AnnotArgsType.AnnotLine:
  1086. case AnnotArgsType.AnnotFreeText:
  1087. //创建注释后,修改注释属性,可用于下次创建的注释
  1088. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1089. {
  1090. PDFViewer.SetToolParam(propertyPanel.annot);
  1091. }
  1092. break;
  1093. }
  1094. }
  1095. }
  1096. }
  1097. private void CreateEraseArgs()
  1098. {
  1099. EraseArgs eraseArgs = new EraseArgs();
  1100. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1101. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1102. eraseArgs.Thickness = 10;
  1103. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1104. if (annotProperty != null)
  1105. {
  1106. eraseArgs.Thickness = annotProperty.Thickness;
  1107. }
  1108. PDFViewer.ClearSelectAnnots(false);
  1109. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1110. PDFViewer.SetToolParam(eraseArgs);
  1111. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1112. if (eraseArgs != null)
  1113. eraseArgsList.Add(eraseArgs);
  1114. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1115. }
  1116. #endregion BindingEvent事件
  1117. }
  1118. }