AnnotToolContentViewModel.cs 82 KB

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