AnnotToolContentViewModel.cs 72 KB

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