AnnotToolContentViewModel.cs 72 KB

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