summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorPino Toscano <pino@kde.org>2010-11-07 21:50:48 +0100
committerPino Toscano <pino@kde.org>2010-11-07 21:50:48 +0100
commitf077e82af0724be88d28c896a3c208f1d50ccff9 (patch)
treedf398249d0123b3ef7ccf233d8d7dc06d675c05f /qt4
parentdf02d1fc9e65422121e5e8f493c13229552ec0e7 (diff)
[qt4] New Page::renderToPainter()
This new painter-based painting function ican be used for painting (with Arthur only for now) without getting an image first. Also add a new flag type for it, with a single item telling whether do not save+restore the provided painter. Mostly based on a patch by Matthias Fauconneau (matthias.fauconneau@gmail.com), thanks!
Diffstat (limited to 'qt4')
-rw-r--r--qt4/src/poppler-page.cc62
-rw-r--r--qt4/src/poppler-qt4.h65
2 files changed, 107 insertions, 20 deletions
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 293d09b1..1b55c33d 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -8,6 +8,7 @@
* Copyright (C) 2009 Shawn Rutledge <shawn.t.rutledge@gmail.com>
* Copyright (C) 2010, Guillermo Amaral <gamaral@kdab.com>
* Copyright (C) 2010 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
+ * Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau@gmail.com>
*
* 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
@@ -250,25 +251,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
QImage tmpimg(w == -1 ? qRound( size.width() * xres / 72.0 ) : w, h == -1 ? qRound( size.height() * yres / 72.0 ) : h, QImage::Format_ARGB32);
QPainter painter(&tmpimg);
- if (m_page->parentDoc->m_hints & Document::Antialiasing)
- painter.setRenderHint(QPainter::Antialiasing);
- if (m_page->parentDoc->m_hints & Document::TextAntialiasing)
- painter.setRenderHint(QPainter::TextAntialiasing);
- painter.translate(x == -1 ? 0 : -x, y == -1 ? 0 : -y);
- ArthurOutputDev arthur_output(&painter);
- arthur_output.startDoc(m_page->parentDoc->doc->getXRef());
- m_page->parentDoc->doc->displayPageSlice(&arthur_output,
- m_page->index + 1,
- xres,
- yres,
- rotation,
- false,
- true,
- false,
- x,
- y,
- w,
- h);
+ renderToPainter(&painter, xres, yres, x, y, w, h, rotate, DontSaveAndRestore);
painter.end();
img = tmpimg;
break;
@@ -278,6 +261,47 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
return img;
}
+bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, int y, int w, int h, Rotation rotate, PainterFlags flags) const
+{
+ if (!painter)
+ return false;
+
+ switch(m_page->parentDoc->m_backend)
+ {
+ case Poppler::Document::SplashBackend:
+ return false;
+ case Poppler::Document::ArthurBackend:
+ {
+ const bool savePainter = !(flags & DontSaveAndRestore);
+ if (savePainter)
+ painter->save();
+ if (m_page->parentDoc->m_hints & Document::Antialiasing)
+ painter->setRenderHint(QPainter::Antialiasing);
+ if (m_page->parentDoc->m_hints & Document::TextAntialiasing)
+ painter->setRenderHint(QPainter::TextAntialiasing);
+ painter->translate(x == -1 ? 0 : -x, y == -1 ? 0 : -y);
+ ArthurOutputDev arthur_output(painter);
+ arthur_output.startDoc(m_page->parentDoc->doc->getXRef());
+ m_page->parentDoc->doc->displayPageSlice(&arthur_output,
+ m_page->index + 1,
+ xres,
+ yres,
+ (int)rotate * 90,
+ false,
+ true,
+ false,
+ x,
+ y,
+ w,
+ h);
+ if (savePainter)
+ painter->restore();
+ return true;
+ }
+ }
+ return false;
+}
+
QImage Page::thumbnail() const
{
unsigned char* data = 0;
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index d742973b..c50e4f9f 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -3,9 +3,10 @@
* Copyright (C) 2005, 2007, Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2005-2010, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2005, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de>
- * Copyright (C) 2006-2009, Pino Toscano <pino@kde.org>
+ * Copyright (C) 2006-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2009 Shawn Rutledge <shawn.t.rutledge@gmail.com>
* Copyright (C) 2010 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
+ * Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau@gmail.com>
*
* 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
@@ -398,6 +399,22 @@ delete it;
RawOrderLayout ///< The text is returned without any type of processing
};
+ /**
+ Additional flags for the renderToPainter method
+ \since 0.16
+ */
+ enum PainterFlag {
+ /**
+ Do not save/restore the caller-owned painter.
+
+ renderToPainter() by default preserves, using save() + restore(),
+ the state of the painter specified; if this is not needed, this
+ flag can avoid this job
+ */
+ DontSaveAndRestore = 0x00000001
+ };
+ Q_DECLARE_FLAGS( PainterFlags, PainterFlag )
+
/**
Render the page to a QImage using the current
\link Document::renderBackend() Document renderer\endlink.
@@ -438,6 +455,51 @@ delete it;
*/
QImage renderToImage(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1, Rotation rotate = Rotate0) const;
+ /**
+ Render the page to the specified QPainter using the current
+ \link Document::renderBackend() Document renderer\endlink.
+
+ If \p x = \p y = \p w = \p h = -1, the method will automatically
+ compute the size of the page area from the horizontal and vertical
+ resolutions specified in \p xres and \p yres. Otherwise, the
+ method renders only a part of the page, specified by the
+ parameters (\p x, \p y, \p w, \p h) in pixel coordinates.
+
+ \param painter the painter to paint on
+
+ \param x specifies the left x-coordinate of the box, in
+ pixels.
+
+ \param y specifies the top y-coordinate of the box, in
+ pixels.
+
+ \param w specifies the width of the box, in pixels.
+
+ \param h specifies the height of the box, in pixels.
+
+ \param xres horizontal resolution of the graphics device,
+ in dots per inch
+
+ \param yres vertical resolution of the graphics device, in
+ dots per inch
+
+ \param rotate how to rotate the page
+
+ \param flags additional painter flags
+
+ \warning The parameter (\p x, \p y, \p w, \p h) are not
+ well-tested. Unusual or meaningless parameters may lead to
+ rather unexpected results.
+
+ \returns whether the painting succeeded
+
+ \note This method is only supported for Arthur
+
+ \since 0.16
+ */
+ bool renderToPainter(QPainter* painter, double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1,
+ Rotation rotate = Rotate0, PainterFlags flags = 0) const;
+
/**
Get the page thumbnail if it exists.
@@ -1626,6 +1688,7 @@ height = dummy.height();
}
+Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Page::PainterFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Document::RenderHints)
Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PDFConverter::PDFOptions)
Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PSConverter::PSOptions)