AnnotToolContentViewModel.cs 105 KB

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