AnnotToolContentViewModel.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  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. StrAnnotToolChecked = "";
  679. PDFViewer.SetMouseMode(MouseModes.PanTool);
  680. HandToolIsCheckedEvent(false);
  681. BtnHandIsChecked = false;
  682. ShowPropertyPanel(false);
  683. break;
  684. case "roll":
  685. StrAnnotToolChecked = "";
  686. HandToolIsCheckedEvent(true);
  687. BtnHandIsChecked = true;
  688. ShowPropertyPanel(false);
  689. break;
  690. case "content":
  691. AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
  692. BtnSelecttoolIsChecked = true;
  693. if (annotHandler != null)
  694. {
  695. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  696. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  697. PDFViewer.SetToolParam(annotHandler);
  698. ShowPropertyPanel(false);
  699. }
  700. break;
  701. default:
  702. break;
  703. }
  704. }
  705. }
  706. private void DelBookMark_Click(object sender, RoutedEventArgs e)
  707. {
  708. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  709. if (bOTAContentVM != null && bOTA != null)
  710. {
  711. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  712. int index = PDFViewer.CurrentIndex;
  713. //检测是否已存在相同数据
  714. if (PDFViewer.Document == null) return;
  715. if (PDFViewer.Document.GetBookmarkList().Count <= 0) return;
  716. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  717. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  718. {
  719. bookmarkContentViewModel.DeleteCommand.Execute(list);
  720. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  721. }
  722. }
  723. }
  724. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  725. {
  726. if (viewContentViewModel.OpenBOTA == false)
  727. {
  728. viewContentViewModel.OpenBOTA = true;
  729. }
  730. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  731. if (isBook == false)
  732. {
  733. bOTA.TabItemBookMark.IsSelected = true;
  734. }
  735. }
  736. private void AddBookMark_Click()
  737. {
  738. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  739. //if (viewContentViewModel.mainViewModel.IsBookMode)
  740. //{
  741. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  742. //}
  743. if (bOTAContentVM != null && bOTA != null)
  744. {
  745. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  746. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  747. {
  748. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  749. bookmark.BtnAddBookmark_Click(null, null);
  750. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  751. return;
  752. }
  753. }
  754. }
  755. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  756. {
  757. BookmarkContentViewModel viewModel = null;
  758. bookmark = null;
  759. if (bOTAContentViewModel != null)
  760. {
  761. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  762. {
  763. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  764. foreach (var item in views)
  765. {
  766. if (item is BookmarkContent bookmark1)
  767. {
  768. bookmark = bookmark1;
  769. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  770. break;
  771. }
  772. }
  773. }
  774. }
  775. return viewModel;
  776. }
  777. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  778. {
  779. OutLineControlViewModel viewModel = null;
  780. outLineControl = null;
  781. if (bOTAContentViewModel != null)
  782. {
  783. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  784. {
  785. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  786. foreach (var item in views)
  787. {
  788. if (item is OutLineControl outLineControl1)
  789. {
  790. outLineControl = outLineControl1;
  791. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  792. break;
  793. }
  794. }
  795. }
  796. }
  797. return viewModel;
  798. }
  799. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  800. {
  801. PDFViewer.SetDrawAnnot(true);
  802. BtnShowAnnotIsChecked = true;
  803. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  804. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  805. {
  806. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  807. viewModel.DisplayAnnot();
  808. }
  809. }
  810. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  811. {
  812. PDFViewer.SetDrawAnnot(false);
  813. BtnShowAnnotIsChecked = false;
  814. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  815. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  816. {
  817. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  818. viewModel.HiddenAnnot();
  819. }
  820. }
  821. private void SetAddAnnotation(ItemCollection items)
  822. {
  823. foreach (var item in items)
  824. {
  825. if (item is MenuItem menuItem)
  826. {
  827. string str = menuItem.Tag.ToString();
  828. //if (str == AddAnnotType.AnnotLink.ToString()
  829. //|| str == AddAnnotType.AnnotStamp.ToString()
  830. //|| str == AddAnnotType.AnnotAutograph.ToString()
  831. //)
  832. //{
  833. // InBookModeSetIsEnabled(menuItem);
  834. //}
  835. menuItem.CommandParameter = item;
  836. menuItem.Command = SetAddAnnotationCommand;
  837. }
  838. }
  839. }
  840. //private void AddLink_Click(object sender, RoutedEventArgs e)
  841. //{
  842. // var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  843. // BtnLinkIsChecked = true;
  844. //}
  845. #endregion 阅读页右键菜单
  846. #region 注释右键菜单事件
  847. //高亮、下划线、删除
  848. private void HightAnnotCopyText_Menu(object obj)
  849. {
  850. if (obj as CusMenuItem != null)
  851. {
  852. var menu = obj as CusMenuItem;
  853. var annot = menu.Parameter as AnnotHandlerEventArgs;
  854. if (annot != null)
  855. {
  856. System.Windows.Clipboard.SetText(annot.Content);
  857. }
  858. }
  859. }
  860. //更改为当前注释属性默认值
  861. private void AnnotDefaultValues_Menu(object obj)
  862. {
  863. if (obj as CusMenuItem != null)
  864. {
  865. var menu = obj as CusMenuItem;
  866. var annot = menu.Parameter as AnnotHandlerEventArgs;
  867. if (annot != null)
  868. {
  869. if (annot is TextHighlightAnnotArgs)
  870. {
  871. var color = (annot as TextHighlightAnnotArgs).Color;
  872. HighLightColor = new SolidColorBrush(color);
  873. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  874. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  875. hightlight.ForgoundColor = color;
  876. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  877. SettingHelper.SetAnnotDefaultProperty(hightlight);
  878. }
  879. else if (annot is TextUnderlineAnnotArgs)
  880. {
  881. var color = (annot as TextUnderlineAnnotArgs).Color;
  882. UnderLineColor = new SolidColorBrush(color);
  883. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  884. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  885. Underline.ForgoundColor = color;
  886. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  887. SettingHelper.SetAnnotDefaultProperty(Underline);
  888. }
  889. else if (annot is TextStrikeoutAnnotArgs)
  890. {
  891. var color = (annot as TextStrikeoutAnnotArgs).Color;
  892. StrikeoutColor = new SolidColorBrush(color);
  893. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  894. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  895. Strikeout.ForgoundColor = color;
  896. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  897. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  898. }
  899. else if (annot is FreehandAnnotArgs)
  900. {
  901. var freeHand = annot as FreehandAnnotArgs;
  902. var color = freeHand.InkColor;
  903. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  904. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  905. FreehandDefault.ForgoundColor = color;
  906. FreehandDefault.Opacity = freeHand.Transparency;
  907. FreehandDefault.Thickness = freeHand.LineWidth;
  908. var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  909. if (isSolid)
  910. {
  911. FreehandDefault.DashArray = null;
  912. }
  913. else
  914. {
  915. FreehandDefault.DashArray = new List<double>();
  916. foreach (var item in freeHand.LineDash.Dashes)
  917. {
  918. FreehandDefault.DashArray.Add(item);
  919. }
  920. }
  921. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  922. }
  923. else if (annot is FreeTextAnnotArgs)
  924. {
  925. var freeText = annot as FreeTextAnnotArgs;
  926. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  927. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  928. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  929. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  930. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  931. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  932. FreeTextDefalut.TextAlign = freeText.Align;
  933. FreeTextDefalut.FontSize = freeText.FontSize;
  934. FreeTextDefalut.FontWeight = freeText.FontWeight;
  935. FreeTextDefalut.FontStyle = freeText.FontStyle;
  936. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  937. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  938. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  939. FreeTextAnnotArgs freeTextAnnotArgs = new FreeTextAnnotArgs()
  940. {
  941. FontColor = freeText.FontColor,
  942. FontFamily = freeText.FontFamily,
  943. Align = freeText.Align,
  944. FontSize = freeText.FontSize,
  945. FontWeight = freeText.FontWeight,
  946. FontStyle = freeText.FontStyle,
  947. BgColor = freeText.BgColor,
  948. Transparency = (annot as FreeTextAnnotArgs).Transparency
  949. };
  950. PDFViewer.SetToolParam(freeTextAnnotArgs);
  951. }
  952. else if (annot is StickyAnnotArgs)
  953. {
  954. var color = (annot as StickyAnnotArgs).Color;
  955. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  956. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  957. StickyDefalut.ForgoundColor = color;
  958. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  959. }
  960. else if (annot is SquareAnnotArgs)
  961. {
  962. var square = annot as SquareAnnotArgs;
  963. var bgColor = square.BgColor;
  964. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  965. var borderColor = square.LineColor;
  966. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  967. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  968. SquareDefalut.BorderColor = borderColor;
  969. SquareDefalut.BackgroundColor = bgColor;
  970. SquareDefalut.Opacity = square.Transparency;
  971. SquareDefalut.Thickness = square.LineWidth;
  972. var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
  973. if (isSolid)
  974. {
  975. SquareDefalut.DashArray = null;
  976. }
  977. else
  978. {
  979. SquareDefalut.DashArray = new List<double>();
  980. foreach (var item in square.LineDash.Dashes)
  981. {
  982. SquareDefalut.DashArray.Add(item);
  983. }
  984. }
  985. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  986. }
  987. else if (annot is CircleAnnotArgs)
  988. {
  989. var circle = annot as CircleAnnotArgs;
  990. var bgColor = circle.BgColor;
  991. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  992. var borderColor = circle.LineColor;
  993. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  994. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  995. CircleDefalut.BorderColor = borderColor;
  996. CircleDefalut.BackgroundColor = bgColor;
  997. CircleDefalut.Opacity = circle.Transparency;
  998. CircleDefalut.Thickness = circle.LineWidth;
  999. var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
  1000. if (isSolid)
  1001. {
  1002. CircleDefalut.DashArray = null;
  1003. }
  1004. else
  1005. {
  1006. CircleDefalut.DashArray = new List<double>();
  1007. foreach (var item in circle.LineDash.Dashes)
  1008. {
  1009. CircleDefalut.DashArray.Add(item);
  1010. }
  1011. }
  1012. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1013. }
  1014. else if (annot is LineAnnotArgs)
  1015. {
  1016. var line = (annot as LineAnnotArgs);
  1017. var color = (annot as LineAnnotArgs).LineColor;
  1018. Settings.Default.AppProperties.Annotate.LineColor = color;
  1019. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1020. lineDefalut.BorderColor = color;
  1021. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1022. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1023. var isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
  1024. if (isSolid)
  1025. {
  1026. lineDefalut.DashArray = null;
  1027. }
  1028. else
  1029. {
  1030. lineDefalut.DashArray = new List<double>();
  1031. foreach (var item in line.LineDash.Dashes)
  1032. {
  1033. lineDefalut.DashArray.Add(item);
  1034. }
  1035. }
  1036. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1037. }
  1038. Settings.Default.Save();
  1039. }
  1040. }
  1041. }
  1042. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1043. {
  1044. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1045. if (Annot == null)
  1046. {
  1047. Annot = new DefaultAnnotProperty();
  1048. Annot.AnnotToolType = annotArgsType;
  1049. }
  1050. return Annot;
  1051. }
  1052. private System.Windows.Controls.Primitives.Popup popup = null;
  1053. //更改颜色
  1054. private async void AnnotColorPalette_Menu(object obj)
  1055. {
  1056. if (obj as CusMenuItem != null)
  1057. {
  1058. var menu = obj as CusMenuItem;
  1059. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1060. if (annot != null)
  1061. {
  1062. var item = new ColorDropBoxPop();
  1063. item.DataContext = menu;
  1064. item.ColorSelected -= AnnotMenu_ColorSelected;
  1065. item.ColorSelected += AnnotMenu_ColorSelected;
  1066. if (popup == null)
  1067. popup = new System.Windows.Controls.Primitives.Popup();
  1068. ContentControl window = null;
  1069. if (PDFViewer.Parent as ContentControl != null)
  1070. window = PDFViewer.Parent as ContentControl;
  1071. else
  1072. window = App.Current.MainWindow;
  1073. popup.Child = item;
  1074. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1075. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1076. popup.PlacementTarget = window;
  1077. popup.IsOpen = true;
  1078. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1079. if (parentWnd != null)
  1080. {
  1081. parentWnd.MouseDown -= parentWnd_MouseDown;
  1082. parentWnd.MouseDown += parentWnd_MouseDown;
  1083. }
  1084. while (popup.IsOpen)
  1085. await Task.Delay(20);
  1086. parentWnd.MouseDown -= parentWnd_MouseDown;
  1087. popup = null;
  1088. }
  1089. }
  1090. }
  1091. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1092. {
  1093. var ui = Mouse.DirectlyOver as FrameworkElement;
  1094. if (ui != null)
  1095. {
  1096. if (popup != null)
  1097. {
  1098. popup.IsOpen = false;
  1099. }
  1100. }
  1101. }
  1102. private void AnnotMenu_ColorSelected(object sender, Color e)
  1103. {
  1104. if (sender != null)
  1105. {
  1106. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1107. if (menu == null) return;
  1108. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1109. if (annot != null)
  1110. {
  1111. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1112. {
  1113. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1114. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1115. AnnotEvent?.UpdateAnnot();
  1116. }
  1117. else if (annot is FreeTextAnnotArgs)
  1118. {
  1119. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1120. if (menu.tag.ToString() == "FontColor")
  1121. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1122. else
  1123. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1124. AnnotEvent?.UpdateAnnot();
  1125. }
  1126. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1127. {
  1128. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1129. if (menu.tag.ToString() == "FillColor")
  1130. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1131. else
  1132. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1133. AnnotEvent?.UpdateAnnot();
  1134. }
  1135. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1136. {
  1137. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1138. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1139. AnnotEvent?.UpdateAnnot();
  1140. }
  1141. }
  1142. }
  1143. }
  1144. //添加笔记
  1145. private void AnnotAddNoteText_Menu(object obj)
  1146. {
  1147. if (obj as CusMenuItem != null)
  1148. {
  1149. var menu = obj as CusMenuItem;
  1150. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1151. PopAnnotNoteText(annot);
  1152. }
  1153. }
  1154. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1155. {
  1156. if (annot != null)
  1157. {
  1158. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1159. args.ClientRect = annot.ClientRect;
  1160. args.AnnotHandlerEventArgs = annot;
  1161. args.PageIndex = annot.PageIndex;
  1162. args.AnnotIndex = annot.AnnotIndex;
  1163. args.EventType = annot.EventType;
  1164. args.CreateTime = annot.CreateTime;
  1165. args.UpdateTime = annot.UpdateTime;
  1166. args.Content = annot.Content;
  1167. args.MarkupContent = annot.MarkupContent;
  1168. args.Author = annot.Author;
  1169. args.Locked = annot.Locked;
  1170. args.ReadOnly = annot.ReadOnly;
  1171. args.FormField = annot.FormField;
  1172. args.Document = PDFViewer.Document;
  1173. DialogParameters value = new DialogParameters();
  1174. value.Add(ParameterNames.Annotation, args);
  1175. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1176. {
  1177. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1178. {
  1179. PDFViewer.UndoManager.CanSave = true;
  1180. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1181. {
  1182. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  1183. //RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  1184. events.GetEvent<RefreshAnnotEvent>().Publish(new RefreshAnnotArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = annotation });
  1185. }
  1186. }
  1187. });
  1188. }
  1189. }
  1190. //手绘
  1191. private void FreeHandLineStyle_Menu(object obj)
  1192. {
  1193. if (obj as CusMenuItem != null)
  1194. {
  1195. var menu = obj as CusMenuItem;
  1196. var annot = menu.Parameter as FreehandAnnotArgs;
  1197. if (annot != null)
  1198. {
  1199. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1200. if (menu.tag.ToString() == "Solid")
  1201. {
  1202. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
  1203. }
  1204. else
  1205. {
  1206. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
  1207. }
  1208. AnnotEvent?.UpdateAnnot();
  1209. }
  1210. }
  1211. }
  1212. //文本
  1213. private void FreeTextFontFamily_Menu(object obj)
  1214. {
  1215. if (obj as CusMenuItem != null)
  1216. {
  1217. var menu = obj as CusMenuItem;
  1218. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1219. if (annot != null)
  1220. {
  1221. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1222. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1223. AnnotEvent?.UpdateAnnot();
  1224. }
  1225. }
  1226. }
  1227. private void FreeTextAglin_Menu(object obj)
  1228. {
  1229. if (obj as CusMenuItem != null)
  1230. {
  1231. var menu = obj as CusMenuItem;
  1232. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1233. var tag = menu.control.Tag;
  1234. if (annot != null && tag != null)
  1235. {
  1236. var strTag = tag.ToString();
  1237. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1238. if (strTag == "Left")
  1239. {
  1240. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1241. }
  1242. else if (strTag == "Center")
  1243. {
  1244. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1245. }
  1246. else if (strTag == "Right")
  1247. {
  1248. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1249. }
  1250. else if (strTag == "Justify")
  1251. {
  1252. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1253. }
  1254. AnnotEvent?.UpdateAnnot();
  1255. }
  1256. }
  1257. }
  1258. //便签
  1259. private void StrikeNoteEditStrike_Menu(object obj)
  1260. {
  1261. if (obj as CusMenuItem != null)
  1262. {
  1263. var menu = obj as CusMenuItem;
  1264. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1265. if (annot != null)
  1266. {
  1267. var sticky = annot as StickyAnnotArgs;
  1268. sticky.PopupEditWnd();
  1269. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1270. //isRightMenuAddAnnot = false;
  1271. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1272. }
  1273. }
  1274. }
  1275. //形状
  1276. private void ShapeLineStyle_Menu(object obj)
  1277. {
  1278. if (obj as CusMenuItem != null)
  1279. {
  1280. var menu = obj as CusMenuItem;
  1281. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1282. var tag = menu.control.Tag;
  1283. if (annot != null && tag != null)
  1284. {
  1285. var strTag = tag.ToString();
  1286. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1287. if (strTag == "Solid")
  1288. {
  1289. var dashStyle = AnnotTransfer.GetLineDashStyle(true);
  1290. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1291. }
  1292. else
  1293. {
  1294. var dashStyle = AnnotTransfer.GetLineDashStyle(false);
  1295. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1296. }
  1297. AnnotEvent?.UpdateAnnot();
  1298. }
  1299. }
  1300. }
  1301. private void ShapeLineDirect_Menu(object obj)
  1302. {
  1303. if (obj as CusMenuItem != null)
  1304. {
  1305. var menu = obj as CusMenuItem;
  1306. var annot = menu.Parameter as LineAnnotArgs;
  1307. var tag = menu.control.Tag;
  1308. if (annot != null && tag != null)
  1309. {
  1310. var strTag = tag.ToString();
  1311. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1312. if (strTag == "Ver")
  1313. {
  1314. annot.SetLineVertical();
  1315. }
  1316. else
  1317. {
  1318. annot.SetLineHorizontal();
  1319. }
  1320. }
  1321. }
  1322. }
  1323. private void Link_Menu(object obj)
  1324. {
  1325. if (obj is CusMenuItem menuItem)
  1326. {
  1327. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1328. {
  1329. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1330. if (result)
  1331. {
  1332. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1333. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1334. if (isTabItemAnnotation)
  1335. {
  1336. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1337. if (viewModel != null)
  1338. {
  1339. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. //图章
  1347. private void StampExportPicture_Menu(object obj)
  1348. {
  1349. if (obj as CusMenuItem != null)
  1350. {
  1351. var menu = obj as CusMenuItem;
  1352. var annot = menu.Parameter as StampAnnotArgs;
  1353. if (annot != null)
  1354. {
  1355. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1356. var format = menu.tag.ToString();
  1357. if (format == "PDF")
  1358. dlg.Filter = "PDF|*.pdf";
  1359. else
  1360. dlg.Filter = format + "|*." + format.ToLower();
  1361. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1362. dlg.FileName = PDFViewer.Document.FileName;
  1363. if (dlg.ShowDialog() == true)
  1364. {
  1365. var stampPicture = dlg.FileName;
  1366. if (menu.tag.ToString() == "PDF")
  1367. {
  1368. var writeStamp = annot.GetStampDrawing();
  1369. var tempDoc = new CPDFViewer();
  1370. tempDoc.CreateDocument();
  1371. if (tempDoc.Document == null)
  1372. {
  1373. AlertsMessage alertsMessage = new AlertsMessage();
  1374. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1375. return;
  1376. }
  1377. byte[] buffer;
  1378. var encoder = new PngBitmapEncoder();
  1379. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1380. using (var memoryStream = new MemoryStream())
  1381. {
  1382. encoder.Save(memoryStream);
  1383. buffer = memoryStream.ToArray();
  1384. }
  1385. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1386. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1387. if (result)
  1388. {
  1389. }
  1390. }
  1391. else
  1392. {
  1393. var writeStamp = annot.GetStampDrawing();
  1394. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1395. {
  1396. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1397. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1398. encoder5.Save(stream5);
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. #endregion 注释右键菜单事件
  1406. #region 快捷键
  1407. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1408. {
  1409. if (KeyEventsHelper.IsSingleKey(Key.Escape))
  1410. {
  1411. //BtnHandIsChecked = true;
  1412. PDFViewer.ClearSelectAnnots();
  1413. StrAnnotToolChecked = "";
  1414. //ShowPropertyPanel(false);
  1415. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1416. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1417. HandToolIsCheckedEvent(false);
  1418. BtnHandIsChecked = false;
  1419. ShowPropertyPanel(false);
  1420. }
  1421. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  1422. {
  1423. //按住Shift等比缩放
  1424. }
  1425. AnnotToolCtrlAltKey();
  1426. }
  1427. /// <summary>
  1428. /// 按下Ctrl + Alt + 序列键,响应注释工具
  1429. /// </summary>
  1430. private void AnnotToolCtrlAltKey()
  1431. {
  1432. var tuple = GetCtrlAltKey();
  1433. if (tuple != null)
  1434. {
  1435. if (tuple.Item1 == Key.L)
  1436. BtnLinkIsChecked = false;
  1437. if (tuple.Item2 == "Eraser")
  1438. {
  1439. CreateEraseArgs();
  1440. StrAnnotToolChecked = "Freehand";
  1441. return;
  1442. }
  1443. AnnotHandlerEventArgs annotArgs = null;
  1444. StrAnnotToolChecked = tuple.Item2;
  1445. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  1446. if (annotArgs != null)
  1447. {
  1448. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1449. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1450. PDFViewer.SetToolParam(annotArgs);
  1451. PDFViewer.ToolManager.EnableClickCreate = false;
  1452. }
  1453. }
  1454. }
  1455. private Tuple<Key, string> GetCtrlAltKey()
  1456. {
  1457. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  1458. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  1459. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  1460. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  1461. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  1462. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  1463. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  1464. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  1465. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  1466. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  1467. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  1468. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  1469. Key key = Key.None;
  1470. foreach (var item in AnnotToolDir.Keys)
  1471. {
  1472. if (AnnotToolDir[item] == true)
  1473. {
  1474. key = item;
  1475. break;
  1476. }
  1477. }
  1478. if (key == Key.None)
  1479. return null;
  1480. var tag = "";
  1481. if (key == Key.H || key == Key.U || key == Key.S)
  1482. {
  1483. var str = PDFViewer.GetSelectedText();
  1484. if (string.IsNullOrEmpty(str) == false)
  1485. {
  1486. if (key == Key.H)
  1487. tag = "HighLight";
  1488. else if (key == Key.U)
  1489. tag = "UnderLine";
  1490. else if (key == Key.S)
  1491. tag = "Strikeout";
  1492. }
  1493. else
  1494. {
  1495. return null;
  1496. }
  1497. }
  1498. else
  1499. {
  1500. if (AnnotToolDir[Key.P])
  1501. tag = "Freehand";
  1502. else if (AnnotToolDir[Key.T])
  1503. tag = "Freetext";
  1504. else if (AnnotToolDir[Key.N])
  1505. tag = "StickyNote";
  1506. else if (AnnotToolDir[Key.R])
  1507. tag = "Rect";
  1508. else if (AnnotToolDir[Key.O])
  1509. tag = "Circle";
  1510. else if (AnnotToolDir[Key.A])
  1511. tag = "Arrow";
  1512. else if (AnnotToolDir[Key.L])
  1513. tag = "Line";
  1514. else if (AnnotToolDir[Key.E])
  1515. tag = "Eraser";
  1516. }
  1517. if (tag == "")
  1518. return null;
  1519. return new Tuple<Key, string>(key, tag);
  1520. }
  1521. #endregion 快捷键
  1522. #region Navigation
  1523. public bool IsNavigationTarget(NavigationContext navigationContext)
  1524. {
  1525. return true;
  1526. }
  1527. public void OnNavigatedFrom(NavigationContext navigationContext)
  1528. {
  1529. StrAnnotToolChecked = "";
  1530. //UnBindingPDFViewerHandler();
  1531. //UnBindingEvent();
  1532. }
  1533. public void OnNavigatedTo(NavigationContext navigationContext)
  1534. {
  1535. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1536. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1537. if (viewContentViewModel != null)
  1538. {
  1539. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  1540. }
  1541. BindingPDFViewerHandler();
  1542. BindingEvent();
  1543. LoaedStickyNotePopup();
  1544. //获取当前是否为滚动状态
  1545. // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  1546. BtnHandIsChecked = false;
  1547. HandToolIsCheckedEvent(false);
  1548. }
  1549. #endregion Navigation
  1550. }
  1551. }