AnnotToolContentViewModel.cs 71 KB

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