AnnotToolContentViewModel.cs 84 KB

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