AnnotToolContentViewModel.cs 81 KB

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