AnnotToolContentViewModel.cs 79 KB

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