AnnotToolContentViewModel.cs 100 KB

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