AnnotToolContentViewModel.cs 83 KB

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