AnnotToolContentViewModel.cs 81 KB

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