AnnotToolContentViewModel.Command.cs 85 KB

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