CPDFScalingControl.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Compdfkit_Tools.Helper;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.PdfViewer;
  4. using System;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. namespace Compdfkit_Tools.PDFControl
  8. {
  9. public partial class CPDFScalingControl : UserControl
  10. {
  11. public CPDFViewer pdfViewer;
  12. public CPDFScalingControl()
  13. {
  14. InitializeComponent();
  15. }
  16. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  17. {
  18. this.pdfViewer = pdfViewer;
  19. }
  20. private void PDFScalingControl_Loaded(object sender, RoutedEventArgs e)
  21. {
  22. CPDFScalingUI.SetScaleEvent += PDFScalingControl_SetScaleEvent;
  23. CPDFScalingUI.ScaleIncreaseEvent += PDFScalingControl_ScaleIncreaseEvent;
  24. CPDFScalingUI.ScaleDecreaseEvent += PDFScalingControl_ScaleDecreaseEvent;
  25. CPDFScalingUI.SetPresetScaleEvent += CPDFScalingUI_SetPresetScaleEvent;
  26. }
  27. private void CPDFScalingUI_Unloaded(object sender, RoutedEventArgs e)
  28. {
  29. CPDFScalingUI.SetScaleEvent -= PDFScalingControl_SetScaleEvent;
  30. CPDFScalingUI.ScaleIncreaseEvent -= PDFScalingControl_ScaleIncreaseEvent;
  31. CPDFScalingUI.ScaleDecreaseEvent -= PDFScalingControl_ScaleDecreaseEvent;
  32. CPDFScalingUI.SetPresetScaleEvent -= CPDFScalingUI_SetPresetScaleEvent;
  33. }
  34. private void PDFScalingControl_ScaleDecreaseEvent(object sender, EventArgs e)
  35. {
  36. if (pdfViewer == null || pdfViewer.Document == null)
  37. {
  38. return;
  39. }
  40. if (pdfViewer.ZoomFactor < 3)
  41. {
  42. pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.1);
  43. }
  44. else if (pdfViewer.ZoomFactor < 6)
  45. {
  46. pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.2);
  47. }
  48. else if (pdfViewer.ZoomFactor <= 10)
  49. {
  50. pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.3);
  51. }
  52. SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
  53. }
  54. private void PDFScalingControl_ScaleIncreaseEvent(object sender, EventArgs e)
  55. {
  56. if (pdfViewer == null || pdfViewer.Document == null)
  57. {
  58. return;
  59. }
  60. if (pdfViewer.ZoomFactor < 3)
  61. {
  62. pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.1);
  63. }
  64. else if (pdfViewer.ZoomFactor < 6)
  65. {
  66. pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.2);
  67. }
  68. else if (pdfViewer.ZoomFactor <= 10)
  69. {
  70. pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.3);
  71. }
  72. SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
  73. }
  74. private void PDFScalingControl_SetScaleEvent(object sender, string e)
  75. {
  76. if (pdfViewer == null || pdfViewer.Document == null)
  77. {
  78. return;
  79. }
  80. if (!string.IsNullOrEmpty(e))
  81. {
  82. pdfViewer.Zoom(double.Parse(e) / 100);
  83. SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
  84. }
  85. }
  86. private void CPDFScalingUI_SetPresetScaleEvent(object sender, string e)
  87. {
  88. if (pdfViewer == null || pdfViewer.Document == null)
  89. {
  90. return;
  91. }
  92. if (e == LanguageHelper.CommonManager.GetString("Zoom_Real"))
  93. {
  94. pdfViewer.ChangeFitMode(FitMode.FitSize);
  95. }
  96. else if (e == LanguageHelper.CommonManager.GetString("Zoom_FitWidth"))
  97. {
  98. pdfViewer.ChangeFitMode(FitMode.FitWidth);
  99. }
  100. else if (e == LanguageHelper.CommonManager.GetString("Zoom_FitPage"))
  101. {
  102. pdfViewer.ChangeFitMode(FitMode.FitHeight);
  103. }
  104. else
  105. {
  106. pdfViewer.Zoom(double.Parse(e) / 100);
  107. }
  108. SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
  109. }
  110. public void SetZoomTextBoxText(string value)
  111. {
  112. CPDFScalingUI.SetZoomTextBoxText(value);
  113. }
  114. private void CPDFPageScalingControl_LostFocus(object sender, RoutedEventArgs e)
  115. {
  116. SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
  117. }
  118. }
  119. }