AnnotToolContentViewModel.cs 80 KB

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