AnnotToolContentViewModel.cs 73 KB

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