AnnotToolContentViewModel.cs 102 KB

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