AnnotToolContentViewModel.cs 105 KB

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