AnnotToolContentViewModel.cs 101 KB

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