AnnotToolContentViewModel.Command.cs 100 KB

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