AnnotToolContentViewModel.Command.cs 101 KB

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