AnnotToolContentViewModel.cs 90 KB

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