AnnotToolContentViewModel.Command.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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. if (e.IsMouseRightActive)
  304. {
  305. ShowPropertyPanel(false);
  306. return;
  307. }
  308. CurrentSelectedAnnot = null;
  309. var annot = e.AnnotItemsList[0];
  310. if (annot != null)
  311. {
  312. if (e.AnnotItemsList.Count == 1)
  313. {
  314. //IsAnnotCreateReset:是否为创建注释的状态
  315. if (e.IsAnnotCreateReset == false)
  316. {
  317. GetSelectedAnnots(e);
  318. SelectedSignature(e.AnnotItemsList);
  319. CurrentSelectedAnnot = annot;
  320. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty
  321. && annot.EventType != AnnotArgsType.AnnotStamp && StrAnnotToolChecked != "Signature"
  322. && annot.EventType != AnnotArgsType.AnnotLink)
  323. ShowPropertyPanel(true);
  324. }
  325. else
  326. {
  327. switch (annot.EventType)
  328. {
  329. case AnnotArgsType.AnnotFreeText:
  330. GetFreetext(e.AnnotItemsList);
  331. PDFViewer.SetToolParam(annot);
  332. break;
  333. case AnnotArgsType.AnnotSticky:
  334. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  335. customStickyPopup.GetPDFViewer = PDFViewer;
  336. break;
  337. case AnnotArgsType.AnnotLink:
  338. //viewContentViewModel.IsCreateLink = false;
  339. GetLink(e.AnnotItemsList, e);
  340. PDFViewer.SetToolParam(annot);
  341. break;
  342. }
  343. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  344. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  345. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  346. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  347. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  348. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  349. //annot.EventType != AnnotArgsType.AnnotLink &&
  350. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  351. //annot.EventType != AnnotArgsType.AnnotSticky &&
  352. //)
  353. //{
  354. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  355. // {
  356. // var strLineAnnotTag = "";
  357. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  358. // {
  359. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  360. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  361. // {
  362. // strLineAnnotTag = "Line";
  363. // }
  364. // else
  365. // {
  366. // strLineAnnotTag = "Arrow";
  367. // }
  368. // }
  369. // foreach (var item in ToolExpandDict)
  370. // {
  371. // if (item.Value == e.AnnotItemsList[0].EventType)
  372. // {
  373. // annot = null;//新建注释时,回到默认值
  374. // if (string.IsNullOrEmpty(strLineAnnotTag))
  375. // {
  376. // FindAnnotTypeKey(item.Key, ref annot);
  377. // break;
  378. // }
  379. // else
  380. // {
  381. // if (strLineAnnotTag == item.Key)
  382. // {
  383. // FindAnnotTypeKey(item.Key, ref annot);
  384. // break;
  385. // }
  386. // }
  387. // }
  388. // }
  389. // PDFViewer.SetToolParam(annot);
  390. // }
  391. //}
  392. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  393. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  394. //{
  395. // ShowPropertyPanel(false);
  396. //}
  397. //else
  398. //{
  399. // ShowPropertyPanel();
  400. //}
  401. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  402. }
  403. }
  404. else
  405. {
  406. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  407. if (isDifferentAnnotTyle)
  408. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  409. else
  410. GetSelectedAnnots(e);
  411. }
  412. }
  413. //注释列表同步选中
  414. var list = e.GetPageAnnotsIndex();
  415. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  416. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  417. {
  418. if (list.Keys.Count == 0)
  419. {
  420. return;
  421. }
  422. var pageindex = new List<int>(list.Keys);
  423. List<int> annotes = new List<int>();
  424. list.TryGetValue(pageindex[0], out annotes);
  425. int annoteindex = annotes[0];
  426. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  427. if (viewModel != null)
  428. {
  429. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  430. }
  431. }
  432. }
  433. else
  434. {
  435. if (BtnLinkIsChecked == false)
  436. {
  437. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  438. {
  439. if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  440. {
  441. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  442. }
  443. }
  444. else
  445. {
  446. if (propertyPanel.IsMultiSelected)
  447. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  448. }
  449. }
  450. }
  451. }
  452. //在注释工具的状态下,右键菜单
  453. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  454. {
  455. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  456. return;
  457. if ((UIElement)sender != null)
  458. {
  459. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  460. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  461. }
  462. switch (e.CommandType)
  463. {
  464. case CommandType.Context:
  465. if (e.AnnotEventArgsList.Count > 0)
  466. {
  467. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  468. {
  469. //绑定标记密文处右键菜单
  470. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  471. }
  472. else
  473. {
  474. if (e.AnnotEventArgsList.Count == 1)
  475. {
  476. var selectedAnnot = e.AnnotEventArgsList[0];
  477. PopMenuCheckedLineDash(selectedAnnot);
  478. PopMenuCheckedFontFamily(selectedAnnot);
  479. PopMenuCheckedTextAglin(selectedAnnot);
  480. switch (selectedAnnot.EventType)
  481. {
  482. case AnnotArgsType.AnnotHighlight:
  483. case AnnotArgsType.AnnotUnderline:
  484. case AnnotArgsType.AnnotStrikeout:
  485. case AnnotArgsType.AnnotSquiggly:
  486. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  487. {
  488. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  489. }
  490. else
  491. {
  492. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  493. }
  494. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  495. break;
  496. case AnnotArgsType.AnnotFreehand:
  497. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  498. break;
  499. case AnnotArgsType.AnnotFreeText:
  500. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  501. break;
  502. case AnnotArgsType.AnnotSticky:
  503. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  504. break;
  505. case AnnotArgsType.AnnotSquare:
  506. case AnnotArgsType.AnnotCircle:
  507. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  508. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  509. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  510. break;
  511. case AnnotArgsType.AnnotLine:
  512. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  513. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  514. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  515. break;
  516. case AnnotArgsType.AnnotLink:
  517. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  518. break;
  519. case AnnotArgsType.AnnotStamp:
  520. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  521. break;
  522. }
  523. }
  524. else
  525. {
  526. bool isHigh = true;//是否为高亮
  527. foreach (var item in e.AnnotEventArgsList)
  528. {
  529. if (AnnotTransfer.IsHightAnnot(item) == false)
  530. {
  531. isHigh = false;
  532. break;
  533. }
  534. }
  535. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  536. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  537. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  538. }
  539. }
  540. if (e.PopupMenu != null)
  541. {
  542. e.Handle = true;
  543. }
  544. }
  545. else
  546. {
  547. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  548. {
  549. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  550. if (e.PopupMenu != null)
  551. {
  552. e.Handle = true;
  553. }
  554. }
  555. else
  556. {
  557. e.PopupMenu = ViewerContextMenu(sender);
  558. if (e.PopupMenu != null)
  559. {
  560. e.Handle = true;
  561. }
  562. }
  563. }
  564. break;
  565. }
  566. }
  567. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  568. {
  569. if (e.Command == ApplicationCommands.Copy)
  570. {
  571. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
  572. if (result.IsDiscryptied)
  573. {
  574. if (result.Password != null)
  575. {
  576. string filePath = PDFViewer.Document.FilePath;
  577. var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
  578. }
  579. }
  580. else
  581. {
  582. e.Handled = true;
  583. }
  584. }
  585. }
  586. //右键菜单,选中字体样式按钮状态
  587. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  588. {
  589. if (annot != null)
  590. {
  591. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  592. {
  593. var freeText = annot as FreeTextAnnotArgs;
  594. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  595. }
  596. }
  597. }
  598. //右键菜单,选中文本内容对齐按钮状态
  599. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  600. {
  601. if (annot != null)
  602. {
  603. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  604. {
  605. var freeText = annot as FreeTextAnnotArgs;
  606. switch (freeText.Align)
  607. {
  608. case TextAlignment.Left:
  609. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  610. break;
  611. case TextAlignment.Center:
  612. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  613. break;
  614. case TextAlignment.Right:
  615. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  616. break;
  617. case TextAlignment.Justify:
  618. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  619. break;
  620. default:
  621. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  622. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  623. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  624. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  625. break;
  626. }
  627. }
  628. }
  629. }
  630. //右键菜单,选中虚实线按钮状态
  631. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  632. {
  633. if (annot != null)
  634. {
  635. bool isSolidLineDash = true;
  636. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  637. {
  638. var freeHand = annot as FreehandAnnotArgs;
  639. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  640. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  641. }
  642. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  643. {
  644. var square = annot as SquareAnnotArgs;
  645. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  646. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  647. }
  648. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  649. {
  650. var circle = annot as CircleAnnotArgs;
  651. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  652. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  653. }
  654. else if (annot.EventType == AnnotArgsType.AnnotLine)
  655. {
  656. var line = annot as LineAnnotArgs;
  657. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  658. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  659. }
  660. }
  661. }
  662. /// <summary>
  663. /// 内容选择工具
  664. /// </summary>
  665. /// <param name="sender"></param>
  666. /// <param name="e"></param>
  667. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  668. {
  669. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  670. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  671. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  672. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  673. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  674. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  675. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  676. {
  677. e.PopupMenu = popMenu;
  678. e.Handle = true;
  679. if (popMenu != null && popMenu.Items.Count == 5)
  680. {
  681. //复制
  682. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  683. menuItem.CommandTarget = PDFViewer;
  684. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  685. //导出
  686. menuItem = popMenu.Items[1] as MenuItem;
  687. menuItem.CommandTarget = PDFViewer;
  688. if (menuItem.Items.Count == 3)
  689. {
  690. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  691. menuItem1.CommandTarget = PDFViewer;
  692. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  693. menuItem1 = menuItem.Items[1] as MenuItem;
  694. menuItem1.CommandTarget = PDFViewer;
  695. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  696. menuItem1 = menuItem.Items[2] as MenuItem;
  697. menuItem1.CommandTarget = PDFViewer;
  698. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  699. }
  700. //裁剪
  701. menuItem = popMenu.Items[2] as MenuItem;
  702. menuItem.CommandTarget = PDFViewer;
  703. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  704. //缩放至所选区域
  705. menuItem = popMenu.Items[3] as MenuItem;
  706. menuItem.CommandTarget = PDFViewer;
  707. menuItem.Visibility = Visibility.Collapsed;
  708. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  709. //打印
  710. menuItem = popMenu.Items[4] as MenuItem;
  711. menuItem.CommandTarget = PDFViewer;
  712. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  713. }
  714. }
  715. }
  716. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  717. {
  718. switch (e.Key)
  719. {
  720. case "CloseSnap":
  721. {
  722. #region to do
  723. //var item = PDFViewerTab.SelectedItem as TabItem;
  724. //if (item == null)
  725. //{
  726. // ClearSelectedToolPanel();
  727. // return;
  728. //}
  729. //Grid grid = item.Content as Grid;
  730. //if (grid == null || grid.Children.Count == 0)
  731. //{
  732. // ClearSelectedToolPanel();
  733. // return;
  734. //}
  735. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  736. //if (pdfViewer == null)
  737. //{
  738. // ClearSelectedToolPanel();
  739. // return;
  740. //}
  741. #endregion to do
  742. switch (PDFViewer.MouseMode)
  743. {
  744. case MouseModes.SelectTextTool:
  745. break;
  746. default:
  747. BtnSelecttoolIsChecked = false;
  748. BtnHandIsChecked = true;
  749. PDFViewer.EnableZoom(true);
  750. PDFViewer.EnableScroll(true);
  751. break;
  752. }
  753. }
  754. break;
  755. default:
  756. break;
  757. }
  758. }
  759. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  760. {
  761. if (e != null && e.Count > 0)
  762. {
  763. MultipleSelectionAnnot(e);
  764. for (int i = 0; i < e.Count; i++)
  765. {
  766. AnnotEditEvent editEvent = e[i];
  767. switch (editEvent.EditAction)
  768. {
  769. case ActionType.Add:
  770. //BOTA
  771. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  772. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  773. {
  774. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  775. if (viewModel != null)
  776. {
  777. int pageindex = editEvent.PageIndex;
  778. int annotindex = editEvent.AnnotIndex;
  779. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  780. }
  781. }
  782. //添加书签注释,用于未保存前跟图章手绘注释的区分
  783. if (StrAnnotToolChecked == "Signature")
  784. {
  785. AddAnnotSignature(editEvent.EditAnnotArgs);
  786. }
  787. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  788. {
  789. (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  790. }
  791. break;
  792. case ActionType.Del:
  793. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  794. if (isTabItemAnnotation)
  795. {
  796. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  797. if (viewModel != null)
  798. {
  799. int pageindex = editEvent.PageIndex;
  800. int annotindex = editEvent.AnnotIndex;
  801. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  802. }
  803. }
  804. break;
  805. case ActionType.Modify:
  806. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  807. if (bOTAContent.TabItemAnnotation.IsSelected)
  808. {
  809. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  810. if (viewModel != null)
  811. {
  812. int pageindex = editEvent.PageIndex;
  813. int annotindex = editEvent.AnnotIndex;
  814. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  815. }
  816. }
  817. break;
  818. case ActionType.TextEdit:
  819. break;
  820. default:
  821. break;
  822. }
  823. }
  824. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  825. if (IsNoSelectMenu)
  826. {
  827. IsNoSelectMenu = false;
  828. PDFViewer.SetMouseMode(MouseModes.PanTool);
  829. }
  830. }
  831. }
  832. //复制多个注释,粘贴后,默认注释未选中状态
  833. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  834. {
  835. bool isAdd = false;
  836. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  837. foreach (var item in e)
  838. {
  839. if (item.EditAction == ActionType.Add /*|| item.EditAction == ActionType.Modify*/)
  840. {
  841. var annot = item.EditAnnotArgs;
  842. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  843. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
  844. {
  845. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  846. {
  847. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  848. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  849. }
  850. else
  851. {
  852. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  853. }
  854. isAdd = true;
  855. }
  856. }
  857. }
  858. if (isAdd)
  859. {
  860. PDFViewer.ClearSelectAnnots();
  861. if (StrAnnotToolChecked != "Signature")
  862. PDFViewer.SelectAnnotation(selectAnnotDicts);
  863. }
  864. }
  865. //阅读页悬浮相应
  866. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  867. {
  868. if (e != null && e.DrawContext != null)
  869. {
  870. Rect hoverRect = new Rect(
  871. e.PaintRect.Left - 2,
  872. e.PaintRect.Top - 2,
  873. e.PaintRect.Width + 4,
  874. e.PaintRect.Height + 4);
  875. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  876. hoverPen.DashStyle = DashStyles.Dash;
  877. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  878. //便签,显示ToolTip内容
  879. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  880. {
  881. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  882. return;
  883. }
  884. }
  885. CloseAnnotToolTip();
  886. }
  887. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  888. {
  889. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  890. {
  891. //鼠标移到注释之外,关闭ToolTip浮窗
  892. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  893. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  894. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  895. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  896. {
  897. CloseAnnotToolTip();
  898. }
  899. }
  900. }
  901. private Rect oldRect = new Rect(0, 0, 0, 0);
  902. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  903. {
  904. //便签,显示ToolTip内容
  905. if (PDFViewer.ToolTip == null)
  906. {
  907. if (string.IsNullOrEmpty(content) == false)
  908. {
  909. ToolTip TipChild = new ToolTip();
  910. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  911. TipChild.MaxWidth = 246;
  912. TipChild.Content = content;
  913. TipChild.Visibility = Visibility.Visible;
  914. TipChild.IsOpen = true;
  915. TipChild.Placement = PlacementMode.Right;
  916. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  917. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  918. TipChild.Placement = PlacementMode.MousePoint;
  919. PDFViewer.ToolTip = TipChild;
  920. oldRect = hoverRect;
  921. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  922. PDFViewer.MouseMove += PDFViewer_MouseMove;
  923. }
  924. }
  925. }
  926. //关闭ToolTip
  927. private void CloseAnnotToolTip()
  928. {
  929. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  930. {
  931. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  932. oldTips.IsOpen = false;
  933. oldTips.Visibility = Visibility.Collapsed;
  934. PDFViewer.ToolTip = null;
  935. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  936. oldRect = new Rect(0, 0, 0, 0);
  937. }
  938. }
  939. #endregion PDFViewer事件
  940. #region BindingEvent事件
  941. //同一属性面板,不同的注释类型
  942. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  943. {
  944. if (e != null)
  945. {
  946. AnnotHandlerEventArgs annotArgs = null;
  947. propertyPanel.SaveLastAnnot();
  948. foreach (AnnotArgsType argsType in e.Keys)
  949. {
  950. if (propertyPanel.annot.EventType != argsType)
  951. {
  952. PDFViewer.SetMouseMode(MouseModes.PanTool);
  953. }
  954. switch (argsType)
  955. {
  956. case AnnotArgsType.AnnotSquare:
  957. annotArgs = GetRect();
  958. break;
  959. case AnnotArgsType.AnnotCircle:
  960. annotArgs = GetCircle();
  961. break;
  962. case AnnotArgsType.AnnotLine:
  963. var LineTag = e[argsType] as string;
  964. annotArgs = GetArrowLine(LineTag);
  965. break;
  966. }
  967. ShowPropertyPanel();
  968. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  969. {
  970. PDFViewer.SetMouseMode(MouseModes.PanTool);
  971. return;
  972. }
  973. if (annotArgs != null)
  974. {
  975. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  976. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  977. PDFViewer.SetToolParam(annotArgs);
  978. }
  979. }
  980. }
  981. }
  982. //来自属性面板的事件,更改颜色等属性而触发
  983. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  984. {
  985. if (e != null)
  986. {
  987. foreach (AnnotArgsType argsType in e.Keys)
  988. {
  989. switch (argsType)
  990. {
  991. case AnnotArgsType.AnnotHighlight:
  992. if (e[argsType] is Color)
  993. {
  994. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  995. }
  996. if (e[argsType] is double)
  997. {
  998. HighLightOpacity = (double)e[argsType];
  999. }
  1000. //创建注释后,修改注释属性,可用于下次创建的注释
  1001. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1002. {
  1003. PDFViewer.SetToolParam(propertyPanel.annot);
  1004. }
  1005. break;
  1006. case AnnotArgsType.AnnotUnderline:
  1007. if (e[argsType] is Color)
  1008. {
  1009. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1010. }
  1011. if (e[argsType] is double)
  1012. {
  1013. underLineOpacity = (double)e[argsType];
  1014. }
  1015. //创建注释后,修改注释属性,可用于下次创建的注释
  1016. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1017. {
  1018. PDFViewer.SetToolParam(propertyPanel.annot);
  1019. }
  1020. break;
  1021. case AnnotArgsType.AnnotSquiggly:
  1022. if (e[argsType] is Color)
  1023. {
  1024. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1025. }
  1026. if (e[argsType] is double)
  1027. {
  1028. SquigglyOpacity = (double)e[argsType];
  1029. }
  1030. //创建注释后,修改注释属性,可用于下次创建的注释
  1031. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1032. {
  1033. PDFViewer.SetToolParam(propertyPanel.annot);
  1034. }
  1035. break;
  1036. case AnnotArgsType.AnnotStrikeout:
  1037. if (e[argsType] is Color)
  1038. {
  1039. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1040. }
  1041. if (e[argsType] is double)
  1042. {
  1043. StrikeoutOpacity = (double)e[argsType];
  1044. }
  1045. //创建注释后,修改注释属性,可用于下次创建的注释
  1046. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1047. {
  1048. PDFViewer.SetToolParam(propertyPanel.annot);
  1049. }
  1050. break;
  1051. case AnnotArgsType.AnnotFreehand:
  1052. if (e[argsType] is FreehandAnnotArgs)
  1053. {
  1054. var annot = e[argsType] as FreehandAnnotArgs;
  1055. if (annot != null)
  1056. {
  1057. if (propertyPanel != null)
  1058. {
  1059. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1060. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1061. propertyPanel.AnnotEvent = AnnotEvent;
  1062. var AnnotEvents = new List<AnnotAttribEvent>();
  1063. AnnotEvents.Add(AnnotEvent);
  1064. propertyPanel.AnnotEvents = AnnotEvents;
  1065. propertyPanel.annot = annot;
  1066. //手绘注释工具按钮的属性
  1067. // FreehandPath.Opacity = annot.Transparency;
  1068. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1069. }
  1070. PDFViewer.SetToolParam(annot);
  1071. }
  1072. }
  1073. break;
  1074. case AnnotArgsType.AnnotErase:
  1075. if (e[argsType] is ToggleButton)
  1076. {
  1077. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1078. if (clickBtn.IsChecked == true)
  1079. {
  1080. if (clickBtn.Tag.ToString() == "PenBtn")
  1081. {
  1082. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1083. btn.Tag = "Freehand"; btn.IsChecked = true;
  1084. BtnMyTools_Click(btn);
  1085. break;
  1086. }
  1087. CreateEraseArgs();
  1088. }
  1089. }
  1090. break;
  1091. case AnnotArgsType.AnnotSquare:
  1092. case AnnotArgsType.AnnotCircle:
  1093. case AnnotArgsType.AnnotLine:
  1094. case AnnotArgsType.AnnotFreeText:
  1095. //创建注释后,修改注释属性,可用于下次创建的注释
  1096. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1097. {
  1098. PDFViewer.SetToolParam(propertyPanel.annot);
  1099. }
  1100. break;
  1101. }
  1102. }
  1103. }
  1104. }
  1105. private void CreateEraseArgs()
  1106. {
  1107. EraseArgs eraseArgs = new EraseArgs();
  1108. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1109. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1110. eraseArgs.Thickness = 10;
  1111. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1112. if (annotProperty != null)
  1113. {
  1114. eraseArgs.Thickness = annotProperty.Thickness;
  1115. }
  1116. PDFViewer.ClearSelectAnnots(false);
  1117. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1118. PDFViewer.SetToolParam(eraseArgs);
  1119. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1120. if (eraseArgs != null)
  1121. eraseArgsList.Add(eraseArgs);
  1122. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1123. }
  1124. #endregion BindingEvent事件
  1125. }
  1126. }