1
0
mirror of https://github.com/JakubMelka/PDF4QT.git synced 2025-01-20 04:18:28 +01:00
PDF4QT/PdfForQtLib/sources/pdfrenderer.cpp

80 lines
2.7 KiB
C++
Raw Normal View History

2019-02-09 18:40:56 +01:00
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfrenderer.h"
2019-02-24 17:48:37 +01:00
#include "pdfpainter.h"
2019-02-09 18:40:56 +01:00
#include "pdfdocument.h"
namespace pdf
{
PDFRenderer::PDFRenderer(const PDFDocument* document) :
m_document(document),
2019-02-21 19:35:07 +01:00
m_features(Antialiasing | TextAntialiasing)
2019-02-09 18:40:56 +01:00
{
Q_ASSERT(document);
}
2019-02-24 17:48:37 +01:00
// TODO: Dodelat features, napr. antialiasing
// TODO: Dodelat rotovani stranek
// TODO: Dodelat obrazky
2019-02-09 18:40:56 +01:00
QList<PDFRenderError> PDFRenderer::render(QPainter* painter, const QRectF& rectangle, size_t pageIndex) const
{
Q_UNUSED(painter);
Q_UNUSED(rectangle);
const PDFCatalog* catalog = m_document->getCatalog();
if (pageIndex >= catalog->getPageCount() || !catalog->getPage(pageIndex))
{
// Invalid page index
return { PDFRenderError(RenderErrorType::Error, PDFTranslationContext::tr("Page %1 doesn't exist.").arg(pageIndex + 1)) };
}
const PDFPage* page = catalog->getPage(pageIndex);
Q_ASSERT(page);
2019-02-24 17:48:37 +01:00
QRectF mediaBox = page->getMediaBox();
2019-02-16 18:26:16 +01:00
2019-02-24 17:48:37 +01:00
QMatrix matrix;
matrix.translate(rectangle.left(), rectangle.bottom());
matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height());
2019-02-16 18:26:16 +01:00
2019-02-24 17:48:37 +01:00
PDFPainter processor(painter, m_features, matrix, page, m_document);
return processor.processContents();
2019-02-17 18:01:22 +01:00
}
2019-02-24 17:48:37 +01:00
QList<PDFRenderError> PDFRenderer::render(QPainter* painter, const QMatrix& matrix, size_t pageIndex) const
2019-02-21 19:35:07 +01:00
{
2019-02-24 17:48:37 +01:00
Q_UNUSED(painter);
2019-02-21 19:35:07 +01:00
2019-02-24 17:48:37 +01:00
const PDFCatalog* catalog = m_document->getCatalog();
if (pageIndex >= catalog->getPageCount() || !catalog->getPage(pageIndex))
2019-02-17 18:01:22 +01:00
{
2019-02-24 17:48:37 +01:00
// Invalid page index
return { PDFRenderError(RenderErrorType::Error, PDFTranslationContext::tr("Page %1 doesn't exist.").arg(pageIndex + 1)) };
2019-02-17 18:01:22 +01:00
}
2019-02-24 17:48:37 +01:00
const PDFPage* page = catalog->getPage(pageIndex);
Q_ASSERT(page);
2019-02-17 18:01:22 +01:00
2019-02-24 17:48:37 +01:00
PDFPainter processor(painter, m_features, matrix, page, m_document);
return processor.processContents();
2019-02-17 18:01:22 +01:00
}
2019-02-09 18:40:56 +01:00
} // namespace pdf