AnnotToolContentViewModel.cs 82 KB

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