AnnotToolContentViewModel.Command.cs 66 KB

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