AnnotToolContentViewModel.cs 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using ImTools;
  7. using Microsoft.Win32;
  8. using PDF_Master.CustomControl;
  9. using PDF_Master.EventAggregators;
  10. using PDF_Master.Helper;
  11. using PDF_Master.Model;
  12. using PDF_Master.Model.BOTA;
  13. using PDF_Master.Properties;
  14. using PDF_Master.ViewModels.BOTA;
  15. using PDF_Master.ViewModels.PropertyPanel;
  16. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  17. using PDF_Master.ViewModels.Tools.AnnotManager;
  18. using PDF_Master.Views.BOTA;
  19. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  20. using PDFSettings;
  21. using PDFSettings.Settings;
  22. using Prism.Commands;
  23. using Prism.Events;
  24. using Prism.Mvvm;
  25. using Prism.Regions;
  26. using Prism.Services.Dialogs;
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Linq;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. using System.Windows;
  35. using System.Windows.Annotations;
  36. using System.Windows.Controls;
  37. using System.Windows.Controls.Primitives;
  38. using System.Windows.Forms;
  39. using System.Windows.Input;
  40. using System.Windows.Media;
  41. using System.Windows.Media.Imaging;
  42. using ContextMenu = System.Windows.Controls.ContextMenu;
  43. using KeyEventArgs = System.Windows.Input.KeyEventArgs;
  44. using MenuItem = System.Windows.Controls.MenuItem;
  45. namespace PDF_Master.ViewModels.Tools
  46. {
  47. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  48. {
  49. #region 初始化
  50. public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogService)
  51. {
  52. region = regionManager;
  53. events = eventAggregator;
  54. dialogs = dialogService;
  55. InitCommand();
  56. InitDefaultValue();
  57. InitToolDict();
  58. InitToolTipDict();
  59. InitPopMenu();
  60. SubscribeEvent();
  61. AnnotContainerBorderColor();
  62. }
  63. //注释容器选中边框的颜色
  64. private void AnnotContainerBorderColor()
  65. {
  66. var pen = new Pen(new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4)), 1);
  67. CommonDrawData.ActiveBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4));
  68. CommonDrawData.ActivePen = pen;
  69. }
  70. //事件聚合器
  71. private void SubscribeEvent()
  72. {
  73. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  74. events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
  75. }
  76. private void InitPopMenu()
  77. {
  78. InitSelectHightAnnotMenu();
  79. InitSelectFreeHandAnnotMenu();
  80. InitSelectFreeTextAnnotMenu();
  81. InitSelectStrickNoteAnnotMenu();
  82. InitSelectShapeAnnotMenu();
  83. InitSelectLinkAnnotMenu();
  84. InitSelectStampAnnotMenu();
  85. InitSelectMultiAnnotMenu();
  86. }
  87. private void InitCommand()
  88. {
  89. MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
  90. SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
  91. AddBookMarkCommand = new DelegateCommand(AddBookMark_Click);
  92. PropertyRegionName = Guid.NewGuid().ToString();
  93. HandCommand = new DelegateCommand(Hand_Click);
  94. #region 注释 - 右键菜单
  95. //公共command
  96. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  97. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  98. AnnotAddNoteText_MenuCommand = new DelegateCommand<object>(AnnotAddNoteText_Menu);
  99. //高亮、下划线、删除
  100. HightAnnotCopyText_MenuCommand = new DelegateCommand<object>(HightAnnotCopyText_Menu);
  101. //手绘
  102. FreeHandLineStyle_MenuCommand = new DelegateCommand<object>(FreeHandLineStyle_Menu);
  103. //文本
  104. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  105. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  106. //便签
  107. StrikeNoteEditStrike_MenuCommand = new DelegateCommand<object>(StrikeNoteEditStrike_Menu);
  108. //形状
  109. ShapeLineStyle_MenuCommand = new DelegateCommand<object>(ShapeLineStyle_Menu);
  110. ShapeLineDirect_MenuCommand = new DelegateCommand<object>(ShapeLineDirect_Menu);
  111. //图章
  112. StampExportPicture_MenuCommand = new DelegateCommand<object>(StampExportPicture_Menu);
  113. //链接
  114. Link_MenuCommand = new DelegateCommand<object>(Link_Menu);
  115. #endregion 注释 - 右键菜单
  116. }
  117. #endregion 初始化
  118. #region 注释工具栏 -》Command实现
  119. //手型工具
  120. private void Hand_Click()
  121. {
  122. HandToolIsCheckedEvent(BtnHandIsChecked);
  123. if (BtnHandIsChecked)
  124. {
  125. //其余注释工具 取消选中
  126. StrAnnotToolChecked = "";
  127. BtnLinkIsChecked = false;
  128. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  129. }
  130. }
  131. //手型工具按钮选中或取消
  132. private void HandToolIsCheckedEvent(bool isChecked)
  133. {
  134. if (isChecked == false)
  135. {
  136. //鼠标框选多选注释
  137. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  138. {
  139. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  140. var annotArgs = new SelectToolArgs();
  141. PDFViewer.SetToolParam(annotArgs);
  142. }
  143. else
  144. {
  145. PDFViewer.SetMouseMode(MouseModes.PanTool);
  146. }
  147. }
  148. else
  149. {
  150. //鼠标滚动页面
  151. PDFViewer.SetMouseMode(MouseModes.Scroll);
  152. PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
  153. }
  154. }
  155. //点击注释工具
  156. private void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
  157. {
  158. if (annotBtn == null || annotBtn.Tag == null) return;
  159. //不创建注释,属于注释模板
  160. Dictionary<string, bool> dictVar = new Dictionary<string, bool>();
  161. dictVar.Add("isTemplateAnnot", false);
  162. dictVar.Add("isSnapshotEdit", false);
  163. AnnotHandlerEventArgs annotArgs = null;
  164. var tag = annotBtn.Tag.ToString();
  165. if (annotBtn.Name == "BtnShowAnnot")
  166. {
  167. //显示/隐藏注释
  168. PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
  169. return;
  170. }
  171. if (annotBtn.IsChecked == true)
  172. {
  173. propertyPanel.SaveLastAnnot();
  174. MyToolCheckedDoing(dictVar, tag);
  175. FindAnnotTypeKey(tag, ref annotArgs);
  176. if (annotArgs != null)
  177. {
  178. //设置点击页面会创建对应选中注释工具的注释
  179. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  180. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  181. PDFViewer.SetToolParam(annotArgs);
  182. }
  183. }
  184. else
  185. {
  186. //取消选中注释工具按钮后,恢复到未编辑注释的状态
  187. propertyPanel.IsAddLink = false;
  188. propertyPanel.IsLocationLink = false;
  189. PDFViewer.ToolManager.EnableClickCreate = false;
  190. PDFViewer.SetMouseMode(MouseModes.PanTool);
  191. ShowPropertyPanel(false);
  192. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  193. {
  194. events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
  195. }
  196. }
  197. if (dictVar["isTemplateAnnot"] == false && annotArgs == null)
  198. {
  199. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  200. HandToolIsCheckedEvent(false);
  201. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  202. }
  203. else
  204. {
  205. if (dictVar["isSnapshotEdit"] == true)
  206. {
  207. ShowPropertyPanel(false);
  208. }
  209. else
  210. {
  211. ShowPropertyPanel((bool)annotBtn.IsChecked);
  212. }
  213. }
  214. }
  215. //选中注释工具按钮时,处理的一些系列事情
  216. private void MyToolCheckedDoing(Dictionary<string, bool> dict, string tag)
  217. {
  218. if (BtnHandIsChecked)
  219. BtnHandIsChecked = false;
  220. PDFViewer.ClearSelectAnnots();
  221. //选中内容选择工具按钮
  222. if (tag == "SnapshotEdit")
  223. {
  224. dict["isSnapshotEdit"] = true;
  225. }
  226. else if (tag == "Signature" || tag == "Stamp")
  227. {
  228. //选中签名、图章工具按钮
  229. dict["isTemplateAnnot"] = true;
  230. }
  231. //超链接工具
  232. //if (tag != "Link")
  233. // BtnLinkIsChecked = false;
  234. //else
  235. // StrAnnotToolChecked = "Link";
  236. if (tag != "Link")
  237. {
  238. events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
  239. //if (region.Regions.ContainsRegionWithName(viewContentViewModel.TipContentRegionName))
  240. //{
  241. // var views = region.Regions[viewContentViewModel.TipContentRegionName].Views;
  242. // Views.TipContent.LinkAnnotTip isHas = (Views.TipContent.LinkAnnotTip)views.FindFirst(q => q is Views.TipContent.LinkAnnotTip);
  243. // if (isHas != null)
  244. // {
  245. // viewContentViewModel.TipVisible = System.Windows.Visibility.Collapsed;
  246. // (isHas.DataContext as LinkAnnotPropertyViewModel).BtnLocationIsChecked = false;
  247. // }
  248. //}
  249. }
  250. if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
  251. {
  252. //新建形状注释,设置默认大小
  253. PDFViewer.ToolManager.EnableClickCreate = true;
  254. PDFViewer.ToolManager.ClickCreateWidth = 140;
  255. PDFViewer.ToolManager.ClickCreateHeight = 140;
  256. }
  257. else
  258. {
  259. PDFViewer.ToolManager.EnableClickCreate = false;
  260. }
  261. }
  262. #endregion 注释工具栏 -》Command实现
  263. #region BOTA
  264. private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel, out AnnotationContent annotation)
  265. {
  266. AnnotationContentViewModel viewModel = null;
  267. annotation = null;
  268. if (bOTAContentViewModel != null)
  269. {
  270. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  271. {
  272. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  273. foreach (var item in views)
  274. {
  275. if (item is AnnotationContent annotation1)
  276. {
  277. annotation = annotation1;
  278. viewModel = annotation1.DataContext as AnnotationContentViewModel;
  279. break;
  280. }
  281. }
  282. }
  283. }
  284. return viewModel;
  285. }
  286. /// <summary>
  287. /// 判断Bota的TabItem是否已显示
  288. /// </summary>
  289. /// <param name="bOTAContentViewModel"></param>
  290. /// <param name="bOTAContent"></param>
  291. /// <param name="tabItemText"></param>
  292. /// <returns></returns>
  293. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  294. {
  295. bool isTabItem = false;
  296. bOTAContentViewModel = null;
  297. bOTAContent = null;
  298. if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  299. {
  300. var views = region.Regions[viewContentViewModel.BOTARegionName].Views;
  301. var model = views.FirstOrDefault(q => q is BOTAContent);
  302. if (model is BOTAContent bOTAContent1)
  303. {
  304. bOTAContent = bOTAContent1;
  305. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  306. if (bOTAContentViewModel.CurrentBar == tabItemText)
  307. {
  308. isTabItem = true;
  309. }
  310. }
  311. }
  312. return isTabItem;
  313. }
  314. private void Select_Click(object sender, RoutedEventArgs e)
  315. {
  316. if (viewContentViewModel.OpenBOTA == false)
  317. {
  318. viewContentViewModel.OpenBOTA = true;
  319. }
  320. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  321. if (isBook == false)
  322. {
  323. bOTAContent.TabItemSearch.IsSelected = true;
  324. }
  325. }
  326. #endregion BOTA
  327. #region 阅读页右键菜单
  328. /// <summary>
  329. /// 空白处-右键菜单-添加注释
  330. /// </summary>
  331. /// <param name="sender"></param>
  332. private void AddAnnotation_Click(object sender)
  333. {
  334. if (sender is MenuItem menuItem)
  335. {
  336. AnnotHandlerEventArgs annotHandler = null;
  337. string str = menuItem.Tag.ToString();
  338. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  339. propertyPanel.IsAddLink = false;
  340. propertyPanel.IsLocationLink = false;
  341. if (str == AddAnnotType.AnnotFreehand.ToString())
  342. {
  343. annotHandler = GetFreehand();
  344. }
  345. if (str == AddAnnotType.AnnotFreeText.ToString())
  346. {
  347. annotHandler = GetFreetext();
  348. }
  349. if (str == AddAnnotType.AnnotSticky.ToString())
  350. {
  351. annotHandler = GetStickyNote();
  352. }
  353. if (str == AddAnnotType.AnnotSquare.ToString())
  354. {
  355. annotHandler = GetRect();
  356. }
  357. if (str == AddAnnotType.AnnotCircle.ToString())
  358. {
  359. annotHandler = GetCircle();
  360. }
  361. if (str == AddAnnotType.AnnotArrow.ToString())
  362. {
  363. annotHandler = GetArrowLine("Arrow");
  364. }
  365. if (str == AddAnnotType.AnnotLine.ToString())
  366. {
  367. annotHandler = GetArrowLine("Line");
  368. }
  369. if (str == AddAnnotType.AnnotLink.ToString())
  370. {
  371. propertyPanel.IsAddLink = true;
  372. annotHandler = GetLink();
  373. }
  374. if (str == AddAnnotType.AnnotStamp.ToString())
  375. {
  376. annotHandler = GetStamp();
  377. }
  378. if (str == AddAnnotType.AnnotAutograph.ToString())
  379. {
  380. annotHandler = GetSignature();
  381. }
  382. if (annotHandler != null)
  383. {
  384. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  385. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  386. PDFViewer.SetToolParam(annotHandler);
  387. //是否展开右侧面板 =>否(链接、图章、签名除外)
  388. ShowPropertyPanel(false);
  389. if (str == AddAnnotType.AnnotLink.ToString()
  390. || str == AddAnnotType.AnnotStamp.ToString()
  391. || str == AddAnnotType.AnnotAutograph.ToString()
  392. )
  393. {
  394. ShowPropertyPanel(true);
  395. }
  396. IsNoSelectMenu = true;
  397. }
  398. }
  399. }
  400. /// <summary>
  401. /// 选择文本、图片,右键菜单
  402. /// </summary>
  403. /// <param name="sender"></param>
  404. /// <param name="e"></param>
  405. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  406. {
  407. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  408. {
  409. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  410. switch (clickMenu.Tag.ToString())
  411. {
  412. case "HighLight"://字体高亮
  413. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  414. highlightArgs.ClientRect = annotCommand.TextRect;
  415. highlightArgs.Content = annotCommand.Text;
  416. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  417. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  418. PDFViewer.SetToolParam(highlightArgs);
  419. PDFViewer.SetMouseMode(MouseModes.PanTool);
  420. break;
  421. case "UnderLine"://下划线
  422. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  423. underlineArgs.ClientRect = annotCommand.TextRect;
  424. underlineArgs.Content = annotCommand.Text;
  425. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  426. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  427. PDFViewer.SetToolParam(underlineArgs);
  428. PDFViewer.SetMouseMode(MouseModes.PanTool);
  429. break;
  430. case "Strikeout"://删除线
  431. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  432. strikeoutArgs.ClientRect = annotCommand.TextRect;
  433. strikeoutArgs.Content = annotCommand.Text;
  434. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  435. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  436. PDFViewer.SetToolParam(strikeoutArgs);
  437. PDFViewer.SetMouseMode(MouseModes.PanTool);
  438. break;
  439. case "Freetext"://文本
  440. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  441. textArgs.ClientRect = annotCommand.TextRect;
  442. //textArgs.Transparency = 1;
  443. //textArgs.BgColor = Colors.Transparent;
  444. //textArgs.LineColor = Colors.Red;
  445. //textArgs.LineWidth = 2;
  446. textArgs.TextContent = annotCommand.Text;
  447. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  448. break;
  449. case "StickyNote"://便签
  450. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  451. //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  452. List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
  453. //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  454. Rect rect = annotCommand.TextRectList[0];
  455. #region to do 转dpi
  456. //int dpi = DpiHelpers.Dpi;
  457. //double x = rect.X / 72D * dpi;
  458. //double y = (rect.Y - rect.Height) / 72D * dpi;
  459. //double width = rect.Width / 72D * dpi;
  460. //double height = rect.Height / 72D * dpi;
  461. #endregion to do 转dpi
  462. //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
  463. //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
  464. stickyAnnotArgs.ClientRect = rect;
  465. //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  466. NavigationParameters param = new NavigationParameters();
  467. param.Add(ParameterNames.PDFViewer, PDFViewer);
  468. param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
  469. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  470. param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
  471. System.Windows.Controls.ContentControl window = null;
  472. if (PDFViewer.Parent as ContentControl != null)
  473. {
  474. window = PDFViewer.Parent as ContentControl;
  475. }
  476. else
  477. {
  478. window = App.Current.MainWindow;
  479. }
  480. var point = Mouse.GetPosition(window);
  481. viewContentViewModel.NotePopupVisible = Visibility.Visible;
  482. viewContentViewModel.CanvasNoteLeft = point.X;
  483. viewContentViewModel.CanvasNoteBottom = point.Y;
  484. if (point.Y > window.ActualHeight / 2)
  485. {
  486. viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
  487. }
  488. viewContentViewModel.IsNoteAdd = true;
  489. region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
  490. //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
  491. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  492. //PDFViewer.SetToolParam(stickyAnnotArgs);
  493. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  494. break;
  495. case "Rect"://矩形
  496. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  497. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  498. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  499. break;
  500. case "Circle"://圆
  501. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  502. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  503. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  504. break;
  505. case "Line"://线
  506. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  507. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  508. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  509. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  510. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  511. break;
  512. case "Link"://链接
  513. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  514. linkArgs.ClientRect = annotCommand.TextRect;
  515. linkArgs.URI = string.Empty;
  516. linkArgs.LinkType = LINK_TYPE.GOTO;
  517. linkArgs.DestIndex = annotCommand.PageIndex;
  518. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  519. //BtnLinkIsChecked = true;
  520. StrAnnotToolChecked = "Link";
  521. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  522. lists.Add(linkArgs);
  523. propertyPanel.IsAddLink = true;
  524. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  525. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  526. PDFViewer.SetToolParam(annotArgs);
  527. viewContentViewModel.IsPropertyOpen = true;
  528. break;
  529. case "OutLine":
  530. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  531. if (isTabItemAnnotation == false)
  532. {
  533. bOTAContent.TabItemOutLine.IsSelected = true;
  534. }
  535. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  536. if (outLineControlViewModel != null && outLineControl != null)
  537. {
  538. string str = null;
  539. if (!string.IsNullOrEmpty(annotCommand.Text))
  540. {
  541. str = annotCommand.Text;
  542. }
  543. #region 选择图片
  544. //if (string.IsNullOrEmpty(annotCommand.Text))
  545. //{
  546. // str = (annotCommand.PageIndex + 1).ToString();
  547. //}
  548. //else
  549. //{
  550. // str = annotCommand.Text;
  551. //}
  552. #endregion 选择图片
  553. outLineControl.AddOutlineNode(str);
  554. }
  555. break;
  556. case "ExportPicture":
  557. ExportPicture_MenuItemClick();
  558. break;
  559. }
  560. //ShowPropertyPanel(false);
  561. }
  562. }
  563. private void PageDisplay(ItemCollection items)
  564. {
  565. foreach (var item in items)
  566. {
  567. if (item is MenuItem menuItem)
  568. {
  569. menuItem.IsCheckable = false;
  570. menuItem.Click -= PageDisplay_Click;
  571. menuItem.Click += PageDisplay_Click;
  572. }
  573. }
  574. }
  575. private void PageDisplay_Click(object sender, RoutedEventArgs e)
  576. {
  577. if (sender is MenuItem menuItem)
  578. {
  579. switch (menuItem.Tag.ToString())
  580. {
  581. case "SingleView":
  582. PDFViewer.ChangeViewMode(ViewMode.Single);
  583. break;
  584. case "SingleContinueView":
  585. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  586. break;
  587. case "DoubleView":
  588. PDFViewer.ChangeViewMode(ViewMode.Double);
  589. break;
  590. case "DoubleContinueView":
  591. PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  592. break;
  593. case "BookMode":
  594. PDFViewer.ChangeViewMode(ViewMode.Book);
  595. break;
  596. }
  597. }
  598. }
  599. private void ViewZoom(ItemCollection items)
  600. {
  601. foreach (var item in items)
  602. {
  603. if (item is MenuItem menuItem)
  604. {
  605. //switch (PDFViewer.ModeFit)
  606. //{
  607. // case FitMode.FitWidth:
  608. // break;
  609. // case FitMode.FitHeight:
  610. // break;
  611. // case FitMode.FitSize:
  612. // break;
  613. // case FitMode.FitFree:
  614. // break;
  615. // default:
  616. // break;
  617. //}
  618. menuItem.IsCheckable = false;
  619. menuItem.Click -= ViewZoom_Click;
  620. menuItem.Click += ViewZoom_Click;
  621. }
  622. }
  623. }
  624. private void ViewZoom_Click(object sender, RoutedEventArgs e)
  625. {
  626. if (sender is MenuItem menuItem)
  627. {
  628. switch (menuItem.Tag.ToString())
  629. {
  630. case "FitWidth":
  631. PDFViewer.ChangeFitMode(FitMode.FitWidth);
  632. break;
  633. case "FitHeight":
  634. PDFViewer.ChangeFitMode(FitMode.FitHeight);
  635. break;
  636. case "FitSize":
  637. PDFViewer.ChangeFitMode(FitMode.FitSize);
  638. break;
  639. case "enlarge":
  640. double newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + 0.01), true);
  641. PDFViewer.Zoom(newZoom);
  642. break;
  643. case "narrow":
  644. newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + -0.01), false);
  645. PDFViewer.Zoom(newZoom);
  646. break;
  647. }
  648. }
  649. }
  650. private void UnReadModel_Click(object sender, RoutedEventArgs e)
  651. {
  652. viewContentViewModel.Off_ReadModel();
  653. }
  654. private void ReadModel_Click(object sender, RoutedEventArgs e)
  655. {
  656. viewContentViewModel.On_ReadMode();
  657. }
  658. private void SetToolMode(ItemCollection items)
  659. {
  660. foreach (var item in items)
  661. {
  662. if (item is MenuItem menuItem)
  663. {
  664. menuItem.IsCheckable = false;
  665. menuItem.Click -= ToolMode_Click;
  666. menuItem.Click += ToolMode_Click;
  667. }
  668. }
  669. }
  670. private void ToolMode_Click(object sender, RoutedEventArgs e)
  671. {
  672. if (sender is MenuItem menuItem)
  673. {
  674. switch (menuItem.Tag.ToString())
  675. {
  676. case "default":
  677. HandToolIsCheckedEvent(false);
  678. BtnHandIsChecked = false;
  679. ShowPropertyPanel(false);
  680. break;
  681. case "roll":
  682. HandToolIsCheckedEvent(true);
  683. BtnHandIsChecked = true;
  684. ShowPropertyPanel(false);
  685. break;
  686. case "content":
  687. AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
  688. BtnSelecttoolIsChecked = true;
  689. if (annotHandler != null)
  690. {
  691. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  692. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  693. PDFViewer.SetToolParam(annotHandler);
  694. ShowPropertyPanel(false);
  695. }
  696. break;
  697. default:
  698. break;
  699. }
  700. }
  701. }
  702. private void DelBookMark_Click(object sender, RoutedEventArgs e)
  703. {
  704. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  705. if (bOTAContentVM != null && bOTA != null)
  706. {
  707. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  708. int index = PDFViewer.CurrentIndex;
  709. //检测是否已存在相同数据
  710. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  711. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  712. {
  713. bookmarkContentViewModel.DeleteCommand.Execute(list);
  714. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  715. }
  716. }
  717. }
  718. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  719. {
  720. if (viewContentViewModel.OpenBOTA == false)
  721. {
  722. viewContentViewModel.OpenBOTA = true;
  723. }
  724. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  725. if (isBook == false)
  726. {
  727. bOTA.TabItemBookMark.IsSelected = true;
  728. }
  729. }
  730. private void AddBookMark_Click()
  731. {
  732. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  733. //if (viewContentViewModel.mainViewModel.IsBookMode)
  734. //{
  735. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  736. //}
  737. if (bOTAContentVM != null && bOTA != null)
  738. {
  739. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  740. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  741. {
  742. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  743. bookmark.BtnAddBookmark_Click(null, null);
  744. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  745. return;
  746. }
  747. }
  748. }
  749. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  750. {
  751. BookmarkContentViewModel viewModel = null;
  752. bookmark = null;
  753. if (bOTAContentViewModel != null)
  754. {
  755. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  756. {
  757. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  758. foreach (var item in views)
  759. {
  760. if (item is BookmarkContent bookmark1)
  761. {
  762. bookmark = bookmark1;
  763. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  764. break;
  765. }
  766. }
  767. }
  768. }
  769. return viewModel;
  770. }
  771. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  772. {
  773. OutLineControlViewModel viewModel = null;
  774. outLineControl = null;
  775. if (bOTAContentViewModel != null)
  776. {
  777. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  778. {
  779. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  780. foreach (var item in views)
  781. {
  782. if (item is OutLineControl outLineControl1)
  783. {
  784. outLineControl = outLineControl1;
  785. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  786. break;
  787. }
  788. }
  789. }
  790. }
  791. return viewModel;
  792. }
  793. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  794. {
  795. PDFViewer.SetDrawAnnot(true);
  796. BtnShowAnnotIsChecked = true;
  797. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  798. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  799. {
  800. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  801. viewModel.DisplayAnnot();
  802. }
  803. }
  804. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  805. {
  806. PDFViewer.SetDrawAnnot(false);
  807. BtnShowAnnotIsChecked = false;
  808. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  809. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  810. {
  811. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  812. viewModel.HiddenAnnot();
  813. }
  814. }
  815. private void SetAddAnnotation(ItemCollection items)
  816. {
  817. foreach (var item in items)
  818. {
  819. if (item is MenuItem menuItem)
  820. {
  821. string str = menuItem.Tag.ToString();
  822. //if (str == AddAnnotType.AnnotLink.ToString()
  823. //|| str == AddAnnotType.AnnotStamp.ToString()
  824. //|| str == AddAnnotType.AnnotAutograph.ToString()
  825. //)
  826. //{
  827. // InBookModeSetIsEnabled(menuItem);
  828. //}
  829. menuItem.CommandParameter = item;
  830. menuItem.Command = SetAddAnnotationCommand;
  831. }
  832. }
  833. }
  834. //private void AddLink_Click(object sender, RoutedEventArgs e)
  835. //{
  836. // var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  837. // BtnLinkIsChecked = true;
  838. //}
  839. #endregion 阅读页右键菜单
  840. #region 注释右键菜单事件
  841. //高亮、下划线、删除
  842. private void HightAnnotCopyText_Menu(object obj)
  843. {
  844. if (obj as CusMenuItem != null)
  845. {
  846. var menu = obj as CusMenuItem;
  847. var annot = menu.Parameter as AnnotHandlerEventArgs;
  848. if (annot != null)
  849. {
  850. System.Windows.Clipboard.SetText(annot.Content);
  851. }
  852. }
  853. }
  854. //更改为当前注释属性默认值
  855. private void AnnotDefaultValues_Menu(object obj)
  856. {
  857. if (obj as CusMenuItem != null)
  858. {
  859. var menu = obj as CusMenuItem;
  860. var annot = menu.Parameter as AnnotHandlerEventArgs;
  861. if (annot != null)
  862. {
  863. if (annot is TextHighlightAnnotArgs)
  864. {
  865. var color = (annot as TextHighlightAnnotArgs).Color;
  866. HighLightColor = new SolidColorBrush(color);
  867. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  868. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  869. hightlight.ForgoundColor = color;
  870. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  871. SettingHelper.SetAnnotDefaultProperty(hightlight);
  872. }
  873. else if (annot is TextUnderlineAnnotArgs)
  874. {
  875. var color = (annot as TextUnderlineAnnotArgs).Color;
  876. UnderLineColor = new SolidColorBrush(color);
  877. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  878. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  879. Underline.ForgoundColor = color;
  880. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  881. SettingHelper.SetAnnotDefaultProperty(Underline);
  882. }
  883. else if (annot is TextStrikeoutAnnotArgs)
  884. {
  885. var color = (annot as TextStrikeoutAnnotArgs).Color;
  886. StrikeoutColor = new SolidColorBrush(color);
  887. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  888. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  889. Strikeout.ForgoundColor = color;
  890. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  891. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  892. }
  893. else if (annot is FreehandAnnotArgs)
  894. {
  895. var freeHand = annot as FreehandAnnotArgs;
  896. var color = freeHand.InkColor;
  897. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  898. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  899. FreehandDefault.ForgoundColor = color;
  900. FreehandDefault.Opacity = freeHand.Transparency;
  901. FreehandDefault.Thickness = freeHand.LineWidth;
  902. var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  903. if (isSolid)
  904. {
  905. FreehandDefault.DashArray = null;
  906. }
  907. else
  908. {
  909. FreehandDefault.DashArray = new List<double>();
  910. foreach (var item in freeHand.LineDash.Dashes)
  911. {
  912. FreehandDefault.DashArray.Add(item);
  913. }
  914. }
  915. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  916. }
  917. else if (annot is FreeTextAnnotArgs)
  918. {
  919. var freeText = annot as FreeTextAnnotArgs;
  920. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  921. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  922. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  923. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  924. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  925. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  926. FreeTextDefalut.TextAlign = freeText.Align;
  927. FreeTextDefalut.FontSize = freeText.FontSize;
  928. FreeTextDefalut.FontWeight = freeText.FontWeight;
  929. FreeTextDefalut.FontStyle = freeText.FontStyle;
  930. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  931. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  932. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  933. FreeTextAnnotArgs freeTextAnnotArgs = new FreeTextAnnotArgs()
  934. {
  935. FontColor = freeText.FontColor,
  936. FontFamily = freeText.FontFamily,
  937. Align = freeText.Align,
  938. FontSize = freeText.FontSize,
  939. FontWeight = freeText.FontWeight,
  940. FontStyle = freeText.FontStyle,
  941. BgColor = freeText.BgColor,
  942. Transparency = (annot as FreeTextAnnotArgs).Transparency
  943. };
  944. PDFViewer.SetToolParam(freeTextAnnotArgs);
  945. }
  946. else if (annot is StickyAnnotArgs)
  947. {
  948. var color = (annot as StickyAnnotArgs).Color;
  949. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  950. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  951. StickyDefalut.ForgoundColor = color;
  952. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  953. }
  954. else if (annot is SquareAnnotArgs)
  955. {
  956. var square = annot as SquareAnnotArgs;
  957. var bgColor = square.BgColor;
  958. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  959. var borderColor = square.LineColor;
  960. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  961. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  962. SquareDefalut.BorderColor = borderColor;
  963. SquareDefalut.BackgroundColor = bgColor;
  964. SquareDefalut.Opacity = square.Transparency;
  965. SquareDefalut.Thickness = square.LineWidth;
  966. var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
  967. if (isSolid)
  968. {
  969. SquareDefalut.DashArray = null;
  970. }
  971. else
  972. {
  973. SquareDefalut.DashArray = new List<double>();
  974. foreach (var item in square.LineDash.Dashes)
  975. {
  976. SquareDefalut.DashArray.Add(item);
  977. }
  978. }
  979. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  980. }
  981. else if (annot is CircleAnnotArgs)
  982. {
  983. var circle = annot as CircleAnnotArgs;
  984. var bgColor = circle.BgColor;
  985. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  986. var borderColor = circle.LineColor;
  987. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  988. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  989. CircleDefalut.BorderColor = borderColor;
  990. CircleDefalut.BackgroundColor = bgColor;
  991. CircleDefalut.Opacity = circle.Transparency;
  992. CircleDefalut.Thickness = circle.LineWidth;
  993. var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
  994. if (isSolid)
  995. {
  996. CircleDefalut.DashArray = null;
  997. }
  998. else
  999. {
  1000. CircleDefalut.DashArray = new List<double>();
  1001. foreach (var item in circle.LineDash.Dashes)
  1002. {
  1003. CircleDefalut.DashArray.Add(item);
  1004. }
  1005. }
  1006. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1007. }
  1008. else if (annot is LineAnnotArgs)
  1009. {
  1010. var line = (annot as LineAnnotArgs);
  1011. var color = (annot as LineAnnotArgs).LineColor;
  1012. Settings.Default.AppProperties.Annotate.LineColor = color;
  1013. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1014. lineDefalut.BorderColor = color;
  1015. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1016. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1017. var isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
  1018. if (isSolid)
  1019. {
  1020. lineDefalut.DashArray = null;
  1021. }
  1022. else
  1023. {
  1024. lineDefalut.DashArray = new List<double>();
  1025. foreach (var item in line.LineDash.Dashes)
  1026. {
  1027. lineDefalut.DashArray.Add(item);
  1028. }
  1029. }
  1030. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1031. }
  1032. Settings.Default.Save();
  1033. }
  1034. }
  1035. }
  1036. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1037. {
  1038. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1039. if (Annot == null)
  1040. {
  1041. Annot = new DefaultAnnotProperty();
  1042. Annot.AnnotToolType = annotArgsType;
  1043. }
  1044. return Annot;
  1045. }
  1046. private System.Windows.Controls.Primitives.Popup popup = null;
  1047. //更改颜色
  1048. private async void AnnotColorPalette_Menu(object obj)
  1049. {
  1050. if (obj as CusMenuItem != null)
  1051. {
  1052. var menu = obj as CusMenuItem;
  1053. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1054. if (annot != null)
  1055. {
  1056. var item = new ColorDropBoxPop();
  1057. item.DataContext = menu;
  1058. item.ColorSelected -= AnnotMenu_ColorSelected;
  1059. item.ColorSelected += AnnotMenu_ColorSelected;
  1060. if (popup == null)
  1061. popup = new System.Windows.Controls.Primitives.Popup();
  1062. ContentControl window = null;
  1063. if (PDFViewer.Parent as ContentControl != null)
  1064. window = PDFViewer.Parent as ContentControl;
  1065. else
  1066. window = App.Current.MainWindow;
  1067. popup.Child = item;
  1068. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1069. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1070. popup.PlacementTarget = window;
  1071. popup.IsOpen = true;
  1072. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1073. if (parentWnd != null)
  1074. {
  1075. parentWnd.MouseDown -= parentWnd_MouseDown;
  1076. parentWnd.MouseDown += parentWnd_MouseDown;
  1077. }
  1078. while (popup.IsOpen)
  1079. await Task.Delay(20);
  1080. parentWnd.MouseDown -= parentWnd_MouseDown;
  1081. popup = null;
  1082. }
  1083. }
  1084. }
  1085. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1086. {
  1087. var ui = Mouse.DirectlyOver as FrameworkElement;
  1088. if (ui != null)
  1089. {
  1090. if (popup != null)
  1091. {
  1092. popup.IsOpen = false;
  1093. }
  1094. }
  1095. }
  1096. private void AnnotMenu_ColorSelected(object sender, Color e)
  1097. {
  1098. if (sender != null)
  1099. {
  1100. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1101. if (menu == null) return;
  1102. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1103. if (annot != null)
  1104. {
  1105. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1106. {
  1107. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1108. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1109. AnnotEvent?.UpdateAnnot();
  1110. }
  1111. else if (annot is FreeTextAnnotArgs)
  1112. {
  1113. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1114. if (menu.tag.ToString() == "FontColor")
  1115. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1116. else
  1117. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1118. AnnotEvent?.UpdateAnnot();
  1119. }
  1120. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1121. {
  1122. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1123. if (menu.tag.ToString() == "FillColor")
  1124. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1125. else
  1126. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1127. AnnotEvent?.UpdateAnnot();
  1128. }
  1129. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1130. {
  1131. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1132. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1133. AnnotEvent?.UpdateAnnot();
  1134. }
  1135. }
  1136. }
  1137. }
  1138. //添加笔记
  1139. private void AnnotAddNoteText_Menu(object obj)
  1140. {
  1141. if (obj as CusMenuItem != null)
  1142. {
  1143. var menu = obj as CusMenuItem;
  1144. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1145. PopAnnotNoteText(annot);
  1146. }
  1147. }
  1148. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1149. {
  1150. if (annot != null)
  1151. {
  1152. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1153. args.ClientRect = annot.ClientRect;
  1154. args.AnnotHandlerEventArgs = annot;
  1155. args.PageIndex = annot.PageIndex;
  1156. args.AnnotIndex = annot.AnnotIndex;
  1157. args.EventType = annot.EventType;
  1158. args.CreateTime = annot.CreateTime;
  1159. args.UpdateTime = annot.UpdateTime;
  1160. args.Content = annot.Content;
  1161. args.MarkupContent = annot.MarkupContent;
  1162. args.Author = annot.Author;
  1163. args.Locked = annot.Locked;
  1164. args.ReadOnly = annot.ReadOnly;
  1165. args.FormField = annot.FormField;
  1166. args.Document = PDFViewer.Document;
  1167. DialogParameters value = new DialogParameters();
  1168. value.Add(ParameterNames.Annotation, args);
  1169. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1170. {
  1171. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1172. {
  1173. PDFViewer.UndoManager.CanSave = true;
  1174. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1175. {
  1176. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  1177. //RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  1178. events.GetEvent<RefreshAnnotEvent>().Publish(new RefreshAnnotArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = annotation });
  1179. }
  1180. }
  1181. });
  1182. }
  1183. }
  1184. //手绘
  1185. private void FreeHandLineStyle_Menu(object obj)
  1186. {
  1187. if (obj as CusMenuItem != null)
  1188. {
  1189. var menu = obj as CusMenuItem;
  1190. var annot = menu.Parameter as FreehandAnnotArgs;
  1191. if (annot != null)
  1192. {
  1193. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1194. if (menu.tag.ToString() == "Solid")
  1195. {
  1196. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
  1197. }
  1198. else
  1199. {
  1200. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
  1201. }
  1202. AnnotEvent?.UpdateAnnot();
  1203. }
  1204. }
  1205. }
  1206. //文本
  1207. private void FreeTextFontFamily_Menu(object obj)
  1208. {
  1209. if (obj as CusMenuItem != null)
  1210. {
  1211. var menu = obj as CusMenuItem;
  1212. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1213. if (annot != null)
  1214. {
  1215. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1216. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1217. AnnotEvent?.UpdateAnnot();
  1218. }
  1219. }
  1220. }
  1221. private void FreeTextAglin_Menu(object obj)
  1222. {
  1223. if (obj as CusMenuItem != null)
  1224. {
  1225. var menu = obj as CusMenuItem;
  1226. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1227. var tag = menu.control.Tag;
  1228. if (annot != null && tag != null)
  1229. {
  1230. var strTag = tag.ToString();
  1231. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1232. if (strTag == "Left")
  1233. {
  1234. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1235. }
  1236. else if (strTag == "Center")
  1237. {
  1238. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1239. }
  1240. else if (strTag == "Right")
  1241. {
  1242. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1243. }
  1244. else if (strTag == "Justify")
  1245. {
  1246. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1247. }
  1248. AnnotEvent?.UpdateAnnot();
  1249. }
  1250. }
  1251. }
  1252. //便签
  1253. private void StrikeNoteEditStrike_Menu(object obj)
  1254. {
  1255. if (obj as CusMenuItem != null)
  1256. {
  1257. var menu = obj as CusMenuItem;
  1258. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1259. if (annot != null)
  1260. {
  1261. var sticky = annot as StickyAnnotArgs;
  1262. sticky.PopupEditWnd();
  1263. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1264. //isRightMenuAddAnnot = false;
  1265. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1266. }
  1267. }
  1268. }
  1269. //形状
  1270. private void ShapeLineStyle_Menu(object obj)
  1271. {
  1272. if (obj as CusMenuItem != null)
  1273. {
  1274. var menu = obj as CusMenuItem;
  1275. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1276. var tag = menu.control.Tag;
  1277. if (annot != null && tag != null)
  1278. {
  1279. var strTag = tag.ToString();
  1280. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1281. if (strTag == "Solid")
  1282. {
  1283. var dashStyle = AnnotTransfer.GetLineDashStyle(true);
  1284. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1285. }
  1286. else
  1287. {
  1288. var dashStyle = AnnotTransfer.GetLineDashStyle(false);
  1289. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1290. }
  1291. AnnotEvent?.UpdateAnnot();
  1292. }
  1293. }
  1294. }
  1295. private void ShapeLineDirect_Menu(object obj)
  1296. {
  1297. if (obj as CusMenuItem != null)
  1298. {
  1299. var menu = obj as CusMenuItem;
  1300. var annot = menu.Parameter as LineAnnotArgs;
  1301. var tag = menu.control.Tag;
  1302. if (annot != null && tag != null)
  1303. {
  1304. var strTag = tag.ToString();
  1305. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1306. if (strTag == "Ver")
  1307. {
  1308. annot.SetLineVertical();
  1309. }
  1310. else
  1311. {
  1312. annot.SetLineHorizontal();
  1313. }
  1314. }
  1315. }
  1316. }
  1317. private void Link_Menu(object obj)
  1318. {
  1319. if (obj is CusMenuItem menuItem)
  1320. {
  1321. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1322. {
  1323. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1324. if (result)
  1325. {
  1326. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1327. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1328. if (isTabItemAnnotation)
  1329. {
  1330. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1331. if (viewModel != null)
  1332. {
  1333. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. }
  1340. //图章
  1341. private void StampExportPicture_Menu(object obj)
  1342. {
  1343. if (obj as CusMenuItem != null)
  1344. {
  1345. var menu = obj as CusMenuItem;
  1346. var annot = menu.Parameter as StampAnnotArgs;
  1347. if (annot != null)
  1348. {
  1349. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1350. var format = menu.tag.ToString();
  1351. if (format == "PDF")
  1352. dlg.Filter = "PDF|*.pdf";
  1353. else
  1354. dlg.Filter = format + "|*." + format.ToLower();
  1355. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1356. dlg.FileName = PDFViewer.Document.FileName;
  1357. if (dlg.ShowDialog() == true)
  1358. {
  1359. var stampPicture = dlg.FileName;
  1360. if (menu.tag.ToString() == "PDF")
  1361. {
  1362. var writeStamp = annot.GetStampDrawing();
  1363. var tempDoc = new CPDFViewer();
  1364. tempDoc.CreateDocument();
  1365. if (tempDoc.Document == null)
  1366. {
  1367. AlertsMessage alertsMessage = new AlertsMessage();
  1368. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1369. return;
  1370. }
  1371. byte[] buffer;
  1372. var encoder = new PngBitmapEncoder();
  1373. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1374. using (var memoryStream = new MemoryStream())
  1375. {
  1376. encoder.Save(memoryStream);
  1377. buffer = memoryStream.ToArray();
  1378. }
  1379. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1380. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1381. if (result)
  1382. {
  1383. }
  1384. }
  1385. else
  1386. {
  1387. var writeStamp = annot.GetStampDrawing();
  1388. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1389. {
  1390. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1391. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1392. encoder5.Save(stream5);
  1393. }
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. #endregion 注释右键菜单事件
  1400. #region 快捷键
  1401. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1402. {
  1403. if (KeyEventsHelper.IsSingleKey(Key.Escape))
  1404. {
  1405. //BtnHandIsChecked = true;
  1406. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1407. PDFViewer.ClearSelectAnnots();
  1408. StrAnnotToolChecked = "";
  1409. ShowPropertyPanel(false);
  1410. }
  1411. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  1412. {
  1413. //按住Shift等比缩放
  1414. }
  1415. AnnotToolCtrlAltKey();
  1416. }
  1417. /// <summary>
  1418. /// 按下Ctrl + Alt + 序列键,响应注释工具
  1419. /// </summary>
  1420. private void AnnotToolCtrlAltKey()
  1421. {
  1422. var tuple = GetCtrlAltKey();
  1423. if (tuple != null)
  1424. {
  1425. if (tuple.Item1 == Key.L)
  1426. BtnLinkIsChecked = false;
  1427. if (tuple.Item2 == "Eraser")
  1428. {
  1429. CreateEraseArgs();
  1430. StrAnnotToolChecked = "Freehand";
  1431. return;
  1432. }
  1433. AnnotHandlerEventArgs annotArgs = null;
  1434. StrAnnotToolChecked = tuple.Item2;
  1435. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  1436. if (annotArgs != null)
  1437. {
  1438. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1439. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1440. PDFViewer.SetToolParam(annotArgs);
  1441. PDFViewer.ToolManager.EnableClickCreate = false;
  1442. }
  1443. }
  1444. }
  1445. private Tuple<Key, string> GetCtrlAltKey()
  1446. {
  1447. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  1448. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  1449. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  1450. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  1451. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  1452. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  1453. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  1454. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  1455. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  1456. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  1457. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  1458. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  1459. Key key = Key.None;
  1460. foreach (var item in AnnotToolDir.Keys)
  1461. {
  1462. if (AnnotToolDir[item] == true)
  1463. {
  1464. key = item;
  1465. break;
  1466. }
  1467. }
  1468. if (key == Key.None)
  1469. return null;
  1470. var tag = "";
  1471. if (key == Key.H || key == Key.U || key == Key.S)
  1472. {
  1473. var str = PDFViewer.GetSelectedText();
  1474. if (string.IsNullOrEmpty(str) == false)
  1475. {
  1476. if (key == Key.H)
  1477. tag = "HighLight";
  1478. else if (key == Key.U)
  1479. tag = "UnderLine";
  1480. else if (key == Key.S)
  1481. tag = "Strikeout";
  1482. }
  1483. else
  1484. {
  1485. return null;
  1486. }
  1487. }
  1488. else
  1489. {
  1490. if (AnnotToolDir[Key.P])
  1491. tag = "Freehand";
  1492. else if (AnnotToolDir[Key.T])
  1493. tag = "Freetext";
  1494. else if (AnnotToolDir[Key.N])
  1495. tag = "StickyNote";
  1496. else if (AnnotToolDir[Key.R])
  1497. tag = "Rect";
  1498. else if (AnnotToolDir[Key.O])
  1499. tag = "Circle";
  1500. else if (AnnotToolDir[Key.A])
  1501. tag = "Arrow";
  1502. else if (AnnotToolDir[Key.L])
  1503. tag = "Line";
  1504. else if (AnnotToolDir[Key.E])
  1505. tag = "Eraser";
  1506. }
  1507. if (tag == "")
  1508. return null;
  1509. return new Tuple<Key, string>(key, tag);
  1510. }
  1511. #endregion 快捷键
  1512. #region Navigation
  1513. public bool IsNavigationTarget(NavigationContext navigationContext)
  1514. {
  1515. return true;
  1516. }
  1517. public void OnNavigatedFrom(NavigationContext navigationContext)
  1518. {
  1519. StrAnnotToolChecked = "";
  1520. UnBindingPDFViewerHandler();
  1521. UnBindingEvent();
  1522. }
  1523. public void OnNavigatedTo(NavigationContext navigationContext)
  1524. {
  1525. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1526. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1527. if (viewContentViewModel != null)
  1528. {
  1529. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  1530. }
  1531. BindingPDFViewerHandler();
  1532. BindingEvent();
  1533. LoaedStickyNotePopup();
  1534. //获取当前是否为滚动状态
  1535. // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  1536. BtnHandIsChecked = false;
  1537. HandToolIsCheckedEvent(false);
  1538. }
  1539. #endregion Navigation
  1540. }
  1541. }