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