AnnotToolContentViewModel.Command.cs 96 KB

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