AnnotToolContentViewModel.cs 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  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. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  441. break;
  442. case "UnderLine"://下划线
  443. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  444. underlineArgs.ClientRect = annotCommand.TextRect;
  445. underlineArgs.Content = annotCommand.Text;
  446. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  447. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  448. PDFViewer.SetToolParam(underlineArgs);
  449. PDFViewer.SetMouseMode(MouseModes.PanTool);
  450. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  451. break;
  452. case "Strikeout"://删除线
  453. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  454. strikeoutArgs.ClientRect = annotCommand.TextRect;
  455. strikeoutArgs.Content = annotCommand.Text;
  456. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  457. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  458. PDFViewer.SetToolParam(strikeoutArgs);
  459. PDFViewer.SetMouseMode(MouseModes.PanTool);
  460. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  461. break;
  462. case "Freetext"://文本
  463. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  464. textArgs.ClientRect = annotCommand.TextRect;
  465. //textArgs.Transparency = 1;
  466. //textArgs.BgColor = Colors.Transparent;
  467. //textArgs.LineColor = Colors.Red;
  468. //textArgs.LineWidth = 2;
  469. textArgs.TextContent = annotCommand.Text;
  470. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  471. break;
  472. case "StickyNote"://便签
  473. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  474. //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  475. List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
  476. //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  477. Rect rect = annotCommand.TextRectList[0];
  478. #region to do 转dpi
  479. //int dpi = DpiHelpers.Dpi;
  480. //double x = rect.X / 72D * dpi;
  481. //double y = (rect.Y - rect.Height) / 72D * dpi;
  482. //double width = rect.Width / 72D * dpi;
  483. //double height = rect.Height / 72D * dpi;
  484. #endregion to do 转dpi
  485. //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
  486. //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
  487. stickyAnnotArgs.ClientRect = rect;
  488. //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  489. NavigationParameters param = new NavigationParameters();
  490. param.Add(ParameterNames.PDFViewer, PDFViewer);
  491. param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
  492. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  493. param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
  494. System.Windows.Controls.ContentControl window = null;
  495. if (PDFViewer.Parent as ContentControl != null)
  496. {
  497. window = PDFViewer.Parent as ContentControl;
  498. }
  499. else
  500. {
  501. window = App.Current.MainWindow;
  502. }
  503. var point = Mouse.GetPosition(window);
  504. viewContentViewModel.NotePopupVisible = Visibility.Visible;
  505. viewContentViewModel.CanvasNoteLeft = point.X;
  506. viewContentViewModel.CanvasNoteBottom = point.Y;
  507. if (point.Y > window.ActualHeight / 2)
  508. {
  509. viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
  510. }
  511. viewContentViewModel.IsNoteAdd = true;
  512. region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
  513. //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
  514. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  515. //PDFViewer.SetToolParam(stickyAnnotArgs);
  516. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  517. break;
  518. case "Rect"://矩形
  519. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  520. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  521. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  522. break;
  523. case "Circle"://圆
  524. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  525. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  526. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  527. break;
  528. case "Line"://线
  529. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  530. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  531. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  532. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  533. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  534. break;
  535. case "Link"://链接
  536. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  537. linkArgs.ClientRect = annotCommand.TextRect;
  538. linkArgs.URI = string.Empty;
  539. linkArgs.LinkType = LINK_TYPE.GOTO;
  540. linkArgs.DestIndex = annotCommand.PageIndex;
  541. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  542. //BtnLinkIsChecked = true;
  543. //StrAnnotToolChecked = "Link";
  544. //List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  545. //lists.Add(linkArgs);
  546. //PropertyPanel.IsAddLink = true;
  547. //AnnotHandlerEventArgs annotArgs = GetLink(lists);
  548. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  549. //PDFViewer.SetToolParam(annotArgs);
  550. viewContentViewModel.IsPropertyOpen = true;
  551. PDFViewer.SelectAnnotation(linkArgs.PageIndex, linkArgs.AnnotIndex);
  552. break;
  553. case "OutLine":
  554. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  555. if (isTabItemAnnotation == false)
  556. {
  557. bOTAContent.TabItemOutLine.IsSelected = true;
  558. }
  559. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  560. if (outLineControlViewModel != null && outLineControl != null)
  561. {
  562. string str = null;
  563. if (!string.IsNullOrEmpty(annotCommand.Text))
  564. {
  565. str = annotCommand.Text;
  566. }
  567. #region 选择图片
  568. //if (string.IsNullOrEmpty(annotCommand.Text))
  569. //{
  570. // str = (annotCommand.PageIndex + 1).ToString();
  571. //}
  572. //else
  573. //{
  574. // str = annotCommand.Text;
  575. //}
  576. #endregion 选择图片
  577. outLineControl.AddOutlineNode(str);
  578. }
  579. break;
  580. case "ExportPicture":
  581. ExportPicture_MenuItemClick();
  582. break;
  583. }
  584. //ShowPropertyPanel(false);
  585. }
  586. }
  587. private void PageDisplay(ItemCollection items)
  588. {
  589. foreach (var item in items)
  590. {
  591. if (item is MenuItem menuItem)
  592. {
  593. menuItem.IsCheckable = false;
  594. menuItem.Click -= PageDisplay_Click;
  595. menuItem.Click += PageDisplay_Click;
  596. }
  597. }
  598. }
  599. private void PageDisplay_Click(object sender, RoutedEventArgs e)
  600. {
  601. if (sender is MenuItem menuItem)
  602. {
  603. switch (menuItem.Tag.ToString())
  604. {
  605. case "SingleView":
  606. PDFViewer.ChangeViewMode(ViewMode.Single);
  607. break;
  608. case "SingleContinueView":
  609. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  610. break;
  611. case "DoubleView":
  612. PDFViewer.ChangeViewMode(ViewMode.Double);
  613. break;
  614. case "DoubleContinueView":
  615. PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  616. break;
  617. case "BookMode":
  618. PDFViewer.ChangeViewMode(ViewMode.Book);
  619. break;
  620. }
  621. }
  622. }
  623. private void ViewZoom(ItemCollection items)
  624. {
  625. foreach (var item in items)
  626. {
  627. if (item is MenuItem menuItem)
  628. {
  629. //switch (PDFViewer.ModeFit)
  630. //{
  631. // case FitMode.FitWidth:
  632. // break;
  633. // case FitMode.FitHeight:
  634. // break;
  635. // case FitMode.FitSize:
  636. // break;
  637. // case FitMode.FitFree:
  638. // break;
  639. // default:
  640. // break;
  641. //}
  642. menuItem.IsCheckable = false;
  643. menuItem.Click -= ViewZoom_Click;
  644. menuItem.Click += ViewZoom_Click;
  645. }
  646. }
  647. }
  648. private void ViewZoom_Click(object sender, RoutedEventArgs e)
  649. {
  650. if (sender is MenuItem menuItem)
  651. {
  652. switch (menuItem.Tag.ToString())
  653. {
  654. case "FitWidth":
  655. PDFViewer.ChangeFitMode(FitMode.FitWidth);
  656. break;
  657. case "FitHeight":
  658. PDFViewer.ChangeFitMode(FitMode.FitHeight);
  659. break;
  660. case "FitSize":
  661. PDFViewer.ChangeFitMode(FitMode.FitSize);
  662. break;
  663. case "enlarge":
  664. double newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + 0.01), true);
  665. PDFViewer.Zoom(newZoom);
  666. break;
  667. case "narrow":
  668. newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + -0.01), false);
  669. PDFViewer.Zoom(newZoom);
  670. break;
  671. }
  672. }
  673. }
  674. private void UnReadModel_Click(object sender, RoutedEventArgs e)
  675. {
  676. viewContentViewModel.Off_ReadModel();
  677. }
  678. private void ReadModel_Click(object sender, RoutedEventArgs e)
  679. {
  680. viewContentViewModel.On_ReadMode();
  681. }
  682. private void SetToolMode(ItemCollection items)
  683. {
  684. foreach (var item in items)
  685. {
  686. if (item is MenuItem menuItem)
  687. {
  688. menuItem.IsCheckable = false;
  689. menuItem.Click -= ToolMode_Click;
  690. menuItem.Click += ToolMode_Click;
  691. }
  692. }
  693. }
  694. private void ToolMode_Click(object sender, RoutedEventArgs e)
  695. {
  696. if (sender is MenuItem menuItem)
  697. {
  698. switch (menuItem.Tag.ToString())
  699. {
  700. case "default":
  701. StrAnnotToolChecked = "";
  702. PDFViewer.SetMouseMode(MouseModes.PanTool);
  703. HandToolIsCheckedEvent(false);
  704. BtnHandIsChecked = false;
  705. ShowPropertyPanel(false);
  706. break;
  707. case "roll":
  708. StrAnnotToolChecked = "";
  709. HandToolIsCheckedEvent(true);
  710. BtnHandIsChecked = true;
  711. ShowPropertyPanel(false);
  712. break;
  713. case "content":
  714. AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
  715. BtnSelecttoolIsChecked = true;
  716. if (annotHandler != null)
  717. {
  718. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  719. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  720. PDFViewer.SetToolParam(annotHandler);
  721. ShowPropertyPanel(false);
  722. }
  723. break;
  724. default:
  725. break;
  726. }
  727. }
  728. }
  729. private void DelBookMark_Click(object sender, RoutedEventArgs e)
  730. {
  731. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  732. if (bOTAContentVM != null && bOTA != null)
  733. {
  734. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  735. int index = PDFViewer.CurrentIndex;
  736. //检测是否已存在相同数据
  737. if (PDFViewer.Document == null) return;
  738. if (PDFViewer.Document.GetBookmarkList().Count <= 0) return;
  739. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  740. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  741. {
  742. bookmarkContentViewModel.DeleteCommand.Execute(list);
  743. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  744. }
  745. }
  746. }
  747. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  748. {
  749. if (viewContentViewModel.OpenBOTA == false)
  750. {
  751. viewContentViewModel.OpenBOTA = true;
  752. }
  753. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  754. if (isBook == false)
  755. {
  756. bOTA.TabItemBookMark.IsSelected = true;
  757. }
  758. }
  759. private void AddBookMark_Click()
  760. {
  761. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  762. //if (viewContentViewModel.mainViewModel.IsBookMode)
  763. //{
  764. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  765. //}
  766. if (bOTAContentVM != null && bOTA != null)
  767. {
  768. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  769. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  770. {
  771. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  772. bookmark.BtnAddBookmark_Click(null, null);
  773. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  774. return;
  775. }
  776. }
  777. }
  778. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  779. {
  780. BookmarkContentViewModel viewModel = null;
  781. bookmark = null;
  782. if (bOTAContentViewModel != null)
  783. {
  784. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  785. {
  786. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  787. foreach (var item in views)
  788. {
  789. if (item is BookmarkContent bookmark1)
  790. {
  791. bookmark = bookmark1;
  792. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  793. break;
  794. }
  795. }
  796. }
  797. }
  798. return viewModel;
  799. }
  800. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  801. {
  802. OutLineControlViewModel viewModel = null;
  803. outLineControl = null;
  804. if (bOTAContentViewModel != null)
  805. {
  806. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  807. {
  808. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  809. foreach (var item in views)
  810. {
  811. if (item is OutLineControl outLineControl1)
  812. {
  813. outLineControl = outLineControl1;
  814. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  815. break;
  816. }
  817. }
  818. }
  819. }
  820. return viewModel;
  821. }
  822. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  823. {
  824. PDFViewer.SetDrawAnnot(true);
  825. BtnShowAnnotIsChecked = true;
  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.DisplayAnnot();
  831. }
  832. }
  833. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  834. {
  835. PDFViewer.SetDrawAnnot(false);
  836. BtnShowAnnotIsChecked = false;
  837. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  838. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  839. {
  840. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  841. viewModel.HiddenAnnot();
  842. }
  843. }
  844. private void SetAddAnnotation(ItemCollection items)
  845. {
  846. foreach (var item in items)
  847. {
  848. if (item is MenuItem menuItem)
  849. {
  850. string str = menuItem.Tag.ToString();
  851. //if (str == AddAnnotType.AnnotLink.ToString()
  852. //|| str == AddAnnotType.AnnotStamp.ToString()
  853. //|| str == AddAnnotType.AnnotAutograph.ToString()
  854. //)
  855. //{
  856. // InBookModeSetIsEnabled(menuItem);
  857. //}
  858. menuItem.CommandParameter = item;
  859. menuItem.Command = SetAddAnnotationCommand;
  860. }
  861. }
  862. }
  863. //private void AddLink_Click(object sender, RoutedEventArgs e)
  864. //{
  865. // var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  866. // BtnLinkIsChecked = true;
  867. //}
  868. #endregion 阅读页右键菜单
  869. #region 注释右键菜单事件
  870. //高亮、下划线、删除
  871. private void HightAnnotCopyText_Menu(object obj)
  872. {
  873. if (obj as CusMenuItem != null)
  874. {
  875. var menu = obj as CusMenuItem;
  876. var annot = menu.Parameter as AnnotHandlerEventArgs;
  877. if (annot != null)
  878. {
  879. System.Windows.Clipboard.SetText(annot.Content);
  880. }
  881. }
  882. }
  883. /// <summary>
  884. /// 更改为当前注释属性默认值
  885. /// </summary>
  886. /// <param name="obj"></param>
  887. private void AnnotDefaultValues_Menu(object obj)
  888. {
  889. if (obj as CusMenuItem != null)
  890. {
  891. var menu = obj as CusMenuItem;
  892. var annot = menu.Parameter as AnnotHandlerEventArgs;
  893. if (annot != null)
  894. {
  895. if (annot is TextHighlightAnnotArgs)
  896. {
  897. var color = (annot as TextHighlightAnnotArgs).Color;
  898. HighLightColor = new SolidColorBrush(color);
  899. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  900. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  901. hightlight.ForgoundColor = color;
  902. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  903. SettingHelper.SetAnnotDefaultProperty(hightlight);
  904. }
  905. else if (annot is TextUnderlineAnnotArgs)
  906. {
  907. var color = (annot as TextUnderlineAnnotArgs).Color;
  908. UnderLineColor = new SolidColorBrush(color);
  909. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  910. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  911. Underline.ForgoundColor = color;
  912. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  913. SettingHelper.SetAnnotDefaultProperty(Underline);
  914. }
  915. else if (annot is TextStrikeoutAnnotArgs)
  916. {
  917. var color = (annot as TextStrikeoutAnnotArgs).Color;
  918. StrikeoutColor = new SolidColorBrush(color);
  919. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  920. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  921. Strikeout.ForgoundColor = color;
  922. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  923. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  924. }
  925. else if (annot is FreehandAnnotArgs)
  926. {
  927. var freeHand = annot as FreehandAnnotArgs;
  928. var color = freeHand.InkColor;
  929. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  930. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  931. FreehandDefault.ForgoundColor = color;
  932. FreehandDefault.Opacity = freeHand.Transparency;
  933. FreehandDefault.Thickness = freeHand.LineWidth;
  934. var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  935. if (isSolid)
  936. {
  937. FreehandDefault.DashArray = null;
  938. }
  939. else
  940. {
  941. FreehandDefault.DashArray = new List<double>();
  942. foreach (var item in freeHand.LineDash.Dashes)
  943. {
  944. FreehandDefault.DashArray.Add(item);
  945. }
  946. }
  947. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  948. FreehandAnnotArgs annotArgs = new FreehandAnnotArgs()
  949. {
  950. InkColor = freeHand.InkColor,
  951. Transparency = freeHand.Transparency,
  952. LineWidth = freeHand.LineWidth,
  953. LineDash = freeHand.LineDash
  954. };
  955. PDFViewer.SetToolParam(annotArgs);
  956. }
  957. else if (annot is FreeTextAnnotArgs freeText)
  958. {
  959. //var freeText = annot as FreeTextAnnotArgs;
  960. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  961. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  962. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  963. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  964. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  965. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  966. FreeTextDefalut.TextAlign = freeText.Align;
  967. FreeTextDefalut.FontSize = freeText.FontSize;
  968. FreeTextDefalut.FontWeight = freeText.FontWeight;
  969. FreeTextDefalut.FontStyle = freeText.FontStyle;
  970. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  971. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  972. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  973. //FreeTextAnnotArgs freeTextAnnotArgs = new FreeTextAnnotArgs()
  974. //{
  975. // FontColor = freeText.FontColor,
  976. // FontFamily = freeText.FontFamily,
  977. // Align = freeText.Align,
  978. // FontSize = freeText.FontSize,
  979. // FontWeight = freeText.FontWeight,
  980. // FontStyle = freeText.FontStyle,
  981. // BgColor = freeText.BgColor,
  982. // Transparency = (annot as FreeTextAnnotArgs).Transparency
  983. //};
  984. //PDFViewer.SetToolParam(freeTextAnnotArgs);
  985. }
  986. else if (annot is StickyAnnotArgs)
  987. {
  988. var color = (annot as StickyAnnotArgs).Color;
  989. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  990. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  991. StickyDefalut.ForgoundColor = color;
  992. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  993. }
  994. else if (annot is SquareAnnotArgs)
  995. {
  996. var square = annot as SquareAnnotArgs;
  997. var bgColor = square.BgColor;
  998. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  999. var borderColor = square.LineColor;
  1000. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  1001. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  1002. SquareDefalut.BorderColor = borderColor;
  1003. SquareDefalut.BackgroundColor = bgColor;
  1004. SquareDefalut.Opacity = square.Transparency;
  1005. SquareDefalut.Thickness = square.LineWidth;
  1006. var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
  1007. if (isSolid)
  1008. {
  1009. SquareDefalut.DashArray = null;
  1010. }
  1011. else
  1012. {
  1013. SquareDefalut.DashArray = new List<double>();
  1014. foreach (var item in square.LineDash.Dashes)
  1015. {
  1016. SquareDefalut.DashArray.Add(item);
  1017. }
  1018. }
  1019. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  1020. }
  1021. else if (annot is CircleAnnotArgs)
  1022. {
  1023. var circle = annot as CircleAnnotArgs;
  1024. var bgColor = circle.BgColor;
  1025. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  1026. var borderColor = circle.LineColor;
  1027. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  1028. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  1029. CircleDefalut.BorderColor = borderColor;
  1030. CircleDefalut.BackgroundColor = bgColor;
  1031. CircleDefalut.Opacity = circle.Transparency;
  1032. CircleDefalut.Thickness = circle.LineWidth;
  1033. var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
  1034. if (isSolid)
  1035. {
  1036. CircleDefalut.DashArray = null;
  1037. }
  1038. else
  1039. {
  1040. CircleDefalut.DashArray = new List<double>();
  1041. foreach (var item in circle.LineDash.Dashes)
  1042. {
  1043. CircleDefalut.DashArray.Add(item);
  1044. }
  1045. }
  1046. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1047. }
  1048. else if (annot is LineAnnotArgs lineAnnotArgs)
  1049. {
  1050. var color = lineAnnotArgs.LineColor;
  1051. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1052. //箭头
  1053. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1054. {
  1055. Settings.Default.AppProperties.Annotate.ArrowColor = color;
  1056. lineDefalut.HeadLineType = lineAnnotArgs.HeadLineType;
  1057. lineDefalut.TailLineType = lineAnnotArgs.TailLineType;
  1058. }
  1059. else
  1060. {
  1061. Settings.Default.AppProperties.Annotate.LineColor = color;
  1062. }
  1063. lineDefalut.BorderColor = color;
  1064. lineDefalut.Opacity = lineAnnotArgs.Transparency;
  1065. lineDefalut.Thickness = lineAnnotArgs.LineWidth;
  1066. var isSolid = AnnotTransfer.IsSolidStyle(lineAnnotArgs.LineDash);
  1067. if (isSolid)
  1068. {
  1069. lineDefalut.DashArray = null;
  1070. }
  1071. else
  1072. {
  1073. lineDefalut.DashArray = new List<double>();
  1074. foreach (var item in lineAnnotArgs.LineDash.Dashes)
  1075. {
  1076. lineDefalut.DashArray.Add(item);
  1077. }
  1078. }
  1079. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1080. }
  1081. Settings.Default.Save();
  1082. PropertyPanel.annot = annot;
  1083. PropertyPanel.SaveLastAnnot();
  1084. }
  1085. }
  1086. }
  1087. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1088. {
  1089. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1090. if (Annot == null)
  1091. {
  1092. Annot = new DefaultAnnotProperty();
  1093. Annot.AnnotToolType = annotArgsType;
  1094. }
  1095. return Annot;
  1096. }
  1097. private System.Windows.Controls.Primitives.Popup popup = null;
  1098. //更改颜色
  1099. private async void AnnotColorPalette_Menu(object obj)
  1100. {
  1101. if (obj as CusMenuItem != null)
  1102. {
  1103. var menu = obj as CusMenuItem;
  1104. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1105. if (annot != null)
  1106. {
  1107. var item = new ColorDropBoxPop();
  1108. item.DataContext = menu;
  1109. item.ColorSelected -= AnnotMenu_ColorSelected;
  1110. item.ColorSelected += AnnotMenu_ColorSelected;
  1111. if (popup == null)
  1112. popup = new System.Windows.Controls.Primitives.Popup();
  1113. ContentControl window = null;
  1114. if (PDFViewer.Parent as ContentControl != null)
  1115. window = PDFViewer.Parent as ContentControl;
  1116. else
  1117. window = App.Current.MainWindow;
  1118. popup.Child = item;
  1119. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1120. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1121. popup.PlacementTarget = window;
  1122. popup.IsOpen = true;
  1123. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1124. if (parentWnd != null)
  1125. {
  1126. parentWnd.MouseDown -= parentWnd_MouseDown;
  1127. parentWnd.MouseDown += parentWnd_MouseDown;
  1128. }
  1129. while (popup.IsOpen)
  1130. await Task.Delay(20);
  1131. parentWnd.MouseDown -= parentWnd_MouseDown;
  1132. popup = null;
  1133. }
  1134. }
  1135. }
  1136. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1137. {
  1138. var ui = Mouse.DirectlyOver as FrameworkElement;
  1139. if (ui != null)
  1140. {
  1141. if (popup != null)
  1142. {
  1143. popup.IsOpen = false;
  1144. }
  1145. }
  1146. }
  1147. private void AnnotMenu_ColorSelected(object sender, Color e)
  1148. {
  1149. if (sender != null)
  1150. {
  1151. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1152. if (menu == null) return;
  1153. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1154. if (annot != null)
  1155. {
  1156. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1157. {
  1158. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1159. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1160. AnnotEvent?.UpdateAnnot();
  1161. }
  1162. else if (annot is FreeTextAnnotArgs)
  1163. {
  1164. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1165. if (menu.tag.ToString() == "FontColor")
  1166. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1167. else
  1168. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1169. AnnotEvent?.UpdateAnnot();
  1170. }
  1171. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1172. {
  1173. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1174. if (menu.tag.ToString() == "FillColor")
  1175. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1176. else
  1177. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1178. AnnotEvent?.UpdateAnnot();
  1179. }
  1180. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1181. {
  1182. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1183. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1184. AnnotEvent?.UpdateAnnot();
  1185. }
  1186. }
  1187. }
  1188. }
  1189. //添加笔记
  1190. private void AnnotAddNoteText_Menu(object obj)
  1191. {
  1192. if (obj as CusMenuItem != null)
  1193. {
  1194. var menu = obj as CusMenuItem;
  1195. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1196. PopAnnotNoteText(annot);
  1197. }
  1198. }
  1199. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1200. {
  1201. if (annot != null)
  1202. {
  1203. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1204. args.ClientRect = annot.ClientRect;
  1205. args.AnnotHandlerEventArgs = annot;
  1206. args.PageIndex = annot.PageIndex;
  1207. args.AnnotIndex = annot.AnnotIndex;
  1208. args.EventType = annot.EventType;
  1209. args.CreateTime = annot.CreateTime;
  1210. args.UpdateTime = annot.UpdateTime;
  1211. args.Content = annot.Content;
  1212. args.MarkupContent = annot.MarkupContent;
  1213. args.Author = annot.Author;
  1214. args.Locked = annot.Locked;
  1215. args.ReadOnly = annot.ReadOnly;
  1216. args.FormField = annot.FormField;
  1217. args.Document = PDFViewer.Document;
  1218. DialogParameters value = new DialogParameters();
  1219. value.Add(ParameterNames.Annotation, args);
  1220. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1221. {
  1222. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1223. {
  1224. PDFViewer.UndoManager.CanSave = true;
  1225. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1226. {
  1227. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  1228. //RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  1229. events.GetEvent<RefreshAnnotEvent>().Publish(new RefreshAnnotArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = annotation });
  1230. }
  1231. }
  1232. });
  1233. }
  1234. }
  1235. //手绘
  1236. private void FreeHandLineStyle_Menu(object obj)
  1237. {
  1238. if (obj as CusMenuItem != null)
  1239. {
  1240. var menu = obj as CusMenuItem;
  1241. var annot = menu.Parameter as FreehandAnnotArgs;
  1242. if (annot != null)
  1243. {
  1244. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1245. if (menu.tag.ToString() == "Solid")
  1246. {
  1247. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
  1248. }
  1249. else
  1250. {
  1251. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
  1252. }
  1253. AnnotEvent?.UpdateAnnot();
  1254. }
  1255. }
  1256. }
  1257. //文本
  1258. private void FreeTextFontFamily_Menu(object obj)
  1259. {
  1260. if (obj as CusMenuItem != null)
  1261. {
  1262. var menu = obj as CusMenuItem;
  1263. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1264. if (annot != null)
  1265. {
  1266. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1267. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1268. AnnotEvent?.UpdateAnnot();
  1269. }
  1270. }
  1271. }
  1272. private void FreeTextAglin_Menu(object obj)
  1273. {
  1274. if (obj as CusMenuItem != null)
  1275. {
  1276. var menu = obj as CusMenuItem;
  1277. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1278. var tag = menu.control.Tag;
  1279. if (annot != null && tag != null)
  1280. {
  1281. var strTag = tag.ToString();
  1282. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1283. if (strTag == "Left")
  1284. {
  1285. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1286. }
  1287. else if (strTag == "Center")
  1288. {
  1289. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1290. }
  1291. else if (strTag == "Right")
  1292. {
  1293. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1294. }
  1295. else if (strTag == "Justify")
  1296. {
  1297. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1298. }
  1299. AnnotEvent?.UpdateAnnot();
  1300. }
  1301. }
  1302. }
  1303. //便签
  1304. private void StrikeNoteEditStrike_Menu(object obj)
  1305. {
  1306. if (obj as CusMenuItem != null)
  1307. {
  1308. var menu = obj as CusMenuItem;
  1309. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1310. if (annot != null)
  1311. {
  1312. var sticky = annot as StickyAnnotArgs;
  1313. sticky.PopupEditWnd();
  1314. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1315. //isRightMenuAddAnnot = false;
  1316. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1317. }
  1318. }
  1319. }
  1320. //形状
  1321. private void ShapeLineStyle_Menu(object obj)
  1322. {
  1323. if (obj as CusMenuItem != null)
  1324. {
  1325. var menu = obj as CusMenuItem;
  1326. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1327. var tag = menu.control.Tag;
  1328. if (annot != null && tag != null)
  1329. {
  1330. var strTag = tag.ToString();
  1331. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1332. if (strTag == "Solid")
  1333. {
  1334. var dashStyle = AnnotTransfer.GetLineDashStyle(true);
  1335. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1336. }
  1337. else
  1338. {
  1339. var dashStyle = AnnotTransfer.GetLineDashStyle(false);
  1340. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1341. }
  1342. AnnotEvent?.UpdateAnnot();
  1343. }
  1344. }
  1345. }
  1346. private void ShapeLineDirect_Menu(object obj)
  1347. {
  1348. if (obj as CusMenuItem != null)
  1349. {
  1350. var menu = obj as CusMenuItem;
  1351. var annot = menu.Parameter as LineAnnotArgs;
  1352. var tag = menu.control.Tag;
  1353. if (annot != null && tag != null)
  1354. {
  1355. var strTag = tag.ToString();
  1356. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1357. if (strTag == "Ver")
  1358. {
  1359. annot.SetLineVertical();
  1360. }
  1361. else
  1362. {
  1363. annot.SetLineHorizontal();
  1364. }
  1365. }
  1366. }
  1367. }
  1368. private void Link_Menu(object obj)
  1369. {
  1370. if (obj is CusMenuItem menuItem)
  1371. {
  1372. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1373. {
  1374. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1375. if (result)
  1376. {
  1377. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1378. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1379. if (isTabItemAnnotation)
  1380. {
  1381. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1382. if (viewModel != null)
  1383. {
  1384. viewModel.DeleteModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1385. }
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. //图章
  1392. private void StampExportPicture_Menu(object obj)
  1393. {
  1394. if (obj as CusMenuItem != null)
  1395. {
  1396. var menu = obj as CusMenuItem;
  1397. var annot = menu.Parameter as StampAnnotArgs;
  1398. if (annot != null)
  1399. {
  1400. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1401. var format = menu.tag.ToString();
  1402. if (format == "PDF")
  1403. dlg.Filter = "PDF|*.pdf";
  1404. else
  1405. dlg.Filter = format + "|*." + format.ToLower();
  1406. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1407. dlg.FileName = PDFViewer.Document.FileName;
  1408. if (dlg.ShowDialog() == true)
  1409. {
  1410. var stampPicture = dlg.FileName;
  1411. if (menu.tag.ToString() == "PDF")
  1412. {
  1413. var writeStamp = annot.GetStampDrawing();
  1414. var tempDoc = new CPDFViewer();
  1415. tempDoc.CreateDocument();
  1416. if (tempDoc.Document == null)
  1417. {
  1418. AlertsMessage alertsMessage = new AlertsMessage();
  1419. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1420. return;
  1421. }
  1422. byte[] buffer;
  1423. var encoder = new PngBitmapEncoder();
  1424. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1425. using (var memoryStream = new MemoryStream())
  1426. {
  1427. encoder.Save(memoryStream);
  1428. buffer = memoryStream.ToArray();
  1429. }
  1430. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1431. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1432. if (result)
  1433. {
  1434. }
  1435. }
  1436. else
  1437. {
  1438. var writeStamp = annot.GetStampDrawing();
  1439. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1440. {
  1441. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1442. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1443. encoder5.Save(stream5);
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. }
  1450. #endregion 注释右键菜单事件
  1451. #region 快捷键
  1452. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1453. {
  1454. //之前取消逻辑
  1455. // if (KeyEventsHelper.IsSingleKey(Key.Escape))
  1456. // {
  1457. // if (StrAnnotToolChecked != "Freetext")
  1458. // {
  1459. // ExitAnnotationTool();
  1460. // }
  1461. // else if (StrAnnotToolChecked == "Freetext")
  1462. // {
  1463. // if (PDFViewer.ToolManager.CurrentAnnotArgs is FreeTextAnnotArgs textAnnotArgs)
  1464. // {
  1465. // if (PDFViewer.ToolManager.HasTool)
  1466. // {
  1467. // PDFViewer.RemoveTool(true);
  1468. // }
  1469. // else
  1470. // {
  1471. // ExitAnnotationTool();
  1472. // }
  1473. // }
  1474. // }
  1475. // }
  1476. //
  1477. if (e.Key == Key.Escape && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1478. {
  1479. if (PDFViewer.ToolManager != null && PDFViewer.ToolManager.CurrentAnnotArgs != null)
  1480. {
  1481. AnnotHandlerEventArgs annotArgs = PDFViewer.ToolManager.CurrentAnnotArgs;
  1482. switch (annotArgs.EventType)
  1483. {
  1484. case AnnotArgsType.AnnotLine:
  1485. case AnnotArgsType.AnnotSquare:
  1486. case AnnotArgsType.AnnotCircle:
  1487. //case AnnotArgsType.AnnotHighlight:
  1488. //case AnnotArgsType.AnnotUnderline:
  1489. //case AnnotArgsType.AnnotStrikeout:
  1490. //case AnnotArgsType.AnnotStamp:
  1491. //case AnnotArgsType.AnnotLink:
  1492. //case AnnotArgsType.AnnotFreehand:
  1493. case AnnotArgsType.AnnotSticky:
  1494. case AnnotArgsType.AnnotFreeText:
  1495. Trace.WriteLine(StrAnnotToolChecked);
  1496. if (PDFViewer.ToolManager.HasTool)
  1497. {
  1498. PDFViewer.RemoveTool(false);
  1499. }
  1500. else { ExitAnnotationTool(); }
  1501. break;
  1502. default:
  1503. break;
  1504. }
  1505. }
  1506. }
  1507. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  1508. {
  1509. //按住Shift等比缩放
  1510. }
  1511. else if (e.Key == Key.F && e.KeyboardDevice.Modifiers == ModifierKeys.Control)
  1512. {
  1513. if (viewContentViewModel.OpenBOTA == false)
  1514. {
  1515. viewContentViewModel.OpenBOTA = true;
  1516. }
  1517. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1518. if (isBook == false)
  1519. {
  1520. bOTAContent.TabItemSearch.IsSelected = true;
  1521. }
  1522. }
  1523. AnnotToolCtrlAltKey();
  1524. }
  1525. private void ExitAnnotationTool()
  1526. {
  1527. PDFViewer.ClearSelectAnnots();
  1528. StrAnnotToolChecked = "";
  1529. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1530. HandToolIsCheckedEvent(false);
  1531. BtnHandIsChecked = false;
  1532. ShowPropertyPanel(false);
  1533. }
  1534. /// <summary>
  1535. /// 按下Ctrl + Alt + 序列键,响应注释工具
  1536. /// </summary>
  1537. private void AnnotToolCtrlAltKey()
  1538. {
  1539. var tuple = GetCtrlAltKey();
  1540. if (tuple != null)
  1541. {
  1542. if (tuple.Item1 == Key.L)
  1543. BtnLinkIsChecked = false;
  1544. if (tuple.Item2 == "Eraser")
  1545. {
  1546. CreateEraseArgs();
  1547. StrAnnotToolChecked = "Freehand";
  1548. return;
  1549. }
  1550. AnnotHandlerEventArgs annotArgs = null;
  1551. StrAnnotToolChecked = tuple.Item2;
  1552. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  1553. if (annotArgs != null)
  1554. {
  1555. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1556. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1557. PDFViewer.SetToolParam(annotArgs);
  1558. PDFViewer.ToolManager.EnableClickCreate = false;
  1559. }
  1560. }
  1561. }
  1562. private Tuple<Key, string> GetCtrlAltKey()
  1563. {
  1564. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  1565. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  1566. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  1567. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  1568. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  1569. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  1570. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  1571. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  1572. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  1573. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  1574. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  1575. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  1576. Key key = Key.None;
  1577. foreach (var item in AnnotToolDir.Keys)
  1578. {
  1579. if (AnnotToolDir[item] == true)
  1580. {
  1581. key = item;
  1582. break;
  1583. }
  1584. }
  1585. if (key == Key.None)
  1586. return null;
  1587. var tag = "";
  1588. if (key == Key.H || key == Key.U || key == Key.S)
  1589. {
  1590. var str = PDFViewer.GetSelectedText();
  1591. if (string.IsNullOrEmpty(str) == false)
  1592. {
  1593. if (key == Key.H)
  1594. tag = "HighLight";
  1595. else if (key == Key.U)
  1596. tag = "UnderLine";
  1597. else if (key == Key.S)
  1598. tag = "Strikeout";
  1599. }
  1600. else
  1601. {
  1602. return null;
  1603. }
  1604. }
  1605. else
  1606. {
  1607. if (AnnotToolDir[Key.P])
  1608. tag = "Freehand";
  1609. else if (AnnotToolDir[Key.T])
  1610. tag = "Freetext";
  1611. else if (AnnotToolDir[Key.N])
  1612. tag = "StickyNote";
  1613. else if (AnnotToolDir[Key.R])
  1614. tag = "Rect";
  1615. else if (AnnotToolDir[Key.O])
  1616. tag = "Circle";
  1617. else if (AnnotToolDir[Key.A])
  1618. tag = "Arrow";
  1619. else if (AnnotToolDir[Key.L])
  1620. tag = "Line";
  1621. else if (AnnotToolDir[Key.E])
  1622. tag = "Eraser";
  1623. }
  1624. if (tag == "")
  1625. return null;
  1626. return new Tuple<Key, string>(key, tag);
  1627. }
  1628. #endregion 快捷键
  1629. #region Navigation
  1630. public bool IsNavigationTarget(NavigationContext navigationContext)
  1631. {
  1632. return true;
  1633. }
  1634. public void OnNavigatedFrom(NavigationContext navigationContext)
  1635. {
  1636. StrAnnotToolChecked = "";
  1637. //UnBindingPDFViewerHandler();
  1638. //UnBindingEvent();
  1639. }
  1640. public void OnNavigatedTo(NavigationContext navigationContext)
  1641. {
  1642. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1643. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1644. if (viewContentViewModel != null)
  1645. {
  1646. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  1647. }
  1648. BindingPDFViewerHandler();
  1649. BindingEvent();
  1650. LoaedStickyNotePopup();
  1651. //获取当前是否为滚动状态
  1652. // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  1653. BtnHandIsChecked = false;
  1654. HandToolIsCheckedEvent(false);
  1655. }
  1656. #endregion Navigation
  1657. }
  1658. }