AnnotToolContentViewModel.cs 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  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 (bOTAContentVM != null && bOTA != null)
  796. {
  797. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  798. int index = PDFViewer.CurrentIndex;
  799. //检测是否已存在相同数据
  800. if (PDFViewer.Document == null) return;
  801. if (PDFViewer.Document.GetBookmarkList().Count <= 0) return;
  802. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  803. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  804. {
  805. bookmarkContentViewModel.DeleteCommand.Execute(list);
  806. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  807. }
  808. }
  809. }
  810. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  811. {
  812. if (viewContentViewModel.OpenBOTA == false)
  813. {
  814. viewContentViewModel.OpenBOTA = true;
  815. }
  816. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  817. if (isBook == false)
  818. {
  819. bOTA.TabItemBookMark.IsSelected = true;
  820. }
  821. }
  822. private void AddBookMark_Click()
  823. {
  824. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  825. //if (viewContentViewModel.mainViewModel.IsBookMode)
  826. //{
  827. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  828. //}
  829. if (bOTAContentVM != null && bOTA != null)
  830. {
  831. AddBookMark(bOTAContentVM, bOTA);
  832. }
  833. //if (viewContentViewModel.mainViewModel.IsBookMode)
  834. //{
  835. // AddBookMark(bOTAContentVM, bOTA);
  836. //}
  837. }
  838. private void AddBookMark(BOTAContentViewModel bOTAContentVM, BOTAContent bOTA)
  839. {
  840. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  841. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  842. {
  843. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  844. bookmark.BtnAddBookmark_Click(null, null);
  845. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  846. return;
  847. }
  848. }
  849. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  850. {
  851. BookmarkContentViewModel viewModel = null;
  852. bookmark = null;
  853. if (bOTAContentViewModel != null)
  854. {
  855. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  856. {
  857. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  858. foreach (var item in views)
  859. {
  860. if (item is BookmarkContent bookmark1)
  861. {
  862. bookmark = bookmark1;
  863. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  864. break;
  865. }
  866. }
  867. }
  868. }
  869. return viewModel;
  870. }
  871. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  872. {
  873. OutLineControlViewModel viewModel = null;
  874. outLineControl = null;
  875. if (bOTAContentViewModel != null)
  876. {
  877. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  878. {
  879. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  880. foreach (var item in views)
  881. {
  882. if (item is OutLineControl outLineControl1)
  883. {
  884. outLineControl = outLineControl1;
  885. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  886. break;
  887. }
  888. }
  889. }
  890. }
  891. return viewModel;
  892. }
  893. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  894. {
  895. PDFViewer.SetDrawAnnot(true);
  896. PDFViewer.ReloadVisibleAnnots();
  897. BtnShowAnnotIsChecked = true;
  898. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  899. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  900. {
  901. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  902. viewModel.DisplayAnnot();
  903. }
  904. }
  905. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  906. {
  907. PDFViewer.ClearSelectAnnots();
  908. PDFViewer.SetDrawAnnot(false);
  909. PDFViewer.ReloadVisibleAnnots();
  910. BtnShowAnnotIsChecked = false;
  911. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  912. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  913. {
  914. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  915. viewModel.HiddenAnnot();
  916. }
  917. }
  918. private void SetAddAnnotation(ItemCollection items)
  919. {
  920. var separator = items[items.Count - 4];
  921. InBookModeSetIsHidden(separator);
  922. foreach (var item in items)
  923. {
  924. if (item is MenuItem menuItem)
  925. {
  926. string str = menuItem.Tag.ToString();
  927. if (str == AddAnnotType.AnnotLink.ToString()
  928. || str == AddAnnotType.AnnotStamp.ToString()
  929. || str == AddAnnotType.AnnotAutograph.ToString()
  930. )
  931. {
  932. InBookModeSetIsHidden(menuItem);
  933. }
  934. menuItem.CommandParameter = item;
  935. menuItem.Command = SetAddAnnotationCommand;
  936. }
  937. }
  938. }
  939. //private void AddLink_Click(object sender, RoutedEventArgs e)
  940. //{
  941. // var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  942. // BtnLinkIsChecked = true;
  943. //}
  944. #endregion 阅读页右键菜单
  945. #region 注释右键菜单事件
  946. //高亮、下划线、删除
  947. private void HightAnnotCopyText_Menu(object obj)
  948. {
  949. if (obj as CusMenuItem != null)
  950. {
  951. var menu = obj as CusMenuItem;
  952. var annot = menu.Parameter as AnnotHandlerEventArgs;
  953. if (annot != null)
  954. {
  955. System.Windows.Clipboard.SetText(annot.Content);
  956. }
  957. }
  958. }
  959. /// <summary>
  960. /// 更改为当前注释属性默认值
  961. /// </summary>
  962. /// <param name="obj"></param>
  963. private void AnnotDefaultValues_Menu(object obj)
  964. {
  965. if (obj as CusMenuItem != null)
  966. {
  967. var menu = obj as CusMenuItem;
  968. var annot = menu.Parameter as AnnotHandlerEventArgs;
  969. if (annot != null)
  970. {
  971. if (annot is TextHighlightAnnotArgs)
  972. {
  973. var color = (annot as TextHighlightAnnotArgs).Color;
  974. HighLightColor = new SolidColorBrush(color);
  975. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  976. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  977. hightlight.ForgoundColor = color;
  978. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  979. SettingHelper.SetAnnotDefaultProperty(hightlight);
  980. }
  981. else if (annot is TextUnderlineAnnotArgs)
  982. {
  983. var color = (annot as TextUnderlineAnnotArgs).Color;
  984. UnderLineColor = new SolidColorBrush(color);
  985. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  986. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  987. Underline.ForgoundColor = color;
  988. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  989. SettingHelper.SetAnnotDefaultProperty(Underline);
  990. }
  991. else if (annot is TextStrikeoutAnnotArgs)
  992. {
  993. var color = (annot as TextStrikeoutAnnotArgs).Color;
  994. StrikeoutColor = new SolidColorBrush(color);
  995. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  996. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  997. Strikeout.ForgoundColor = color;
  998. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  999. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  1000. }
  1001. else if (annot is FreehandAnnotArgs)
  1002. {
  1003. var freeHand = annot as FreehandAnnotArgs;
  1004. var color = freeHand.InkColor;
  1005. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  1006. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  1007. FreehandDefault.ForgoundColor = color;
  1008. FreehandDefault.Opacity = freeHand.Transparency;
  1009. FreehandDefault.Thickness = freeHand.LineWidth;
  1010. var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  1011. if (isSolid)
  1012. {
  1013. FreehandDefault.DashArray = null;
  1014. }
  1015. else
  1016. {
  1017. FreehandDefault.DashArray = new List<double>();
  1018. foreach (var item in freeHand.LineDash.Dashes)
  1019. {
  1020. FreehandDefault.DashArray.Add(item);
  1021. }
  1022. }
  1023. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  1024. FreehandAnnotArgs annotArgs = new FreehandAnnotArgs()
  1025. {
  1026. InkColor = freeHand.InkColor,
  1027. Transparency = freeHand.Transparency,
  1028. LineWidth = freeHand.LineWidth,
  1029. LineDash = freeHand.LineDash
  1030. };
  1031. PDFViewer.SetToolParam(annotArgs);
  1032. }
  1033. else if (annot is FreeTextAnnotArgs freeText)
  1034. {
  1035. //var freeText = annot as FreeTextAnnotArgs;
  1036. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  1037. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  1038. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  1039. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  1040. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  1041. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  1042. FreeTextDefalut.TextAlign = freeText.Align;
  1043. FreeTextDefalut.FontSize = freeText.FontSize;
  1044. FreeTextDefalut.FontWeight = freeText.FontWeight;
  1045. FreeTextDefalut.FontStyle = freeText.FontStyle;
  1046. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  1047. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  1048. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  1049. //FreeTextAnnotArgs freeTextAnnotArgs = new FreeTextAnnotArgs()
  1050. //{
  1051. // FontColor = freeText.FontColor,
  1052. // FontFamily = freeText.FontFamily,
  1053. // Align = freeText.Align,
  1054. // FontSize = freeText.FontSize,
  1055. // FontWeight = freeText.FontWeight,
  1056. // FontStyle = freeText.FontStyle,
  1057. // BgColor = freeText.BgColor,
  1058. // Transparency = (annot as FreeTextAnnotArgs).Transparency
  1059. //};
  1060. //PDFViewer.SetToolParam(freeTextAnnotArgs);
  1061. }
  1062. else if (annot is StickyAnnotArgs)
  1063. {
  1064. var color = (annot as StickyAnnotArgs).Color;
  1065. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  1066. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  1067. StickyDefalut.ForgoundColor = color;
  1068. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  1069. }
  1070. else if (annot is SquareAnnotArgs)
  1071. {
  1072. var square = annot as SquareAnnotArgs;
  1073. var bgColor = square.BgColor;
  1074. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  1075. var borderColor = square.LineColor;
  1076. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  1077. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  1078. SquareDefalut.BorderColor = borderColor;
  1079. SquareDefalut.BackgroundColor = bgColor;
  1080. SquareDefalut.Opacity = square.Transparency;
  1081. SquareDefalut.Thickness = square.LineWidth;
  1082. var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
  1083. if (isSolid)
  1084. {
  1085. SquareDefalut.DashArray = null;
  1086. }
  1087. else
  1088. {
  1089. SquareDefalut.DashArray = new List<double>();
  1090. foreach (var item in square.LineDash.Dashes)
  1091. {
  1092. SquareDefalut.DashArray.Add(item);
  1093. }
  1094. }
  1095. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  1096. }
  1097. else if (annot is CircleAnnotArgs)
  1098. {
  1099. var circle = annot as CircleAnnotArgs;
  1100. var bgColor = circle.BgColor;
  1101. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  1102. var borderColor = circle.LineColor;
  1103. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  1104. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  1105. CircleDefalut.BorderColor = borderColor;
  1106. CircleDefalut.BackgroundColor = bgColor;
  1107. CircleDefalut.Opacity = circle.Transparency;
  1108. CircleDefalut.Thickness = circle.LineWidth;
  1109. var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
  1110. if (isSolid)
  1111. {
  1112. CircleDefalut.DashArray = null;
  1113. }
  1114. else
  1115. {
  1116. CircleDefalut.DashArray = new List<double>();
  1117. foreach (var item in circle.LineDash.Dashes)
  1118. {
  1119. CircleDefalut.DashArray.Add(item);
  1120. }
  1121. }
  1122. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1123. }
  1124. else if (annot is LineAnnotArgs lineAnnotArgs)
  1125. {
  1126. var color = lineAnnotArgs.LineColor;
  1127. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1128. //箭头
  1129. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1130. {
  1131. Settings.Default.AppProperties.Annotate.ArrowColor = color;
  1132. lineDefalut.HeadLineType = lineAnnotArgs.HeadLineType;
  1133. lineDefalut.TailLineType = lineAnnotArgs.TailLineType;
  1134. }
  1135. else
  1136. {
  1137. Settings.Default.AppProperties.Annotate.LineColor = color;
  1138. }
  1139. lineDefalut.BorderColor = color;
  1140. lineDefalut.Opacity = lineAnnotArgs.Transparency;
  1141. lineDefalut.Thickness = lineAnnotArgs.LineWidth;
  1142. var isSolid = AnnotTransfer.IsSolidStyle(lineAnnotArgs.LineDash);
  1143. if (isSolid)
  1144. {
  1145. lineDefalut.DashArray = null;
  1146. }
  1147. else
  1148. {
  1149. lineDefalut.DashArray = new List<double>();
  1150. foreach (var item in lineAnnotArgs.LineDash.Dashes)
  1151. {
  1152. lineDefalut.DashArray.Add(item);
  1153. }
  1154. }
  1155. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1156. }
  1157. Settings.Default.Save();
  1158. PropertyPanel.annot = annot;
  1159. PropertyPanel.SaveLastAnnot();
  1160. }
  1161. }
  1162. }
  1163. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1164. {
  1165. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1166. if (Annot == null)
  1167. {
  1168. Annot = new DefaultAnnotProperty();
  1169. Annot.AnnotToolType = annotArgsType;
  1170. }
  1171. return Annot;
  1172. }
  1173. private System.Windows.Controls.Primitives.Popup popup = null;
  1174. //更改颜色
  1175. private async void AnnotColorPalette_Menu(object obj)
  1176. {
  1177. if (obj as CusMenuItem != null)
  1178. {
  1179. var menu = obj as CusMenuItem;
  1180. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1181. if (annot != null)
  1182. {
  1183. var item = new ColorDropBoxPop();
  1184. item.DataContext = menu;
  1185. item.ColorSelected -= AnnotMenu_ColorSelected;
  1186. item.ColorSelected += AnnotMenu_ColorSelected;
  1187. if (popup == null)
  1188. popup = new System.Windows.Controls.Primitives.Popup();
  1189. ContentControl window = null;
  1190. if (PDFViewer.Parent as ContentControl != null)
  1191. window = PDFViewer.Parent as ContentControl;
  1192. else
  1193. window = App.Current.MainWindow;
  1194. popup.Child = item;
  1195. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1196. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1197. popup.PlacementTarget = window;
  1198. popup.IsOpen = true;
  1199. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1200. if (parentWnd != null)
  1201. {
  1202. parentWnd.MouseDown -= parentWnd_MouseDown;
  1203. parentWnd.MouseDown += parentWnd_MouseDown;
  1204. }
  1205. while (popup.IsOpen)
  1206. await Task.Delay(20);
  1207. parentWnd.MouseDown -= parentWnd_MouseDown;
  1208. popup = null;
  1209. }
  1210. }
  1211. }
  1212. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1213. {
  1214. var ui = Mouse.DirectlyOver as FrameworkElement;
  1215. if (ui != null)
  1216. {
  1217. if (popup != null)
  1218. {
  1219. popup.IsOpen = false;
  1220. }
  1221. }
  1222. }
  1223. private void AnnotMenu_ColorSelected(object sender, Color e)
  1224. {
  1225. if (sender != null)
  1226. {
  1227. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1228. if (menu == null) return;
  1229. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1230. if (annot != null)
  1231. {
  1232. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1233. {
  1234. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1235. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1236. AnnotEvent?.UpdateAnnot();
  1237. }
  1238. else if (annot is FreeTextAnnotArgs)
  1239. {
  1240. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1241. if (menu.tag.ToString() == "FontColor")
  1242. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1243. else
  1244. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1245. AnnotEvent?.UpdateAnnot();
  1246. }
  1247. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1248. {
  1249. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1250. if (menu.tag.ToString() == "FillColor")
  1251. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1252. else
  1253. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1254. AnnotEvent?.UpdateAnnot();
  1255. }
  1256. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1257. {
  1258. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1259. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1260. AnnotEvent?.UpdateAnnot();
  1261. }
  1262. }
  1263. }
  1264. }
  1265. //添加笔记
  1266. private void AnnotAddNoteText_Menu(object obj)
  1267. {
  1268. if (obj as CusMenuItem != null)
  1269. {
  1270. var menu = obj as CusMenuItem;
  1271. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1272. PopAnnotNoteText(annot);
  1273. }
  1274. }
  1275. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1276. {
  1277. if (annot != null)
  1278. {
  1279. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1280. args.ClientRect = annot.ClientRect;
  1281. args.AnnotHandlerEventArgs = annot;
  1282. args.PageIndex = annot.PageIndex;
  1283. args.AnnotIndex = annot.AnnotIndex;
  1284. args.EventType = annot.EventType;
  1285. args.CreateTime = annot.CreateTime;
  1286. args.UpdateTime = annot.UpdateTime;
  1287. args.Content = annot.Content;
  1288. args.MarkupContent = annot.MarkupContent;
  1289. args.Author = annot.Author;
  1290. args.Locked = annot.Locked;
  1291. args.ReadOnly = annot.ReadOnly;
  1292. args.FormField = annot.FormField;
  1293. args.Document = PDFViewer.Document;
  1294. DialogParameters value = new DialogParameters();
  1295. value.Add(ParameterNames.Annotation, args);
  1296. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1297. {
  1298. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1299. {
  1300. PDFViewer.UndoManager.CanSave = true;
  1301. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1302. {
  1303. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  1304. //RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  1305. events.GetEvent<RefreshAnnotEvent>().Publish(new RefreshAnnotArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = annotation });
  1306. }
  1307. }
  1308. });
  1309. }
  1310. }
  1311. //手绘
  1312. private void FreeHandLineStyle_Menu(object obj)
  1313. {
  1314. if (obj as CusMenuItem != null)
  1315. {
  1316. var menu = obj as CusMenuItem;
  1317. var annot = menu.Parameter as FreehandAnnotArgs;
  1318. if (annot != null)
  1319. {
  1320. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1321. if (menu.tag.ToString() == "Solid")
  1322. {
  1323. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
  1324. }
  1325. else
  1326. {
  1327. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
  1328. }
  1329. AnnotEvent?.UpdateAnnot();
  1330. }
  1331. }
  1332. }
  1333. //文本
  1334. private void FreeTextFontFamily_Menu(object obj)
  1335. {
  1336. if (obj as CusMenuItem != null)
  1337. {
  1338. var menu = obj as CusMenuItem;
  1339. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1340. if (annot != null)
  1341. {
  1342. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1343. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1344. AnnotEvent?.UpdateAnnot();
  1345. }
  1346. }
  1347. }
  1348. private void FreeTextAglin_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. var tag = menu.control.Tag;
  1355. if (annot != null && tag != null)
  1356. {
  1357. var strTag = tag.ToString();
  1358. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1359. if (strTag == "Left")
  1360. {
  1361. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1362. }
  1363. else if (strTag == "Center")
  1364. {
  1365. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1366. }
  1367. else if (strTag == "Right")
  1368. {
  1369. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1370. }
  1371. else if (strTag == "Justify")
  1372. {
  1373. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1374. }
  1375. AnnotEvent?.UpdateAnnot();
  1376. }
  1377. }
  1378. }
  1379. //便签
  1380. private void StrikeNoteEditStrike_Menu(object obj)
  1381. {
  1382. if (obj as CusMenuItem != null)
  1383. {
  1384. var menu = obj as CusMenuItem;
  1385. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1386. if (annot != null)
  1387. {
  1388. var sticky = annot as StickyAnnotArgs;
  1389. sticky.PopupEditWnd();
  1390. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1391. //isRightMenuAddAnnot = false;
  1392. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1393. }
  1394. }
  1395. }
  1396. //形状
  1397. private void ShapeLineStyle_Menu(object obj)
  1398. {
  1399. if (obj as CusMenuItem != null)
  1400. {
  1401. var menu = obj as CusMenuItem;
  1402. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1403. var tag = menu.control.Tag;
  1404. if (annot != null && tag != null)
  1405. {
  1406. var strTag = tag.ToString();
  1407. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1408. if (strTag == "Solid")
  1409. {
  1410. var dashStyle = AnnotTransfer.GetLineDashStyle(true);
  1411. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1412. }
  1413. else
  1414. {
  1415. var dashStyle = AnnotTransfer.GetLineDashStyle(false);
  1416. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1417. }
  1418. AnnotEvent?.UpdateAnnot();
  1419. }
  1420. }
  1421. }
  1422. private void ShapeLineDirect_Menu(object obj)
  1423. {
  1424. if (obj as CusMenuItem != null)
  1425. {
  1426. var menu = obj as CusMenuItem;
  1427. var annot = menu.Parameter as LineAnnotArgs;
  1428. var tag = menu.control.Tag;
  1429. if (annot != null && tag != null)
  1430. {
  1431. var strTag = tag.ToString();
  1432. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1433. if (strTag == "Ver")
  1434. {
  1435. annot.SetLineVertical();
  1436. }
  1437. else
  1438. {
  1439. annot.SetLineHorizontal();
  1440. }
  1441. }
  1442. }
  1443. }
  1444. private void Link_Menu(object obj)
  1445. {
  1446. if (obj is CusMenuItem menuItem)
  1447. {
  1448. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1449. {
  1450. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1451. if (result)
  1452. {
  1453. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1454. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1455. if (isTabItemAnnotation)
  1456. {
  1457. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1458. if (viewModel != null)
  1459. {
  1460. viewModel.DeleteModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. }
  1467. //图章
  1468. private void StampExportPicture_Menu(object obj)
  1469. {
  1470. if (obj as CusMenuItem != null)
  1471. {
  1472. var menu = obj as CusMenuItem;
  1473. var annot = menu.Parameter as StampAnnotArgs;
  1474. if (annot != null)
  1475. {
  1476. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1477. var format = menu.tag.ToString();
  1478. if (format == "PDF")
  1479. dlg.Filter = "PDF|*.pdf";
  1480. else
  1481. dlg.Filter = format + "|*." + format.ToLower();
  1482. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1483. dlg.FileName = PDFViewer.Document.FileName;
  1484. if (dlg.ShowDialog() == true)
  1485. {
  1486. var stampPicture = dlg.FileName;
  1487. if (menu.tag.ToString() == "PDF")
  1488. {
  1489. var writeStamp = annot.GetStampDrawing();
  1490. var tempDoc = new CPDFViewer();
  1491. tempDoc.CreateDocument();
  1492. if (tempDoc.Document == null)
  1493. {
  1494. AlertsMessage alertsMessage = new AlertsMessage();
  1495. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
  1496. return;
  1497. }
  1498. byte[] buffer;
  1499. //var encoder = new PngBitmapEncoder();
  1500. //encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1501. //using (var memoryStream = new MemoryStream())
  1502. //{
  1503. // encoder.Save(memoryStream);
  1504. // buffer = memoryStream.ToArray();
  1505. //}
  1506. //tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1507. //var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1508. //if (result)
  1509. //{
  1510. //}
  1511. string imagePath = SaveImage(writeStamp);
  1512. if (CreateFile(imagePath, tempDoc))
  1513. {
  1514. bool result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1515. }
  1516. }
  1517. else
  1518. {
  1519. var writeStamp = annot.GetStampDrawing();
  1520. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1521. {
  1522. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1523. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1524. encoder5.Save(stream5);
  1525. }
  1526. }
  1527. System.Diagnostics.Process.Start("explorer", "/select,\"" + stampPicture + "\"");
  1528. }
  1529. }
  1530. }
  1531. }
  1532. private string SaveImage(WriteableBitmap wtbBmp)
  1533. {
  1534. string isSave = null;
  1535. if (wtbBmp == null)
  1536. {
  1537. return isSave;
  1538. }
  1539. try
  1540. {
  1541. DirectoryInfo tempfolder = new DirectoryInfo(Path.Combine(App.CurrentPath, "Temp"));
  1542. string strpath = Path.Combine(tempfolder.FullName, DateTime.Now.ToString("yyyyMMddfff") + ".jpg");
  1543. if (!File.Exists(tempfolder.FullName))
  1544. {
  1545. Directory.CreateDirectory(tempfolder.FullName);
  1546. }
  1547. using (FileStream stream = new FileStream(strpath, FileMode.Create))
  1548. {
  1549. JpegBitmapEncoder bitmapEncoder = new JpegBitmapEncoder();
  1550. bitmapEncoder.Frames.Add(BitmapFrame.Create(wtbBmp));
  1551. bitmapEncoder.Save(stream);
  1552. isSave = strpath;
  1553. }
  1554. }
  1555. catch (Exception ex)
  1556. {
  1557. System.Diagnostics.Debug.WriteLine(ex.ToString());
  1558. isSave = null;
  1559. }
  1560. return isSave;
  1561. }
  1562. public bool CreateFile(string imagePath = null, CPDFViewer saveToPDFViewer = null)
  1563. {
  1564. string fileName = null;
  1565. //saveToPDFViewer.CreateDocument();
  1566. //if (saveToPDFViewer.Document == null)
  1567. //{
  1568. // AlertsMessage alertsMessage = new AlertsMessage();
  1569. // alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
  1570. // return false;
  1571. //}
  1572. if (string.IsNullOrEmpty(imagePath))
  1573. {
  1574. fileName = "Blank Page.pdf";
  1575. //默认插入595*842 大小的页面
  1576. saveToPDFViewer.Document.InsertPage(0, 595, 842, null);
  1577. }
  1578. else
  1579. {
  1580. fileName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1) + ".pdf";
  1581. System.Drawing.Bitmap pic = new System.Drawing.Bitmap(imagePath);
  1582. int width = pic.Size.Width;
  1583. int height = pic.Size.Height;
  1584. string ex = System.IO.Path.GetExtension(imagePath);
  1585. //其他格式或者名称中含空格的图片 在本地先转存一下
  1586. if ((ex != ".jpg" && ex != ".jpeg") || !Uri.IsWellFormedUriString(imagePath, UriKind.Absolute))
  1587. {
  1588. //将其他格式图片转换成jpg
  1589. string folderPath = Path.GetTempPath();
  1590. if (File.Exists(folderPath))
  1591. {
  1592. File.Delete(folderPath);
  1593. }
  1594. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  1595. if (!tempfolder.Exists)
  1596. {
  1597. tempfolder.Create();
  1598. }
  1599. string targetPath = System.IO.Path.Combine(folderPath, Guid.NewGuid().ToString());
  1600. imagePath = targetPath;
  1601. pic.Save(targetPath, ImageFormat.Jpeg);
  1602. }
  1603. pic.Dispose();
  1604. var result = saveToPDFViewer.Document.InsertPage(0, width, height, imagePath);
  1605. if (!result)
  1606. {
  1607. AlertsMessage alertsMessage = new AlertsMessage();
  1608. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
  1609. return false;
  1610. }
  1611. }
  1612. return true;
  1613. }
  1614. #endregion 注释右键菜单事件
  1615. #region 快捷键
  1616. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1617. {
  1618. //之前取消逻辑
  1619. // if (KeyEventsHelper.IsSingleKey(Key.Escape))
  1620. // {
  1621. // if (StrAnnotToolChecked != "Freetext")
  1622. // {
  1623. // ExitAnnotationTool();
  1624. // }
  1625. // else if (StrAnnotToolChecked == "Freetext")
  1626. // {
  1627. // if (PDFViewer.ToolManager.CurrentAnnotArgs is FreeTextAnnotArgs textAnnotArgs)
  1628. // {
  1629. // if (PDFViewer.ToolManager.HasTool)
  1630. // {
  1631. // PDFViewer.RemoveTool(true);
  1632. // }
  1633. // else
  1634. // {
  1635. // ExitAnnotationTool();
  1636. // }
  1637. // }
  1638. // }
  1639. // }
  1640. //
  1641. if (e.Key == Key.Escape)
  1642. {
  1643. if (PropertyPanel != null)
  1644. PropertyPanel.IsAddLink = false;
  1645. if (PDFViewer != null)
  1646. {
  1647. if (PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1648. {
  1649. if (PDFViewer.ToolManager != null && PDFViewer.ToolManager.CurrentAnnotArgs != null)
  1650. {
  1651. AnnotHandlerEventArgs annotArgs = PDFViewer.ToolManager.CurrentAnnotArgs;
  1652. switch (annotArgs.EventType)
  1653. {
  1654. case AnnotArgsType.AnnotErase:
  1655. case AnnotArgsType.AnnotLine:
  1656. case AnnotArgsType.AnnotSquare:
  1657. case AnnotArgsType.AnnotCircle:
  1658. case AnnotArgsType.AnnotFreeText:
  1659. //case AnnotArgsType.AnnotSticky:
  1660. Trace.WriteLine(StrAnnotToolChecked);
  1661. if (PDFViewer.ToolManager.HasTool)
  1662. {
  1663. PDFViewer.RemoveTool(false);
  1664. IsCreateAnnot = true;
  1665. }
  1666. else
  1667. {
  1668. ExitAnnotationTool();
  1669. }
  1670. break;
  1671. case AnnotArgsType.AnnotSticky:
  1672. if (PDFViewer.ToolManager.HasTool)
  1673. {
  1674. //PDFViewer.RemoveTool(false);
  1675. events.GetEvent<StickyNoteEvent>().Subscribe(UnStickyNote, q => q.Unicode == Unicode);
  1676. }
  1677. else
  1678. {
  1679. ExitAnnotationTool();
  1680. }
  1681. break;
  1682. case AnnotArgsType.AnnotHighlight:
  1683. case AnnotArgsType.AnnotUnderline:
  1684. case AnnotArgsType.AnnotStrikeout:
  1685. case AnnotArgsType.AnnotStamp:
  1686. case AnnotArgsType.AnnotFreehand:
  1687. case AnnotArgsType.AnnotSelectTool:
  1688. ExitAnnotationTool();
  1689. break;
  1690. case AnnotArgsType.AnnotLink:
  1691. ExitAnnotationTool();
  1692. events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
  1693. break;
  1694. }
  1695. }
  1696. }
  1697. else
  1698. {
  1699. ExitAnnotationTool();
  1700. }
  1701. }
  1702. }
  1703. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  1704. {
  1705. //按住Shift等比缩放
  1706. }
  1707. else if (e.Key == Key.F && e.KeyboardDevice.Modifiers == ModifierKeys.Control)
  1708. {
  1709. if (viewContentViewModel.OpenBOTA == false)
  1710. {
  1711. viewContentViewModel.OpenBOTA = true;
  1712. }
  1713. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1714. if (isBook == false)
  1715. {
  1716. bOTAContent.TabItemSearch.IsSelected = true;
  1717. }
  1718. }
  1719. AnnotToolCtrlAltKey();
  1720. }
  1721. private void UnStickyNote(StickyNoteArgs obj)
  1722. {
  1723. if (PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1724. {
  1725. if (PDFViewer.ToolManager != null && PDFViewer.ToolManager.CurrentAnnotArgs != null)
  1726. {
  1727. if (string.IsNullOrEmpty(obj.Text))
  1728. {
  1729. PDFViewer.RemoveTool(false);
  1730. }
  1731. else
  1732. {
  1733. }
  1734. }
  1735. }
  1736. }
  1737. private void ExitAnnotationTool()
  1738. {
  1739. PDFViewer.DisableClearSelectAnnot(false);
  1740. PDFViewer.ClearSelectAnnots();
  1741. StrAnnotToolChecked = "";
  1742. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1743. HandToolIsCheckedEvent(false);
  1744. BtnHandIsChecked = false;
  1745. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1746. ShowPropertyPanel(false);
  1747. }
  1748. /// <summary>
  1749. /// 按下Ctrl + Alt + 序列键,响应注释工具
  1750. /// </summary>
  1751. private void AnnotToolCtrlAltKey()
  1752. {
  1753. var tuple = GetCtrlAltKey();
  1754. if (tuple != null && PDFViewer != null)
  1755. {
  1756. //进入快捷键时清除选中
  1757. PDFViewer.ClearSelectAnnots();
  1758. if (tuple.Item1 == Key.L)
  1759. BtnLinkIsChecked = false;
  1760. if (tuple.Item2 == "Eraser")
  1761. {
  1762. CreateEraseArgs();
  1763. StrAnnotToolChecked = "Freehand";
  1764. return;
  1765. }
  1766. AnnotHandlerEventArgs annotArgs = null;
  1767. StrAnnotToolChecked = tuple.Item2;
  1768. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  1769. if (annotArgs != null && tuple.Item2 != "Stamp")
  1770. {
  1771. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1772. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1773. PDFViewer.SetToolParam(annotArgs);
  1774. PDFViewer.ToolManager.EnableClickCreate = false;
  1775. }
  1776. else
  1777. {
  1778. //2023/4/6 设置Stamp刚进入时点击view出现空的选中方框
  1779. PDFViewer.SetMouseMode(MouseModes.None);
  1780. }
  1781. }
  1782. }
  1783. private Tuple<Key, string> GetCtrlAltKey()
  1784. {
  1785. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  1786. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  1787. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  1788. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  1789. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  1790. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  1791. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  1792. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  1793. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  1794. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  1795. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  1796. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  1797. Key key = Key.None;
  1798. foreach (var item in AnnotToolDir.Keys)
  1799. {
  1800. if (AnnotToolDir[item] == true)
  1801. {
  1802. key = item;
  1803. break;
  1804. }
  1805. }
  1806. if (key == Key.None)
  1807. return null;
  1808. var tag = "";
  1809. if (key == Key.H || key == Key.U || key == Key.S)
  1810. {
  1811. //判断是否选中文字
  1812. //var str = PDFViewer.GetSelectedText();
  1813. //if (string.IsNullOrEmpty(str) == false)
  1814. {
  1815. if (key == Key.H)
  1816. tag = "HighLight";
  1817. else if (key == Key.U)
  1818. tag = "UnderLine";
  1819. else if (key == Key.S)
  1820. tag = "Strikeout";
  1821. }
  1822. //else
  1823. //{
  1824. // return null;
  1825. //}
  1826. }
  1827. else
  1828. {
  1829. if (AnnotToolDir[Key.P])
  1830. tag = "Freehand";
  1831. else if (AnnotToolDir[Key.T])
  1832. tag = "Freetext";
  1833. else if (AnnotToolDir[Key.N])
  1834. tag = "StickyNote";
  1835. else if (AnnotToolDir[Key.R])
  1836. tag = "RectKey";
  1837. else if (AnnotToolDir[Key.O])
  1838. tag = "Circle";
  1839. else if (AnnotToolDir[Key.A])
  1840. tag = "Arrow";
  1841. else if (AnnotToolDir[Key.L])
  1842. tag = "Line";
  1843. else if (AnnotToolDir[Key.E])
  1844. tag = "Eraser";
  1845. }
  1846. if (tag == "")
  1847. return null;
  1848. return new Tuple<Key, string>(key, tag);
  1849. }
  1850. #endregion 快捷键
  1851. #region Navigation
  1852. public bool IsNavigationTarget(NavigationContext navigationContext)
  1853. {
  1854. return true;
  1855. }
  1856. public void OnNavigatedFrom(NavigationContext navigationContext)
  1857. {
  1858. StrAnnotToolChecked = "";
  1859. //UnBindingPDFViewerHandler();
  1860. //UnBindingEvent();
  1861. }
  1862. public void OnNavigatedTo(NavigationContext navigationContext)
  1863. {
  1864. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1865. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1866. if (viewContentViewModel != null)
  1867. {
  1868. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  1869. }
  1870. if (PDFViewer != null)
  1871. {
  1872. BindingPDFViewerHandler();
  1873. BindingEvent();
  1874. LoaedStickyNotePopup();
  1875. //获取当前是否为滚动状态
  1876. // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  1877. BtnHandIsChecked = false;
  1878. HandToolIsCheckedEvent(false);
  1879. }
  1880. }
  1881. #endregion Navigation
  1882. }
  1883. }