AnnotToolContentViewModel.cs 98 KB

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