AnnotToolContentViewModel.cs 69 KB

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