AnnotToolContentViewModel.cs 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422
  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. //ShowPropertyPanel(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. }
  1951. }
  1952. else
  1953. {
  1954. //避免编辑功能ESC快捷键冲突
  1955. if (PDFViewer.MouseMode != MouseModes.PDFEdit)
  1956. {
  1957. ExitAnnotationTool();
  1958. }
  1959. }
  1960. }
  1961. }
  1962. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  1963. {
  1964. //按住Shift等比缩放
  1965. }
  1966. else if (e.Key == Key.F && e.KeyboardDevice.Modifiers == ModifierKeys.Control)
  1967. {
  1968. if (ViewContentViewModel.OpenBOTA == false)
  1969. {
  1970. ViewContentViewModel.OpenBOTA = true;
  1971. }
  1972. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1973. if (isBook == false)
  1974. {
  1975. bOTAContent.TabItemSearch.IsSelected = true;
  1976. }
  1977. }
  1978. AnnotToolCtrlAltKey();
  1979. }
  1980. private void UnStickyNote(StickyNoteArgs obj)
  1981. {
  1982. if (PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1983. {
  1984. if (PDFViewer.ToolManager != null && PDFViewer.ToolManager.CurrentAnnotArgs != null)
  1985. {
  1986. if (string.IsNullOrEmpty(obj.Text))
  1987. {
  1988. PDFViewer.RemoveTool(false);
  1989. }
  1990. else
  1991. {
  1992. }
  1993. }
  1994. }
  1995. }
  1996. public void ExitAnnotationTool(bool isShow = true)
  1997. {
  1998. if (isShow)
  1999. {
  2000. ViewContentViewModel.IsReadModeShow = false;
  2001. ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  2002. ShowPropertyPanel(false);
  2003. }
  2004. else
  2005. {
  2006. ViewContentViewModel.IsReadModeShow = true;
  2007. }
  2008. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2009. var annotArgs = new SelectToolArgs();
  2010. PDFViewer.SetToolParam(annotArgs);
  2011. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  2012. PDFViewer.DisableClearSelectAnnot(false);
  2013. PDFViewer.ClearSelectAnnots();
  2014. StrAnnotToolChecked = "";
  2015. BtnHandIsChecked = false;
  2016. }
  2017. /// <summary>
  2018. /// 按下Ctrl + Alt + 序列键,响应注释工具
  2019. /// </summary>
  2020. private void AnnotToolCtrlAltKey()
  2021. {
  2022. var tuple = GetCtrlAltKey();
  2023. if (tuple != null && PDFViewer != null)
  2024. {
  2025. //进入快捷键时清除选中
  2026. PDFViewer.ClearSelectAnnots();
  2027. if (tuple.Item1 == Key.L)
  2028. BtnLinkIsChecked = false;
  2029. if (tuple.Item2 == "Eraser")
  2030. {
  2031. CreateEraseArgs();
  2032. StrAnnotToolChecked = "Freehand";
  2033. return;
  2034. }
  2035. AnnotHandlerEventArgs annotArgs = null;
  2036. //注释 快捷键 第一次选中对应的,第二次取消选中
  2037. if (StrAnnotToolChecked == tuple.Item2)
  2038. {
  2039. StrAnnotToolChecked = "";
  2040. UncheckAnnot();
  2041. }
  2042. else
  2043. {
  2044. StrAnnotToolChecked = tuple.Item2;
  2045. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  2046. if (annotArgs != null && tuple.Item2 != "Stamp")
  2047. {
  2048. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  2049. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2050. PDFViewer.SetToolParam(annotArgs);
  2051. PDFViewer.ToolManager.EnableClickCreate = false;
  2052. }
  2053. else
  2054. {
  2055. //2023/4/6 设置Stamp刚进入时点击view出现空的选中方框
  2056. //PDFViewer.SetMouseMode(MouseModes.None);
  2057. //解决 注释 工具 图章,不选中注释的bug
  2058. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2059. PDFViewer.SetToolParam(new SelectToolArgs());
  2060. }
  2061. }
  2062. }
  2063. }
  2064. private Tuple<Key, string> GetCtrlAltKey()
  2065. {
  2066. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  2067. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  2068. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  2069. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  2070. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  2071. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  2072. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  2073. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  2074. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  2075. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  2076. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  2077. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  2078. Key key = Key.None;
  2079. foreach (var item in AnnotToolDir.Keys)
  2080. {
  2081. if (AnnotToolDir[item] == true)
  2082. {
  2083. key = item;
  2084. break;
  2085. }
  2086. }
  2087. if (key == Key.None)
  2088. return null;
  2089. var tag = "";
  2090. if (key == Key.H || key == Key.U || key == Key.S)
  2091. {
  2092. //判断是否选中文字
  2093. //var str = PDFViewer.GetSelectedText();
  2094. //if (string.IsNullOrEmpty(str) == false)
  2095. {
  2096. if (key == Key.H)
  2097. tag = "HighLight";
  2098. else if (key == Key.U)
  2099. tag = "UnderLine";
  2100. else if (key == Key.S)
  2101. tag = "Strikeout";
  2102. }
  2103. //else
  2104. //{
  2105. // return null;
  2106. //}
  2107. }
  2108. else
  2109. {
  2110. if (AnnotToolDir[Key.P])
  2111. tag = "Freehand";
  2112. else if (AnnotToolDir[Key.T])
  2113. tag = "Freetext";
  2114. else if (AnnotToolDir[Key.N])
  2115. tag = "StickyNote";
  2116. else if (AnnotToolDir[Key.R])
  2117. tag = "RectKey";
  2118. else if (AnnotToolDir[Key.O])
  2119. tag = "Circle";
  2120. else if (AnnotToolDir[Key.A])
  2121. tag = "Arrow";
  2122. else if (AnnotToolDir[Key.L])
  2123. tag = "Line";
  2124. else if (AnnotToolDir[Key.E])
  2125. tag = "Eraser";
  2126. }
  2127. if (tag == "")
  2128. return null;
  2129. return new Tuple<Key, string>(key, tag);
  2130. }
  2131. #endregion 快捷键
  2132. #region Navigation
  2133. public bool IsNavigationTarget(NavigationContext navigationContext)
  2134. {
  2135. return true;
  2136. }
  2137. public void OnNavigatedFrom(NavigationContext navigationContext)
  2138. {
  2139. StrAnnotToolChecked = "";
  2140. //UnBindingPDFViewerHandler();
  2141. //UnBindingEvent();
  2142. }
  2143. public void OnNavigatedTo(NavigationContext navigationContext)
  2144. {
  2145. //链接 框 的 样式
  2146. SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(50, 23, 112, 244));
  2147. SolidColorBrush solidColorPen = new SolidColorBrush(System.Windows.Media.Color.FromRgb(23, 112, 244));
  2148. CommonDrawData.LinkPen = new System.Windows.Media.Pen(solidColorPen, 0);
  2149. CommonDrawData.LinkBrush = solidColorBrush;
  2150. CommonDrawData.LinkAreaSelectPen = new System.Windows.Media.Pen(solidColorBrush, 0);
  2151. CommonDrawData.LinkAreaSelectBrush = solidColorBrush;
  2152. ViewContentViewModel viewModel;
  2153. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewModel);
  2154. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  2155. ViewContentViewModel = viewModel;
  2156. if (ViewContentViewModel != null)
  2157. {
  2158. OpenFileInfo = ViewContentViewModel.OpenFileInfo;
  2159. ViewContentViewModel.PropertyChanged -= ViewContentViewModel_PropertyChanged;
  2160. ViewContentViewModel.PropertyChanged += ViewContentViewModel_PropertyChanged;
  2161. }
  2162. if (PDFViewer != null)
  2163. {
  2164. BindingPDFViewerHandler();
  2165. BindingEvent();
  2166. LoaedStickyNotePopup();
  2167. //获取当前是否为滚动状态
  2168. // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  2169. BtnHandIsChecked = false;
  2170. HandToolIsCheckedEvent(false);
  2171. }
  2172. }
  2173. #endregion Navigation
  2174. }
  2175. }