AnnotToolContentViewModel.Command.cs 101 KB

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