AnnotToolContentViewModel.cs 74 KB

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