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/>.
|
|
|
|
|
|
|
|
#ifndef PDFRENDERER_H
|
|
|
|
#define PDFRENDERER_H
|
|
|
|
|
|
|
|
#include "pdfpage.h"
|
2019-04-29 17:03:19 +02:00
|
|
|
#include "pdfexception.h"
|
2019-09-28 18:26:31 +02:00
|
|
|
#include "pdfmeshqualitysettings.h"
|
2019-02-09 18:40:56 +01:00
|
|
|
|
2019-02-14 19:45:07 +01:00
|
|
|
class QPainter;
|
2019-02-09 18:40:56 +01:00
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
{
|
2019-04-12 19:17:19 +02:00
|
|
|
class PDFFontCache;
|
2019-07-04 17:52:38 +02:00
|
|
|
class PDFOptionalContentActivity;
|
2019-02-09 18:40:56 +01:00
|
|
|
|
|
|
|
/// Renders the PDF page on the painter, or onto an image.
|
|
|
|
class PDFRenderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Feature
|
|
|
|
{
|
2019-07-06 15:55:37 +02:00
|
|
|
Antialiasing = 0x0001, ///< Antialiasing for lines, shapes, etc.
|
|
|
|
TextAntialiasing = 0x0002, ///< Antialiasing for drawing text
|
|
|
|
SmoothImages = 0x0004, ///< Adjust images to the device space using smooth transformation (slower, but better image quality)
|
|
|
|
IgnoreOptionalContent = 0x0008, ///< Ignore optional content (so all is drawn ignoring settings of optional content)
|
2019-09-01 15:44:22 +02:00
|
|
|
ClipToCropBox = 0x0010, ///< Clip page content to crop box (items outside crop box will not be visible)
|
2019-02-09 18:40:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_FLAGS(Features, Feature)
|
|
|
|
|
2019-09-28 18:26:31 +02:00
|
|
|
explicit PDFRenderer(const PDFDocument* document, const PDFFontCache* fontCache, const PDFOptionalContentActivity* optionalContentActivity, Features features, const PDFMeshQualitySettings& meshQualitySettings);
|
2019-07-06 15:55:37 +02:00
|
|
|
|
2019-02-09 18:40:56 +01:00
|
|
|
/// Paints desired page onto the painter. Page is painted in the rectangle using best-fit method.
|
|
|
|
/// If the page doesn't exist, then error is returned. No exception is thrown. Rendering errors
|
|
|
|
/// are reported and returned in the error list. If no error occured, empty list is returned.
|
|
|
|
/// \param painter Painter
|
|
|
|
/// \param rectangle Paint area for the page
|
|
|
|
/// \param pageIndex Index of the page to be painted
|
|
|
|
QList<PDFRenderError> render(QPainter* painter, const QRectF& rectangle, size_t pageIndex) const;
|
|
|
|
|
2019-02-24 17:48:37 +01:00
|
|
|
/// Paints desired page onto the painter. Page is painted using \p matrix, which maps page coordinates
|
|
|
|
/// to the device coordinates. If the page doesn't exist, then error is returned. No exception is thrown.
|
|
|
|
/// Rendering errors are reported and returned in the error list. If no error occured, empty list is returned.
|
|
|
|
QList<PDFRenderError> render(QPainter* painter, const QMatrix& matrix, size_t pageIndex) const;
|
|
|
|
|
2019-07-06 15:55:37 +02:00
|
|
|
/// Returns default renderer features
|
2019-09-01 15:44:22 +02:00
|
|
|
static constexpr Features getDefaultFeatures() { return Antialiasing | TextAntialiasing | ClipToCropBox; }
|
2019-07-06 15:55:37 +02:00
|
|
|
|
2019-02-09 18:40:56 +01:00
|
|
|
private:
|
|
|
|
const PDFDocument* m_document;
|
2019-04-12 19:17:19 +02:00
|
|
|
const PDFFontCache* m_fontCache;
|
2019-07-04 17:52:38 +02:00
|
|
|
const PDFOptionalContentActivity* m_optionalContentActivity;
|
2019-02-09 18:40:56 +01:00
|
|
|
Features m_features;
|
2019-09-28 18:26:31 +02:00
|
|
|
PDFMeshQualitySettings m_meshQualitySettings;
|
2019-02-09 18:40:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(pdf::PDFRenderer::Features)
|
|
|
|
|
|
|
|
#endif // PDFRENDERER_H
|