AnnotToolContentViewModel.cs 89 KB

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