AnnotToolContentViewModel.Command.cs 101 KB

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