Fix #154: Switch to Pdfium; better PDF async loading

This commit is contained in:
Paddy Xu
2017-12-22 01:28:30 +02:00
parent 1bcfd8db08
commit fe39854b57
17 changed files with 1675 additions and 545 deletions

View File

@@ -0,0 +1,54 @@
// Copyright © 2017 Paddy Xu
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PDFiumSharp;
using QuickLook.Helpers;
namespace QuickLook.Plugin.PDFViewer
{
internal static class PdfPageExtension
{
public static BitmapSource RenderThumbnail(this PdfPage page)
{
var factorX = 130d / page.Width;
var factorY = 210d / page.Height;
return page.Render(Math.Min(factorX, factorY), false);
}
public static BitmapSource Render(this PdfPage page, double factor, bool fixDpi = true)
{
var scale = DpiHelper.GetCurrentScaleFactor();
var dpiX = fixDpi ? scale.Horizontal * DpiHelper.DefaultDpi : 96;
var dpiY = fixDpi ? scale.Vertical * DpiHelper.DefaultDpi : 96;
var realWidth = (int) Math.Ceiling(page.Width * (dpiX / 72) * factor);
var realHeight = (int) Math.Ceiling(page.Height * (dpiY / 72) * factor);
var bitmap = new WriteableBitmap(realWidth, realHeight, dpiX, dpiY, PixelFormats.Bgr24, null);
page.Render(bitmap,
flags: RenderingFlags.LimitImageCache | RenderingFlags.Annotations | RenderingFlags.DontCatch |
RenderingFlags.LcdText);
bitmap.Freeze();
return bitmap;
}
}
}