AnnotToolContentViewModel.Command.cs 94 KB

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