AnnotToolContentViewModel.cs 77 KB

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