AnnotToolContentViewModel.cs 79 KB

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