AnnotToolContentViewModel.Command.cs 98 KB

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