diff options
Diffstat (limited to 'src/gui/previewwindow.cpp')
-rw-r--r-- | src/gui/previewwindow.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 5452a7e..724a951 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -46,7 +46,14 @@ PreviewWindow::~PreviewWindow() void PreviewWindow::setPdf(QString file) { Poppler::Document *oldDoc = _doc; - Poppler::Document *newDoc = Poppler::Document::load(file); + + // use loadFromData to avoid holding a lock on the PDF file in windows + QFile f(file); + f.open(QFile::ReadOnly); + QByteArray data = f.readAll(); + f.close(); + Poppler::Document *newDoc = Poppler::Document::loadFromData(data); + if (!newDoc) { QMessageBox::warning(nullptr, "Could not read PDF", @@ -90,11 +97,14 @@ void PreviewWindow::render() { QSizeF size = _page->pageSizeF(); + qreal ratio = devicePixelRatioF(); QRect rect = ui->scrollArea->visibleRegion().boundingRect(); - int w = rect.width() - 20; - int h = rect.height() - 20; + int w = static_cast<int>(ratio * (rect.width() - 20)); + int h = static_cast<int>(ratio * (rect.height() - 20)); qreal scale = fmin(static_cast<qreal>(w) / size.width(), static_cast<qreal>(h) / size.height()); + + int dpi = static_cast<int>(scale * 72.0); int w1 = static_cast<int>(scale * size.width()); int h1 = static_cast<int>(scale * size.height()); @@ -106,6 +116,7 @@ void PreviewWindow::render() { // qDebug() << "scale:" << scale; // qDebug() << "dpi:" << dpi; - QImage img = _page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h); - ui->pdf->setPixmap(QPixmap::fromImage(img)); + QPixmap pm = QPixmap::fromImage(_page->renderToImage(dpi, dpi, (w1 - w)/2, (h1 - h)/2, w, h)); + pm.setDevicePixelRatio(ratio); + ui->pdf->setPixmap(pm); } |