AnnotToolContentViewModel.cs 102 KB

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