AnnotToolContentViewModel.Command.cs 102 KB

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