AnnotToolContentViewModel.cs 77 KB

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