AnnotToolContentViewModel.Command.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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. //BOTA所有列表都需要响应 单击阅读页取消多选
  96. if (viewContentViewModel.OpenBOTA == true)
  97. {
  98. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  99. }
  100. }
  101. if (e.ClickCount == 2)
  102. {
  103. if (CurrentSelectedAnnot != null)
  104. {
  105. var type = CurrentSelectedAnnot.EventType;
  106. if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
  107. type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline
  108. && type != AnnotArgsType.AnnotStrikeout &&type!=AnnotArgsType.AnnotLink)
  109. {
  110. int dpi = DpiHelpers.Dpi;
  111. var rect = CurrentSelectedAnnot.ClientRect;
  112. rect = new Rect(
  113. rect.Left * PDFViewer.ZoomFactor,
  114. rect.Top * PDFViewer.ZoomFactor,
  115. rect.Width * PDFViewer.ZoomFactor,
  116. rect.Height * PDFViewer.ZoomFactor);
  117. var ui = PDFViewer.Parent as ContentControl;
  118. if (ui != null)
  119. {
  120. var point = e.GetPosition(ui);
  121. int pageIndex = 0;
  122. Point pagePoint = new Point(0, 0);
  123. PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
  124. if (pagePoint.X >= rect.Left && pagePoint.X <= rect.Right && pagePoint.Y >= rect.Top && pagePoint.Y <= rect.Bottom)
  125. PopAnnotNoteText(CurrentSelectedAnnot);
  126. }
  127. }
  128. if (type == AnnotArgsType.AnnotSticky)
  129. {
  130. (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
  131. }
  132. }
  133. }
  134. }
  135. //超链接跳转
  136. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  137. {
  138. if (action == null)
  139. {
  140. return;
  141. }
  142. switch (action.ActionType)
  143. {
  144. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  145. if (PDFViewer != null)
  146. {
  147. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  148. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  149. if (dest != null)
  150. {
  151. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  152. }
  153. }
  154. break;
  155. case C_ACTION_TYPE.ACTION_TYPE_URI:
  156. {
  157. CPDFUriAction uriAction = action as CPDFUriAction;
  158. string uri = uriAction.GetUri();
  159. try
  160. {
  161. if (!string.IsNullOrEmpty(uri))
  162. {
  163. Process.Start(uri);
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. }
  169. }
  170. break;
  171. }
  172. }
  173. private void GetSelectedAnnots(AnnotAttribEvent e)
  174. {
  175. var annot = e.AnnotItemsList[0];
  176. switch (annot.EventType)
  177. {
  178. case AnnotArgsType.AnnotHighlight:
  179. GetHighLight(e.AnnotItemsList);
  180. break;
  181. case AnnotArgsType.AnnotUnderline:
  182. GetUnderLine(e.AnnotItemsList);
  183. break;
  184. case AnnotArgsType.AnnotStrikeout:
  185. GetStrikeout(e.AnnotItemsList);
  186. break;
  187. case AnnotArgsType.AnnotSquiggly:
  188. GetSquiggly(e.AnnotItemsList);
  189. break;
  190. case AnnotArgsType.AnnotFreehand:
  191. GetFreehand(e.AnnotItemsList);
  192. break;
  193. case AnnotArgsType.AnnotFreeText:
  194. GetFreetext(e.AnnotItemsList);
  195. break;
  196. case AnnotArgsType.AnnotSquare:
  197. GetRect(e.AnnotItemsList);
  198. break;
  199. case AnnotArgsType.AnnotCircle:
  200. GetCircle(e.AnnotItemsList);
  201. break;
  202. case AnnotArgsType.AnnotLine:
  203. bool isLine = true;
  204. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  205. {
  206. 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)
  207. {
  208. isLine = false;
  209. }
  210. }
  211. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  212. {
  213. 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)
  214. {
  215. isLine = false;
  216. }
  217. }
  218. if (isLine)
  219. GetArrowLine("Line", e.AnnotItemsList);
  220. else
  221. GetArrowLine("Arrow", e.AnnotItemsList);
  222. break;
  223. case AnnotArgsType.AnnotLink:
  224. //viewContentViewModel.IsCreateLink = false;
  225. //e.IsAnnotCreateReset= true;
  226. if (StrAnnotToolChecked == "Link")
  227. {
  228. PropertyPanel.IsAddLink = false;
  229. }
  230. GetLink(e.AnnotItemsList, e);
  231. break;
  232. case AnnotArgsType.AnnotSticky:
  233. GetStickyNote(e.AnnotItemsList);
  234. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  235. customStickyPopup.GetPDFViewer = PDFViewer;
  236. if (e.IsAnnotCreateReset)
  237. {
  238. PropertyPanel.annot = e.AnnotItemsList[0];
  239. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  240. PropertyPanel.AnnotEvents = null;
  241. PropertyPanel.AnnotEvent = AnnotEvent;
  242. PropertyPanel.annotlists = e.AnnotItemsList;
  243. }
  244. break;
  245. case AnnotArgsType.AnnotStamp:
  246. if (e.IsAnnotCreateReset == false)
  247. {
  248. GetStamp();
  249. }
  250. break;
  251. }
  252. }
  253. /// <summary>
  254. /// 选中注释 区分签名、图章、手绘
  255. /// </summary>
  256. /// <param name="annotlist"></param>
  257. private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
  258. {
  259. if (annotlist == null || annotlist.Count == 0)
  260. return;
  261. var annot = annotlist[0];
  262. if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
  263. return;
  264. if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
  265. return;
  266. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  267. if (signAnnot == null)
  268. {
  269. //var key = ToolExpandDict.FirstOrDefault(q => q.Value == annot.EventType);
  270. //if (!string.IsNullOrEmpty(StrAnnotToolChecked))
  271. // StrAnnotToolChecked = key.Key.ToString();
  272. //if (annot.EventType == AnnotArgsType.AnnotStamp)
  273. //{
  274. // StrAnnotToolChecked = "Stamp";
  275. //}
  276. //else
  277. //{
  278. // StrAnnotToolChecked = "";
  279. //}
  280. }
  281. else
  282. {
  283. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  284. {
  285. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  286. //GetSignature();
  287. //StrAnnotToolChecked = "Signature";
  288. }
  289. }
  290. }
  291. private void AddAnnotSignature(AnnotHandlerEventArgs annot)
  292. {
  293. if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
  294. (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
  295. if (StrAnnotToolChecked == "Signature")
  296. {
  297. if (viewContentViewModel.AnnotSignatures == null)
  298. viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
  299. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  300. if (signAnnot == null)
  301. {
  302. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
  303. }
  304. }
  305. }
  306. #endregion 与触发事件调用相关的函数
  307. #region PDFViewer事件
  308. private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
  309. //选中和非选中注释
  310. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  311. {
  312. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  313. {
  314. //viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  315. return;
  316. }
  317. if (e == null)
  318. {
  319. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  320. //HandToolIsCheckedEvent(false);
  321. if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  322. {
  323. PropertyPanel.annot = null;
  324. PropertyPanel.AnnotEvents = null;
  325. PropertyPanel.AnnotEvent = null;
  326. PropertyPanel.annotlists = null;
  327. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  328. }
  329. else
  330. {
  331. if (StrAnnotToolChecked != "Stamp" && StrAnnotToolChecked != "Freetext")
  332. {
  333. AnnotHandlerEventArgs annotArgs = null;
  334. //此处不能用这个方法更新创建注释的属性 会导致死循环
  335. // FindAnnotTypeKey(StrAnnotToolChecked, ref annotArgs);
  336. return;
  337. }
  338. return;
  339. }
  340. }
  341. if (e != null)
  342. {
  343. if (e.IsMouseRightActive)
  344. {
  345. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  346. {
  347. ShowPropertyPanel(false);
  348. return;
  349. }
  350. }
  351. CurrentSelectedAnnot = null;
  352. var annot = e.AnnotItemsList[0];
  353. if (annot != null)
  354. {
  355. if (e.AnnotItemsList.Count == 1)
  356. {
  357. //IsAnnotCreateReset:是否为创建注释的状态
  358. if (e.IsAnnotCreateReset == false)
  359. {
  360. CurrentSelectedAnnot = annot;
  361. GetSelectedAnnots(e);
  362. SelectedSignature(e.AnnotItemsList);
  363. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty
  364. && annot.EventType != AnnotArgsType.AnnotStamp && StrAnnotToolChecked != "Signature"
  365. && annot.EventType != AnnotArgsType.AnnotLink)
  366. {
  367. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  368. if (signAnnot == null)
  369. {
  370. ShowPropertyPanel(true);
  371. }
  372. }
  373. if (StrAnnotToolChecked == "Signature")
  374. {
  375. GetSignature();
  376. }
  377. //注释列表同步选中
  378. SelectedBotaAnnotationList(e);
  379. }
  380. else
  381. {
  382. if (!string.IsNullOrEmpty(StrAnnotToolChecked))
  383. {
  384. GetSelectedAnnots(e);
  385. PDFViewer.SetToolParam(annot);
  386. }
  387. else
  388. {
  389. if (IsNoSelectMenu)
  390. {
  391. return;
  392. }
  393. PropertyPanel.annot = null;
  394. PropertyPanel.AnnotEvents = null;
  395. PropertyPanel.AnnotEvent = null;
  396. PropertyPanel.annotlists = null;
  397. PDFViewer.SetMouseMode(MouseModes.PanTool);
  398. HandToolIsCheckedEvent(false);
  399. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  400. }
  401. //switch (annot.EventType)
  402. //{
  403. // case AnnotArgsType.AnnotFreeText:
  404. // annot = GetFreetext(e.AnnotItemsList);
  405. // PDFViewer.SetToolParam(annot);
  406. // break;
  407. // case AnnotArgsType.AnnotSticky:
  408. // customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  409. // customStickyPopup.GetPDFViewer = PDFViewer;
  410. // propertyPanel.annot = e.AnnotItemsList[0];
  411. // var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  412. // propertyPanel.AnnotEvents = null;
  413. // propertyPanel.AnnotEvent = AnnotEvent;
  414. // propertyPanel.annotlists = e.AnnotItemsList;
  415. // break;
  416. // case AnnotArgsType.AnnotLink:
  417. // //viewContentViewModel.IsCreateLink = false;
  418. // GetLink(e.AnnotItemsList, e);
  419. // PDFViewer.SetToolParam(annot);
  420. // break;
  421. //}
  422. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  423. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  424. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  425. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  426. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  427. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  428. //annot.EventType != AnnotArgsType.AnnotLink &&
  429. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  430. //annot.EventType != AnnotArgsType.AnnotSticky &&
  431. //)
  432. //{
  433. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  434. // {
  435. // var strLineAnnotTag = "";
  436. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  437. // {
  438. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  439. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  440. // {
  441. // strLineAnnotTag = "Line";
  442. // }
  443. // else
  444. // {
  445. // strLineAnnotTag = "Arrow";
  446. // }
  447. // }
  448. // foreach (var item in ToolExpandDict)
  449. // {
  450. // if (item.Value == e.AnnotItemsList[0].EventType)
  451. // {
  452. // annot = null;//新建注释时,回到默认值
  453. // if (string.IsNullOrEmpty(strLineAnnotTag))
  454. // {
  455. // FindAnnotTypeKey(item.Key, ref annot);
  456. // break;
  457. // }
  458. // else
  459. // {
  460. // if (strLineAnnotTag == item.Key)
  461. // {
  462. // FindAnnotTypeKey(item.Key, ref annot);
  463. // break;
  464. // }
  465. // }
  466. // }
  467. // }
  468. // PDFViewer.SetToolParam(annot);
  469. // }
  470. //}
  471. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  472. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  473. //{
  474. // ShowPropertyPanel(false);
  475. //}
  476. //else
  477. //{
  478. // ShowPropertyPanel();
  479. //}
  480. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  481. }
  482. }
  483. else
  484. {
  485. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  486. if (isDifferentAnnotTyle)
  487. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  488. else
  489. GetSelectedAnnots(e);
  490. }
  491. }
  492. }
  493. //else
  494. //{
  495. //if (StrAnnotToolChecked == "Link")
  496. //{
  497. // if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  498. // {
  499. // if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  500. // {
  501. // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  502. // }
  503. // }
  504. //}
  505. //if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  506. //{
  507. // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  508. //}
  509. //}
  510. }
  511. /// <summary>
  512. /// 注释列表同步选中
  513. /// </summary>
  514. /// <param name="e"></param>
  515. private void SelectedBotaAnnotationList(AnnotAttribEvent e)
  516. {
  517. var list = e.GetPageAnnotsIndex();
  518. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  519. //if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
  520. //{
  521. // viewContentViewModel.OpenBOTA = true;
  522. // bOTAContent.TabItemAnnotation.IsSelected = true;
  523. //}
  524. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  525. {
  526. if (list.Keys.Count == 0)
  527. {
  528. return;
  529. }
  530. var pageindex = new List<int>(list.Keys);
  531. List<int> annotes = new List<int>();
  532. list.TryGetValue(pageindex[0], out annotes);
  533. int annoteindex = annotes[0];
  534. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  535. if (viewModel != null)
  536. {
  537. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  538. }
  539. }
  540. }
  541. //在注释工具的状态下,右键菜单
  542. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  543. {
  544. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  545. return;
  546. if ((UIElement)sender != null)
  547. {
  548. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  549. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  550. }
  551. switch (e.CommandType)
  552. {
  553. case CommandType.Context:
  554. if (e.AnnotEventArgsList.Count > 0)
  555. {
  556. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  557. {
  558. //绑定标记密文处右键菜单
  559. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  560. }
  561. else
  562. {
  563. if (e.AnnotEventArgsList.Count == 1)
  564. {
  565. var selectedAnnot = e.AnnotEventArgsList[0];
  566. PopMenuCheckedLineDash(selectedAnnot);
  567. PopMenuCheckedFontFamily(selectedAnnot);
  568. PopMenuCheckedTextAglin(selectedAnnot);
  569. switch (selectedAnnot.EventType)
  570. {
  571. case AnnotArgsType.AnnotHighlight:
  572. case AnnotArgsType.AnnotUnderline:
  573. case AnnotArgsType.AnnotStrikeout:
  574. case AnnotArgsType.AnnotSquiggly:
  575. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  576. {
  577. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  578. }
  579. else
  580. {
  581. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  582. }
  583. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  584. break;
  585. case AnnotArgsType.AnnotFreehand:
  586. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  587. break;
  588. case AnnotArgsType.AnnotFreeText:
  589. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  590. break;
  591. case AnnotArgsType.AnnotSticky:
  592. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  593. break;
  594. case AnnotArgsType.AnnotSquare:
  595. case AnnotArgsType.AnnotCircle:
  596. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  597. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  598. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  599. break;
  600. case AnnotArgsType.AnnotLine:
  601. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  602. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  603. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  604. break;
  605. case AnnotArgsType.AnnotLink:
  606. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  607. break;
  608. case AnnotArgsType.AnnotStamp:
  609. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  610. break;
  611. }
  612. }
  613. else
  614. {
  615. bool isHigh = true;//是否为高亮
  616. foreach (var item in e.AnnotEventArgsList)
  617. {
  618. if (AnnotTransfer.IsHightAnnot(item) == false)
  619. {
  620. isHigh = false;
  621. break;
  622. }
  623. }
  624. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  625. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  626. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  627. }
  628. }
  629. if (e.PopupMenu != null)
  630. {
  631. e.Handle = true;
  632. }
  633. }
  634. else
  635. {
  636. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  637. {
  638. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  639. if (e.PopupMenu != null)
  640. {
  641. e.Handle = true;
  642. }
  643. }
  644. else
  645. {
  646. e.PopupMenu = ViewerContextMenu(sender);
  647. if (e.PopupMenu != null)
  648. {
  649. e.Handle = true;
  650. }
  651. }
  652. }
  653. break;
  654. }
  655. }
  656. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  657. {
  658. if (e.Command == ApplicationCommands.Copy)
  659. {
  660. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
  661. if (result.IsDiscryptied)
  662. {
  663. if (result.Password != null)
  664. {
  665. string filePath = PDFViewer.Document.FilePath;
  666. var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
  667. }
  668. }
  669. else
  670. {
  671. e.Handled = true;
  672. }
  673. }
  674. }
  675. /// <summary>
  676. /// 右键菜单,选中字体样式按钮状态
  677. /// </summary>
  678. /// <param name="annot"></param>
  679. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  680. {
  681. if (annot != null)
  682. {
  683. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  684. {
  685. var freeText = annot as FreeTextAnnotArgs;
  686. string fontFamily = freeText.FontFamily.ToString();
  687. if (fontFamily == "Arial")
  688. {
  689. fontFamily = "Helvetica";
  690. }
  691. if(fontFamily== "Courier New")
  692. {
  693. fontFamily = "Courier";
  694. }
  695. if (fontFamily == "Times New Roman")
  696. {
  697. fontFamily = "Times";
  698. }
  699. FreeTextAnnotPopMenu.SetIsChecked(fontFamily, true);
  700. }
  701. }
  702. }
  703. /// <summary>
  704. /// 右键菜单,选中文本内容对齐按钮状态
  705. /// </summary>
  706. /// <param name="annot"></param>
  707. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  708. {
  709. if (annot != null)
  710. {
  711. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  712. {
  713. var freeText = annot as FreeTextAnnotArgs;
  714. switch (freeText.Align)
  715. {
  716. case TextAlignment.Left:
  717. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  718. break;
  719. case TextAlignment.Center:
  720. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  721. break;
  722. case TextAlignment.Right:
  723. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  724. break;
  725. case TextAlignment.Justify:
  726. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  727. break;
  728. default:
  729. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  730. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  731. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  732. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  733. break;
  734. }
  735. }
  736. }
  737. }
  738. //右键菜单,选中虚实线按钮状态
  739. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  740. {
  741. if (annot != null)
  742. {
  743. bool isSolidLineDash = true;
  744. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  745. {
  746. var freeHand = annot as FreehandAnnotArgs;
  747. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  748. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  749. }
  750. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  751. {
  752. var square = annot as SquareAnnotArgs;
  753. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  754. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  755. }
  756. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  757. {
  758. var circle = annot as CircleAnnotArgs;
  759. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  760. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  761. }
  762. else if (annot.EventType == AnnotArgsType.AnnotLine)
  763. {
  764. var line = annot as LineAnnotArgs;
  765. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  766. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  767. }
  768. }
  769. }
  770. /// <summary>
  771. /// 内容选择工具
  772. /// </summary>
  773. /// <param name="sender"></param>
  774. /// <param name="e"></param>
  775. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  776. {
  777. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  778. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  779. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  780. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  781. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  782. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  783. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  784. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  785. {
  786. e.PopupMenu = popMenu;
  787. e.Handle = true;
  788. if (popMenu != null && popMenu.Items.Count == 5)
  789. {
  790. //复制
  791. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  792. menuItem.CommandTarget = PDFViewer;
  793. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  794. //导出
  795. menuItem = popMenu.Items[1] as MenuItem;
  796. menuItem.CommandTarget = PDFViewer;
  797. if (menuItem.Items.Count == 3)
  798. {
  799. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  800. menuItem1.CommandTarget = PDFViewer;
  801. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  802. menuItem1 = menuItem.Items[1] as MenuItem;
  803. menuItem1.CommandTarget = PDFViewer;
  804. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  805. menuItem1 = menuItem.Items[2] as MenuItem;
  806. menuItem1.CommandTarget = PDFViewer;
  807. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  808. }
  809. //裁剪
  810. menuItem = popMenu.Items[2] as MenuItem;
  811. menuItem.CommandTarget = PDFViewer;
  812. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  813. //缩放至所选区域
  814. menuItem = popMenu.Items[3] as MenuItem;
  815. menuItem.CommandTarget = PDFViewer;
  816. menuItem.Visibility = Visibility.Collapsed;
  817. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  818. //打印
  819. menuItem = popMenu.Items[4] as MenuItem;
  820. menuItem.CommandTarget = PDFViewer;
  821. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  822. }
  823. }
  824. }
  825. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  826. {
  827. switch (e.Key)
  828. {
  829. case "CloseSnap":
  830. {
  831. #region to do
  832. //var item = PDFViewerTab.SelectedItem as TabItem;
  833. //if (item == null)
  834. //{
  835. // ClearSelectedToolPanel();
  836. // return;
  837. //}
  838. //Grid grid = item.Content as Grid;
  839. //if (grid == null || grid.Children.Count == 0)
  840. //{
  841. // ClearSelectedToolPanel();
  842. // return;
  843. //}
  844. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  845. //if (pdfViewer == null)
  846. //{
  847. // ClearSelectedToolPanel();
  848. // return;
  849. //}
  850. #endregion to do
  851. switch (PDFViewer.MouseMode)
  852. {
  853. case MouseModes.SelectTextTool:
  854. break;
  855. default:
  856. BtnSelecttoolIsChecked = false;
  857. //BtnHandIsChecked = true;
  858. PDFViewer.EnableZoom(true);
  859. PDFViewer.EnableScroll(true);
  860. PDFViewer.SetMouseMode(MouseModes.PanTool);
  861. break;
  862. }
  863. }
  864. break;
  865. default:
  866. break;
  867. }
  868. }
  869. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  870. {
  871. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  872. AnnotationContentViewModel viewModel = null;
  873. AnnotationContent annotation = null;
  874. if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  875. {
  876. viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out annotation);
  877. }
  878. bool isMultiple = false;
  879. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  880. if (e != null && e.Count > 0)
  881. {
  882. for (int i = 0; i < e.Count; i++)
  883. {
  884. AnnotEditEvent editEvent = e[i];
  885. bool isVisible = PDFViewer.CheckAnnotVisible(editEvent.PageIndex, editEvent.AnnotIndex);
  886. var annot = editEvent.EditAnnotArgs;
  887. switch (editEvent.EditAction)
  888. {
  889. case ActionType.Add:
  890. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  891. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText /*|| annot.EventType == AnnotArgsType.AnnotFreehand*/)
  892. {
  893. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  894. {
  895. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  896. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  897. }
  898. else
  899. {
  900. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  901. }
  902. isMultiple = true;
  903. }
  904. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  905. //{
  906. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  907. if (viewModel != null)
  908. {
  909. int pageindex = editEvent.PageIndex;
  910. int annotindex = editEvent.AnnotIndex;
  911. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  912. }
  913. //}
  914. //添加书签注释,用于未保存前跟图章手绘注释的区分
  915. if (StrAnnotToolChecked == "Signature")
  916. {
  917. AddAnnotSignature(editEvent.EditAnnotArgs);
  918. }
  919. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  920. //{
  921. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  922. //}
  923. break;
  924. case ActionType.Modify:
  925. // if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  926. //annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  927. // {
  928. // if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  929. // {
  930. // selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  931. // selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  932. // }
  933. // else
  934. // {
  935. // selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  936. // }
  937. // isMultiple = true;
  938. // }
  939. if (viewModel != null)
  940. {
  941. int pageindex = editEvent.PageIndex;
  942. int annotindex = editEvent.AnnotIndex;
  943. viewModel.UpdateModifiedAnnot(pageindex, annotindex);
  944. }
  945. //}
  946. break;
  947. case ActionType.Del:
  948. //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  949. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  950. //{
  951. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  952. if (viewModel != null)
  953. {
  954. int pageindex = editEvent.PageIndex;
  955. int annotindex = editEvent.AnnotIndex;
  956. viewModel.DeleteModifiedAnnot(pageindex, annotindex);
  957. }
  958. //}
  959. ExitAnnotationTool();
  960. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  961. break;
  962. case ActionType.TextEdit:
  963. break;
  964. default:
  965. break;
  966. }
  967. }
  968. if (isMultiple && selectAnnotDicts.Count >= 1)
  969. {
  970. PDFViewer.ClearSelectAnnots();
  971. if (StrAnnotToolChecked != "Signature")
  972. {
  973. PDFViewer.SelectAnnotation(selectAnnotDicts);
  974. //foreach (var item in selectAnnotDicts.Keys)
  975. //{
  976. // List<int> value = selectAnnotDicts[item];
  977. // foreach (var item1 in value)
  978. // {
  979. // }
  980. //}
  981. }
  982. }
  983. //MultipleSelectionAnnot(e);
  984. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  985. if (IsNoSelectMenu)
  986. {
  987. IsNoSelectMenu = false;
  988. PDFViewer.SetMouseMode(MouseModes.PanTool);
  989. }
  990. }
  991. }
  992. //复制多个注释,粘贴后,默认注释未选中状态
  993. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  994. {
  995. bool isAdd = false;
  996. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  997. foreach (var item in e)
  998. {
  999. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  1000. {
  1001. var annot = item.EditAnnotArgs;
  1002. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1003. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  1004. {
  1005. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  1006. {
  1007. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  1008. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1009. }
  1010. else
  1011. {
  1012. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1013. }
  1014. isAdd = true;
  1015. }
  1016. }
  1017. }
  1018. if (isAdd && selectAnnotDicts.Count >= 1)
  1019. {
  1020. PDFViewer.ClearSelectAnnots();
  1021. if (StrAnnotToolChecked != "Signature")
  1022. {
  1023. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1024. }
  1025. }
  1026. }
  1027. //阅读页悬浮相应
  1028. /// <summary>
  1029. /// 阅读页鼠标悬浮在注释上的虚线
  1030. /// </summary>
  1031. /// <param name="sender"></param>
  1032. /// <param name="e"></param>
  1033. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1034. {
  1035. if (e != null && e.DrawContext != null)
  1036. {
  1037. if (StrAnnotToolChecked != "Link")
  1038. {
  1039. if (e.Annot is CPDFLinkAnnotation linkAnnotation)
  1040. {
  1041. return;
  1042. }
  1043. }
  1044. Rect hoverRect = new Rect(
  1045. e.PaintRect.Left - 2,
  1046. e.PaintRect.Top - 2,
  1047. e.PaintRect.Width + 4,
  1048. e.PaintRect.Height + 4);
  1049. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1050. hoverPen.DashStyle = DashStyles.Dash;
  1051. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1052. //便签,显示ToolTip内容
  1053. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1054. {
  1055. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  1056. return;
  1057. }
  1058. }
  1059. CloseAnnotToolTip();
  1060. }
  1061. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1062. {
  1063. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1064. {
  1065. //鼠标移到注释之外,关闭ToolTip浮窗
  1066. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1067. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1068. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1069. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1070. {
  1071. CloseAnnotToolTip();
  1072. }
  1073. }
  1074. }
  1075. private Rect oldRect = new Rect(0, 0, 0, 0);
  1076. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  1077. {
  1078. //便签,显示ToolTip内容
  1079. if (PDFViewer.ToolTip == null)
  1080. {
  1081. if (string.IsNullOrEmpty(content) == false)
  1082. {
  1083. ToolTip TipChild = new ToolTip();
  1084. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1085. TipChild.MaxWidth = 246;
  1086. TipChild.Content = content;
  1087. TipChild.Visibility = Visibility.Visible;
  1088. TipChild.IsOpen = true;
  1089. TipChild.Placement = PlacementMode.Right;
  1090. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  1091. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1092. TipChild.Placement = PlacementMode.MousePoint;
  1093. PDFViewer.ToolTip = TipChild;
  1094. oldRect = hoverRect;
  1095. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1096. PDFViewer.MouseMove += PDFViewer_MouseMove;
  1097. }
  1098. }
  1099. }
  1100. //关闭ToolTip
  1101. private void CloseAnnotToolTip()
  1102. {
  1103. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1104. {
  1105. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1106. oldTips.IsOpen = false;
  1107. oldTips.Visibility = Visibility.Collapsed;
  1108. PDFViewer.ToolTip = null;
  1109. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1110. oldRect = new Rect(0, 0, 0, 0);
  1111. }
  1112. }
  1113. #endregion PDFViewer事件
  1114. #region BindingEvent事件
  1115. //同一属性面板,不同的注释类型
  1116. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1117. {
  1118. if (e != null && sender is SharpsAnnotPropertyViewModel sharpsAnnot)
  1119. {
  1120. AnnotHandlerEventArgs annotArgs = null;
  1121. //PropertyPanel.SaveLastAnnot();
  1122. List<AnnotHandlerEventArgs> annots = new List<AnnotHandlerEventArgs>();
  1123. foreach (AnnotArgsType argsType in e.Keys)
  1124. {
  1125. if (PropertyPanel.annot != null)
  1126. {
  1127. if (PropertyPanel.annot.EventType != argsType)
  1128. {
  1129. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1130. CurrentSelectedAnnot = null;
  1131. }
  1132. }
  1133. switch (argsType)
  1134. {
  1135. case AnnotArgsType.AnnotSquare:
  1136. #region TO DO
  1137. //选择一个形状注释A,在选择B(非多选),修改属性成功,以下操作的操作可以解决,
  1138. //可能会出现选择注释A,鼠标直接点击属性面板,注释A取消选中,但还可以对注释A更改属性的BUG
  1139. //if (CurrentSelectedAnnot != null)
  1140. //{
  1141. // if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotSquare)
  1142. // {
  1143. // CurrentSelectedAnnot.PageIndex = -1;
  1144. // CurrentSelectedAnnot.AnnotIndex = -1;
  1145. // CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1146. // annots.Add(CurrentSelectedAnnot);
  1147. // }
  1148. //}
  1149. //if (annots.Count > 0)
  1150. //{
  1151. // annotArgs = GetRect(annots);
  1152. //}
  1153. //else
  1154. //{
  1155. // annotArgs = GetRect();
  1156. //}
  1157. #endregion TO DO
  1158. annotArgs = GetRect();
  1159. break;
  1160. case AnnotArgsType.AnnotCircle:
  1161. #region TO DO
  1162. //if (CurrentSelectedAnnot != null)
  1163. //{
  1164. // if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotCircle)
  1165. // {
  1166. // CurrentSelectedAnnot.PageIndex = -1;
  1167. // CurrentSelectedAnnot.AnnotIndex = -1;
  1168. // CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1169. // annots.Add(CurrentSelectedAnnot);
  1170. // }
  1171. //}
  1172. //if (annots.Count > 0)
  1173. //{
  1174. // annotArgs = GetCircle(annots);
  1175. //}
  1176. //else
  1177. //{
  1178. // annotArgs = GetCircle();
  1179. //}
  1180. #endregion TO DO
  1181. annotArgs = GetCircle();
  1182. break;
  1183. case AnnotArgsType.AnnotLine:
  1184. var LineTag = e[argsType] as string;
  1185. #region TO DO
  1186. //if (CurrentSelectedAnnot != null)
  1187. //{
  1188. // if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotLine)
  1189. // {
  1190. // CurrentSelectedAnnot.PageIndex = -1;
  1191. // CurrentSelectedAnnot.AnnotIndex = -1;
  1192. // CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1193. // if (CurrentSelectedAnnot is LineAnnotArgs lineAnnotArgs)
  1194. // {
  1195. // if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1196. // {
  1197. // if (LineTag == "Arrow")
  1198. // {
  1199. // annots.Add(CurrentSelectedAnnot);
  1200. // }
  1201. // }
  1202. // else
  1203. // {
  1204. // if (LineTag == "Line")
  1205. // {
  1206. // annots.Add(CurrentSelectedAnnot);
  1207. // }
  1208. // }
  1209. // }
  1210. // }
  1211. //}
  1212. //if (annots.Count > 0)
  1213. //{
  1214. // annotArgs = GetArrowLine(LineTag, annots);
  1215. //}
  1216. //else
  1217. //{
  1218. // annotArgs = GetArrowLine(LineTag);
  1219. //}
  1220. #endregion TO DO
  1221. annotArgs = GetArrowLine(LineTag);
  1222. break;
  1223. }
  1224. ShowPropertyPanel();
  1225. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1226. {
  1227. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1228. return;
  1229. }
  1230. if (annotArgs != null)
  1231. {
  1232. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1233. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1234. PDFViewer.SetToolParam(annotArgs);
  1235. }
  1236. }
  1237. }
  1238. }
  1239. //来自属性面板的事件,更改颜色等属性而触发
  1240. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1241. {
  1242. if (e != null)
  1243. {
  1244. foreach (AnnotArgsType argsType in e.Keys)
  1245. {
  1246. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1247. switch (argsType)
  1248. {
  1249. case AnnotArgsType.AnnotHighlight:
  1250. if (e[argsType] is Color)
  1251. {
  1252. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1253. }
  1254. if (e[argsType] is double)
  1255. {
  1256. HighLightOpacity = (double)e[argsType];
  1257. }
  1258. //创建注释后,修改注释属性,可用于下次创建的注释
  1259. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1260. {
  1261. if (StrAnnotToolChecked == key.Key)
  1262. {
  1263. PDFViewer.SetToolParam(PropertyPanel.annot);
  1264. }
  1265. }
  1266. break;
  1267. case AnnotArgsType.AnnotUnderline:
  1268. if (e[argsType] is Color)
  1269. {
  1270. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1271. }
  1272. if (e[argsType] is double)
  1273. {
  1274. underLineOpacity = (double)e[argsType];
  1275. }
  1276. //创建注释后,修改注释属性,可用于下次创建的注释
  1277. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1278. {
  1279. if (StrAnnotToolChecked == key.Key)
  1280. {
  1281. PDFViewer.SetToolParam(PropertyPanel.annot);
  1282. }
  1283. }
  1284. break;
  1285. case AnnotArgsType.AnnotSquiggly:
  1286. if (e[argsType] is Color)
  1287. {
  1288. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1289. }
  1290. if (e[argsType] is double)
  1291. {
  1292. SquigglyOpacity = (double)e[argsType];
  1293. }
  1294. //创建注释后,修改注释属性,可用于下次创建的注释
  1295. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1296. {
  1297. if (StrAnnotToolChecked == key.Key)
  1298. {
  1299. PDFViewer.SetToolParam(PropertyPanel.annot);
  1300. }
  1301. }
  1302. break;
  1303. case AnnotArgsType.AnnotStrikeout:
  1304. if (e[argsType] is Color)
  1305. {
  1306. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1307. }
  1308. if (e[argsType] is double)
  1309. {
  1310. StrikeoutOpacity = (double)e[argsType];
  1311. }
  1312. //创建注释后,修改注释属性,可用于下次创建的注释
  1313. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1314. {
  1315. if (StrAnnotToolChecked == key.Key)
  1316. {
  1317. PDFViewer.SetToolParam(PropertyPanel.annot);
  1318. }
  1319. }
  1320. break;
  1321. case AnnotArgsType.AnnotFreehand:
  1322. if (e[argsType] is FreehandAnnotArgs)
  1323. {
  1324. var annot = e[argsType] as FreehandAnnotArgs;
  1325. if (annot != null)
  1326. {
  1327. if (PropertyPanel != null)
  1328. {
  1329. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1330. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1331. PropertyPanel.AnnotEvent = AnnotEvent;
  1332. var AnnotEvents = new List<AnnotAttribEvent>();
  1333. AnnotEvents.Add(AnnotEvent);
  1334. PropertyPanel.AnnotEvents = AnnotEvents;
  1335. PropertyPanel.annot = annot;
  1336. //手绘注释工具按钮的属性
  1337. // FreehandPath.Opacity = annot.Transparency;
  1338. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1339. }
  1340. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1341. {
  1342. if (StrAnnotToolChecked == key.Key)
  1343. {
  1344. PDFViewer.SetToolParam(PropertyPanel.annot);
  1345. }
  1346. }
  1347. }
  1348. }
  1349. break;
  1350. case AnnotArgsType.AnnotErase:
  1351. if (e[argsType] is ToggleButton)
  1352. {
  1353. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1354. if (clickBtn.IsChecked == true)
  1355. {
  1356. if (clickBtn.Tag.ToString() == "PenBtn")
  1357. {
  1358. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1359. btn.Tag = "Freehand"; btn.IsChecked = true;
  1360. BtnMyTools_Click(btn);
  1361. break;
  1362. }
  1363. CreateEraseArgs();
  1364. }
  1365. }
  1366. break;
  1367. case AnnotArgsType.AnnotSquare:
  1368. case AnnotArgsType.AnnotCircle:
  1369. case AnnotArgsType.AnnotLine:
  1370. case AnnotArgsType.AnnotFreeText:
  1371. //创建注释后,修改注释属性,可用于下次创建的注释
  1372. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1373. {
  1374. if (StrAnnotToolChecked == key.Key || PropertyPanel.SharpsAnnot == key.Key)
  1375. {
  1376. PDFViewer.SetToolParam(PropertyPanel.annot);
  1377. PropertyPanel.SaveLastAnnot();
  1378. }
  1379. }
  1380. break;
  1381. }
  1382. }
  1383. }
  1384. }
  1385. private void CreateEraseArgs()
  1386. {
  1387. EraseArgs eraseArgs = new EraseArgs();
  1388. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1389. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1390. eraseArgs.Thickness = 10;
  1391. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1392. if (annotProperty != null)
  1393. {
  1394. eraseArgs.Thickness = annotProperty.Thickness;
  1395. }
  1396. PDFViewer.ClearSelectAnnots(false);
  1397. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1398. PDFViewer.SetToolParam(eraseArgs);
  1399. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1400. if (eraseArgs != null)
  1401. eraseArgsList.Add(eraseArgs);
  1402. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1403. }
  1404. #endregion BindingEvent事件
  1405. }
  1406. }