summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2006-01-05 13:53:58 +0000
committerAlbert Astals Cid <aacid@kde.org>2006-01-05 13:53:58 +0000
commit0dc16af02071350a0dc11af4106799378c99cdad (patch)
tree6113cdaca3ce041a016a0c8efcd6cac9f62a4ef3
parent5c2cbf5d327c6cc75c073b56c3ab1748c0d24387 (diff)
Introduce variants of renderTo that return a QImage and do not use a QPixmap so threading is possible.
-rw-r--r--ChangeLog8
-rw-r--r--qt/poppler-page.cc18
-rw-r--r--qt/poppler-qt.h30
-rw-r--r--qt4/src/poppler-page.cc9
-rw-r--r--qt4/src/poppler-qt4.h59
5 files changed, 85 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index af01b8af..905b071b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2006-01-02 Albert Astals Cid <aacid@kde.org>
+ * qt/poppler-page.cc:
+ * qt/poppler-qt.h:
+ * qt4/src/poppler-page.cc:
+ * qt4/src/poppler-qt4.h: Introduce variants of renderTo that return a
+ QImage and do not use a QPixmap so threading is possible.
+
+2006-01-02 Albert Astals Cid <aacid@kde.org>
+
* poppler/PageTransition.cc: Use error() insted of std::cerr
Sun Jan 1 18:50:51 2006 Jonathan Blandford <jrb@redhat.com>
diff --git a/qt/poppler-page.cc b/qt/poppler-page.cc
index 7c332884..b2a3bdab 100644
--- a/qt/poppler-page.cc
+++ b/qt/poppler-page.cc
@@ -59,31 +59,37 @@ void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h) const
void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const
{
+ QImage img = renderToImage(xres, yres);
+ *q = new QPixmap( img );
+}
+
+QImage Page::renderToImage(double xres, double yres) const
+{
SplashOutputDev *output_dev;
SplashBitmap *bitmap;
SplashColorPtr color_ptr;
output_dev = data->doc->data->getOutputDev();
-
+
data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, xres, yres,
0, false, false, false, -1, -1, -1, -1);
bitmap = output_dev->getBitmap ();
color_ptr = bitmap->getDataPtr ();
int bw = output_dev->getBitmap()->getWidth();
int bh = output_dev->getBitmap()->getHeight();
- QImage * img = new QImage( bw, bh, 32 );
+
+ QImage img( bw, bh, 32 );
SplashColorPtr pixel = new Guchar[4];
for (int i = 0; i < bw; i++)
{
for (int j = 0; j < bh; j++)
{
output_dev->getBitmap()->getPixel(i, j, pixel);
- img->setPixel( i, j, qRgb( pixel[0], pixel[1], pixel[2] ) );
+ img.setPixel( i, j, qRgb( pixel[0], pixel[1], pixel[2] ) );
}
}
delete[] pixel;
- *q = new QPixmap( *img );
-
- delete img;
+
+ return img;
}
QString Page::getText(const Rectangle &r) const
diff --git a/qt/poppler-qt.h b/qt/poppler-qt.h
index c0172a15..42d7e4b1 100644
--- a/qt/poppler-qt.h
+++ b/qt/poppler-qt.h
@@ -128,12 +128,32 @@ class Page {
void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const;
/**
- * This is a convenience function that is equivalent to
- * renderToPixmap() with xres and yres set to 72.0. We keep it
- * only for binary compatibility
- **/
+ This is a convenience function that is equivalent to
+ renderToPixmap() with xres and yres set to 72.0. We keep it
+ only for binary compatibility
+
+ \sa renderToImage()
+ */
void renderToPixmap(QPixmap **q, int x, int y, int w, int h) const;
-
+
+ /**
+ \brief Render the page to a QImage using the Splash renderer
+
+ This method can be used to render the page to a QImage. It
+ uses the "Splash" rendering engine.
+
+ \param xres horizontal resolution of the graphics device,
+ in dots per inch (defaults to 72 dpi)
+
+ \param yres vertical resolution of the graphics device, in
+ dots per inch (defaults to 72 dpi)
+
+ \returns a QImage of the page.
+
+ \sa renderToPixmap()
+ */
+ QImage renderToImage(double xres = 72.0, double yres = 72.0) const;
+
/**
* Returns the size of the page in points
**/
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index fe617f00..f625beb5 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -55,7 +55,7 @@ Page::~Page()
delete m_page;
}
-QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int w, int h) const
+QImage Page::splashRenderToImage(double xres, double yres, int x, int y, int w, int h) const
{
SplashOutputDev *output_dev = m_page->parentDoc->m_doc->getSplashOutputDev();
@@ -86,6 +86,13 @@ QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int
}
delete[] pixel;
+ return img;
+}
+
+QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int w, int h) const
+{
+ QImage img = splashRenderToImage(xres, yres, x, y, w, h);
+
// Turn the QImage into a QPixmap
QPixmap* out = new QPixmap(QPixmap::fromImage(img));
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 29b80f63..61987c56 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -153,31 +153,14 @@ namespace Poppler {
public:
~Page();
- /**
- Render the page to a QPixmap using the Splash renderer
-
+ /**
+ Render the page to a QImage using the Splash renderer
+
This method can be used to render the page to a QPixmap. It
- uses the "Splash" rendering engine that is included in the
- Poppler distribution. This method is reasonably well-tested
- and has produced good output so far. This method is used as
- follows.
-
-@code
-Poppler::Page* pdfPage;
-
-// Generate a QPixmap of the rendered page
-QPixmap* pixmap = pdfPage->splashRenderToPixmap(0, 0, 0, 0, xres, yres );
-if (pixmap == 0) {
- ... error message ...
- return;
-}
-
-... use pixmap ...
-
-delete pixmap;
-@endcode
-
- If x=y=w=h=-1, the method will automatically compute the
+ uses the "Splash" rendering engine. This method is reasonably
+ well-tested and has produced good output so far.
+
+ If x=y=w=h=-1, the method will automatically compute the
size of the pixmap from the horizontal and vertical
resolutions specified in xres and yres. Otherwise, the
method renders only a part of the page, specified by the
@@ -205,11 +188,33 @@ delete pixmap;
well-tested. Unusual or meaningless parameters may lead to
rather unexpected results.
- \returns pointer to a QPixmap, or NULL on failure. The
- pixmap returned must be deleted.
+ \returns a QImage of the page, or a null image on failure.
+ */
+ QImage splashRenderToImage(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1) const;
+
+ /**
+ Render the page to a QPixmap using the Splash renderer
+
+ This member function is provided for convenience. It behaves essentially like the above function.
+ It is used as follows.
+
+@code
+Poppler::Page* pdfPage;
+
+// Generate a QPixmap of the rendered page
+QPixmap* pixmap = pdfPage->splashRenderToPixmap(0, 0, 0, 0, xres, yres );
+if (pixmap == 0) {
+ ... error message ...
+ return;
+}
+
+... use pixmap ...
+
+delete pixmap;
+@endcode
*/
QPixmap *splashRenderToPixmap(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1) const;
-
+
/**
Render the page to a pixmap using the Arthur (Qt4) renderer