mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2024-12-26 16:22:50 +01:00
DocPage Organizer: page image preview
This commit is contained in:
parent
97151df84c
commit
edcd992697
@ -34,6 +34,8 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QImageReader>
|
||||
#include <QPixmapCache>
|
||||
#include <QScreen>
|
||||
#include <QGuiApplication>
|
||||
|
||||
namespace pdfdocpage
|
||||
{
|
||||
@ -126,6 +128,14 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize pixmap cache size
|
||||
const int depth = 4; // 4 bytes (ARGB)
|
||||
const int reserveSize = 2; // Caching of two screens
|
||||
QSize size = QGuiApplication::primaryScreen()->availableVirtualSize();
|
||||
int bytes = size.width() * size.height() * depth * reserveSize;
|
||||
int kBytes = bytes / 1024;
|
||||
QPixmapCache::setCacheLimit(kBytes);
|
||||
|
||||
loadSettings();
|
||||
updateActions();
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "pdfwidgetutils.h"
|
||||
#include "pdfpainterutils.h"
|
||||
#include "pdfrenderer.h"
|
||||
#include "pdfcompiler.h"
|
||||
#include "pdfconstants.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
@ -29,9 +31,13 @@ namespace pdfdocpage
|
||||
|
||||
PageItemDelegate::PageItemDelegate(PageItemModel* model, QObject* parent) :
|
||||
BaseClass(parent),
|
||||
m_model(model)
|
||||
m_model(model),
|
||||
m_rasterizer(nullptr)
|
||||
{
|
||||
|
||||
m_rasterizer = new pdf::PDFRasterizer(this);
|
||||
QSurfaceFormat format;
|
||||
format.setSamples(16);
|
||||
m_rasterizer->reset(true, format);
|
||||
}
|
||||
|
||||
PageItemDelegate::~PageItemDelegate()
|
||||
@ -161,7 +167,37 @@ QPixmap PageItemDelegate::getPageImagePixmap(const PageGroupItem* item, QRect re
|
||||
switch (groupItem.pageType)
|
||||
{
|
||||
case pdfdocpage::PT_DocumentPage:
|
||||
{
|
||||
const auto& documents = m_model->getDocuments();
|
||||
auto it = documents.find(groupItem.documentIndex);
|
||||
if (it != documents.cend())
|
||||
{
|
||||
const pdf::PDFDocument& document = it->second.document;
|
||||
const pdf::PDFInteger pageIndex = groupItem.pageIndex - 1;
|
||||
if (pageIndex >= 0 && pageIndex < pdf::PDFInteger(document.getCatalog()->getPageCount()))
|
||||
{
|
||||
const pdf::PDFPage* page = document.getCatalog()->getPage(pageIndex);
|
||||
Q_ASSERT(page);
|
||||
|
||||
pdf::PDFPrecompiledPage compiledPage;
|
||||
pdf::PDFFontCache fontCache(pdf::DEFAULT_FONT_CACHE_LIMIT, pdf::DEFAULT_REALIZED_FONT_CACHE_LIMIT);
|
||||
pdf::PDFCMSManager cmsManager(nullptr);
|
||||
pdf::PDFOptionalContentActivity optionalContentActivity(&document, pdf::OCUsage::View, nullptr);
|
||||
|
||||
fontCache.setDocument(pdf::PDFModifiedDocument(const_cast<pdf::PDFDocument*>(&document), &optionalContentActivity));
|
||||
cmsManager.setDocument(&document);
|
||||
|
||||
pdf::PDFCMSPointer cms = cmsManager.getCurrentCMS();
|
||||
pdf::PDFRenderer renderer(&document, &fontCache, cms.data(), &optionalContentActivity, pdf::PDFRenderer::getDefaultFeatures(), pdf::PDFMeshQualitySettings());
|
||||
renderer.compile(&compiledPage, pageIndex);
|
||||
|
||||
QSize imageSize = rect.size();
|
||||
QImage pageImage = m_rasterizer->render(pageIndex, page, &compiledPage, imageSize, pdf::PDFRenderer::getDefaultFeatures(), nullptr, groupItem.pageAdditionalRotation);
|
||||
pixmap = QPixmap::fromImage(qMove(pageImage));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case pdfdocpage::PT_Image:
|
||||
{
|
||||
|
@ -18,6 +18,9 @@
|
||||
#ifndef PDFDOCPAGEORGANIZER_PAGEITEMDELEGATE_H
|
||||
#define PDFDOCPAGEORGANIZER_PAGEITEMDELEGATE_H
|
||||
|
||||
#include "pdfrenderer.h"
|
||||
#include "pdfcms.h"
|
||||
|
||||
#include <QAbstractItemDelegate>
|
||||
|
||||
namespace pdfdocpage
|
||||
@ -51,6 +54,7 @@ private:
|
||||
|
||||
PageItemModel* m_model;
|
||||
QSize m_pageImageSize;
|
||||
pdf::PDFRasterizer* m_rasterizer;
|
||||
};
|
||||
|
||||
} // namespace pdfdocpage
|
||||
|
@ -845,7 +845,7 @@ QImage PDFDrawWidgetProxy::drawThumbnailImage(PDFInteger pageIndex, int pixelSiz
|
||||
if (compiledPage && compiledPage->isValid())
|
||||
{
|
||||
// Rasterize the image.
|
||||
image = m_rasterizer->render(pageIndex, page, compiledPage, imageSize, m_features, m_widget->getAnnotationManager());
|
||||
image = m_rasterizer->render(pageIndex, page, compiledPage, imageSize, m_features, m_widget->getAnnotationManager(), PageRotation::None);
|
||||
}
|
||||
|
||||
if (image.isNull())
|
||||
|
@ -209,11 +209,12 @@ QImage PDFRasterizer::render(PDFInteger pageIndex,
|
||||
const PDFPrecompiledPage* compiledPage,
|
||||
QSize size,
|
||||
PDFRenderer::Features features,
|
||||
const PDFAnnotationManager* annotationManager)
|
||||
const PDFAnnotationManager* annotationManager,
|
||||
PageRotation extraRotation)
|
||||
{
|
||||
QImage image;
|
||||
|
||||
QMatrix matrix = PDFRenderer::createPagePointToDevicePointMatrix(page, QRect(QPoint(0, 0), size));
|
||||
QMatrix matrix = PDFRenderer::createPagePointToDevicePointMatrix(page, QRect(QPoint(0, 0), size), extraRotation);
|
||||
if (m_features.testFlag(UseOpenGL) && m_features.testFlag(ValidOpenGL))
|
||||
{
|
||||
// We have valid OpenGL context, try to select it and possibly create framebuffer object
|
||||
@ -464,7 +465,7 @@ void PDFRasterizerPool::render(const std::vector<PDFInteger>& pageIndices,
|
||||
pageTimer.restart();
|
||||
PDFRasterizer* rasterizer = acquire();
|
||||
qint64 pageWaitTime = pageTimer.restart();
|
||||
QImage image = rasterizer->render(pageIndex, page, &precompiledPage, imageSizeGetter(page), m_features, &annotationManager);
|
||||
QImage image = rasterizer->render(pageIndex, page, &precompiledPage, imageSizeGetter(page), m_features, &annotationManager, PageRotation::None);
|
||||
qint64 pageRenderTime = pageTimer.elapsed();
|
||||
release(rasterizer);
|
||||
|
||||
|
@ -126,7 +126,7 @@ private:
|
||||
/// if it is enabled, if this is the case, offscreen rendering to framebuffer
|
||||
/// is used.
|
||||
/// \note Construct this object only in main GUI thread
|
||||
class PDFRasterizer : public QObject
|
||||
class Pdf4QtLIBSHARED_EXPORT PDFRasterizer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -163,12 +163,14 @@ public:
|
||||
/// \param size Size of the target image
|
||||
/// \param features Renderer features
|
||||
/// \param annotationManager Annotation manager (can be nullptr)
|
||||
/// \param extraRotation Extra page rotation
|
||||
QImage render(PDFInteger pageIndex,
|
||||
const PDFPage* page,
|
||||
const PDFPrecompiledPage* compiledPage,
|
||||
QSize size,
|
||||
PDFRenderer::Features features,
|
||||
const PDFAnnotationManager* annotationManager);
|
||||
const PDFAnnotationManager* annotationManager,
|
||||
PageRotation extraRotation);
|
||||
|
||||
private:
|
||||
void initializeOpenGL();
|
||||
|
Loading…
Reference in New Issue
Block a user