AnnotToolContentViewModel.Command.cs 58 KB

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