AnnotToolContentViewModel.cs 79 KB

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