AnnotToolContentViewModel.Command.cs 101 KB

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