summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.t.rutledge@gmail.com>2009-06-03 01:19:16 +0200
committerPino Toscano <pino@kde.org>2009-06-03 01:19:16 +0200
commit1f1baf186f9e37606765e51ec5b9893ddfbfa893 (patch)
tree86908b976269e62db06764a57b162612fdc2a38a /qt4
parent5cc24be1e9af0a27ab88ffa719bcabc2378868e4 (diff)
[Qt4] Add Page::thumbnail()
This function can be used to get the embedded thumbnail of the page, present in the document. Reindented by me, and avoid a memory leak because of non-freed data.
Diffstat (limited to 'qt4')
-rw-r--r--qt4/src/poppler-page.cc21
-rw-r--r--qt4/src/poppler-qt4.h11
2 files changed, 31 insertions, 1 deletions
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 9a27538f..f3edfe6b 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -3,8 +3,9 @@
* Copyright (C) 2005, Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2005-2008, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2005, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de>
- * Copyright (C) 2006-2008, Pino Toscano <pino@kde.org>
+ * Copyright (C) 2006-2009, Pino Toscano <pino@kde.org>
* Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
+ * Copyright (C) 2009 Shawn Rutledge <shawn.t.rutledge@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
@@ -277,6 +278,24 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
return img;
}
+QImage Page::thumbnail() const
+{
+ unsigned char* data = 0;
+ int w = 0;
+ int h = 0;
+ int rowstride = 0;
+ GBool r = m_page->page->loadThumb(&data, &w, &h, &rowstride);
+ QImage ret;
+ if (r)
+ {
+ // first construct a temporary image with the data got,
+ // then force a copy of it so we can free the raw thumbnail data
+ ret = QImage(data, w, h, rowstride, QImage::Format_RGB888).copy();
+ gfree(data);
+ }
+ return ret;
+}
+
QString Page::text(const QRectF &r) const
{
TextOutputDev *output_dev;
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 05c4c0de..257162ec 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -4,6 +4,7 @@
* Copyright (C) 2005-2008, 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) 2009 Shawn Rutledge <shawn.t.rutledge@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
@@ -417,6 +418,16 @@ while (it->hasNext()) {
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;
/**
+ Get the page thumbnail if it exists.
+
+ \return a QImage of the thumbnail, or a null image
+ if the PDF does not contain one for this page
+
+ \since 0.12
+ */
+ QImage thumbnail() const;
+
+ /**
Returns the text that is inside a specified rectangle
\param rect the rectangle specifying the area of interest,