AnnotToolContentViewModel.cs 82 KB

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