AnnotToolContentViewModel.cs 79 KB

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