AnnotToolContentViewModel.Command.cs 97 KB

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