AnnotToolContentViewModel.Command.cs 84 KB

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