AnnotToolContentViewModel.Command.cs 76 KB

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