AnnotToolContentViewModel.Command.cs 100 KB

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