AnnotToolContentViewModel.cs 77 KB

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