AnnotToolContentViewModel.cs 78 KB

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