AnnotToolContentViewModel.Command.cs 98 KB

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