AnnotToolContentViewModel.Command.cs 100 KB

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