AnnotToolContentViewModel.cs 100 KB

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