AnnotToolContentViewModel.Command.cs 84 KB

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