AnnotToolContentViewModel.cs 74 KB

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