AnnotToolContentViewModel.cs 100 KB

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