AnnotToolContentViewModel.cs 98 KB

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