AnnotToolContentViewModel.cs 84 KB

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