AnnotToolContentViewModel.cs 104 KB

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