|
@@ -27,6 +27,10 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
/// </summary>
|
|
|
public partial class PreviewControl : UserControl, INotifyPropertyChanged
|
|
|
{
|
|
|
+ private Point lastMousePosition;
|
|
|
+ private double startVerticalOffset;
|
|
|
+ private double startHorizontalOffset;
|
|
|
+
|
|
|
private List<int> _pageIndexList = new List<int>();
|
|
|
public List<int> PageRangeList
|
|
|
{
|
|
@@ -70,13 +74,13 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private double _scale = 1.0;
|
|
|
+ private double _scale = 0.3;
|
|
|
public double Scale
|
|
|
{
|
|
|
get => _scale;
|
|
|
set
|
|
|
{
|
|
|
- UpdateProper(ref _scale, Math.Min((Math.Max(value, 0.1)), 10));
|
|
|
+ UpdateProper(ref _scale, Math.Min((Math.Max(value, 0.1)), 1));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -118,17 +122,33 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
-
|
|
|
+ lastMousePosition = e.GetPosition(Image);
|
|
|
+ startVerticalOffset = ImageSv.VerticalOffset;
|
|
|
+ startHorizontalOffset = ImageSv.HorizontalOffset;
|
|
|
+ Image.CaptureMouse();
|
|
|
+ this.Cursor = Cursors.Hand;
|
|
|
}
|
|
|
|
|
|
private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
-
|
|
|
+ Image.ReleaseMouseCapture();
|
|
|
+ this.Cursor = Cursors.Arrow;
|
|
|
}
|
|
|
|
|
|
private void Image_MouseMove(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
+ if (ImageSv.Visibility == Visibility.Visible && Image.IsMouseCaptured)
|
|
|
+ {
|
|
|
+ Point currentMousePosition = e.GetPosition(Image);
|
|
|
+ double deltaVerticalOffset = lastMousePosition.Y - currentMousePosition.Y;
|
|
|
+ double deltaHorizontalOffset = lastMousePosition.X - currentMousePosition.X;
|
|
|
+
|
|
|
+ double newVerticalOffset = startVerticalOffset + deltaVerticalOffset/3;
|
|
|
+ double newHorizontalOffset = startHorizontalOffset + deltaHorizontalOffset/3;
|
|
|
|
|
|
+ ImageSv.ScrollToVerticalOffset(newVerticalOffset);
|
|
|
+ ImageSv.ScrollToHorizontalOffset(newHorizontalOffset);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
@@ -174,10 +194,10 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
private WriteableBitmap LoadImage(CPDFPage pdfPage)
|
|
|
{
|
|
|
Size pageSize = pdfPage.PageSize;
|
|
|
- double ratio = CalculateThumbnailSize(pageSize);
|
|
|
- Rect pageRect = new Rect(0, 0, (int)(pageSize.Width / 72.0 * 96 * ratio), (int)(pageSize.Height / 72.0 * 96 * ratio));
|
|
|
- byte[] bmpData = new byte[(int)(pageRect.Width * pageRect.Height * (96 / 72.0) * (96 / 72.0) * 4)];
|
|
|
- pdfPage.RenderPageBitmapWithMatrix((float)(96 / 72.0 * ratio), pageRect, 0xFFFFFFFF, bmpData, 0, true);
|
|
|
+ double ratio = CalculateThumbnailSize(pageSize) * 3;
|
|
|
+ Rect pageRect = new Rect(0, 0, (int)(pageSize.Width * ratio), (int)(pageSize.Height * ratio));
|
|
|
+ byte[] bmpData = new byte[(int)(pageRect.Width * pageRect.Height * 4)];
|
|
|
+ pdfPage.RenderPageBitmapWithMatrix((float)ratio, pageRect, 0xFFFFFFFF, bmpData, 0, true);
|
|
|
|
|
|
WriteableBitmap writeableBitmap = new WriteableBitmap((int)pageRect.Width, (int)pageRect.Height, 96, 96, PixelFormats.Bgra32, null);
|
|
|
writeableBitmap.WritePixels(new Int32Rect(0, 0, (int)pageRect.Width, (int)pageRect.Height), bmpData, writeableBitmap.BackBufferStride, 0);
|
|
@@ -190,11 +210,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
if (size.Height / size.Width > aspectRatio)
|
|
|
{
|
|
|
- return thumbnailWidth / size.Width;
|
|
|
+ return (thumbnailWidth) / size.Width;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return thumbnailHeight / size.Height;
|
|
|
+ return (thumbnailHeight) / size.Height;
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -202,9 +222,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
private async void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
aspectRatio = ImageGd.ActualHeight / ImageGd.ActualWidth;
|
|
|
- thumbnailWidth = ImageGd.ActualWidth;
|
|
|
- thumbnailHeight = ImageGd.ActualHeight;
|
|
|
-
|
|
|
+ thumbnailWidth = ImageGd.ActualWidth - 20;
|
|
|
+ thumbnailHeight = ImageGd.ActualHeight - 20;
|
|
|
await LoadImageAsync(Document.PageAtIndex(0));
|
|
|
}
|
|
|
|
|
@@ -243,5 +262,21 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void ScaleBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ var button = sender as Button;
|
|
|
+ if (button != null)
|
|
|
+ {
|
|
|
+ if (button.Name == "ZoomInBtn")
|
|
|
+ {
|
|
|
+ Scale -= 0.1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Scale += 0.1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|