Hi,
attached are two patches (for the qt3 and qt4 bindings) which change
Page::links() in a way to make it work correctly even if the render function
was not called with doLinks=true previously. The current code results in a
crash in such a situation.
The doLinks parameter is now only needed if you want to draw link retangles
into the rendered image.
The patches are based on code that was recently posted by Krzysztof Kowalczyk.
Greetings,
Wilfried Huss
Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-page.cc,v
retrieving revision 1.17
diff -u -r1.17 poppler-page.cc
--- poppler-page.cc 16 Aug 2006 14:35:14 -0000 1.17
+++ poppler-page.cc 7 Sep 2006 08:53:55 -0000
@@ -220,7 +220,13 @@
{
QValueList<Link*> popplerLinks;
- Links *xpdfLinks = data->doc->data->doc.takeLinks();
+ Links *xpdfLinks = GetLinksForPage(&data->doc->data->doc, data->index + 1);
+
+ if (!xpdfLinks)
+ {
+ return popplerLinks;
+ }
+
for (int i = 0; i < xpdfLinks->getNumLinks(); ++i)
{
::Link *xpdfLink = xpdfLinks->getLink(i);
Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-private.h,v
retrieving revision 1.8
diff -u -r1.8 poppler-private.h
--- poppler-private.h 26 Jul 2006 18:16:01 -0000 1.8
+++ poppler-private.h 7 Sep 2006 08:53:55 -0000
@@ -22,6 +22,7 @@
#include <Outline.h>
#include <SplashOutputDev.h>
#include <Link.h>
+#include <Page.h>
#include <PDFDoc.h>
#include <FontInfo.h>
#include <UGooString.h>
@@ -45,6 +46,22 @@
u[i] = s.at(i).unicode();
return new UGooString(u, len);
}
+
+static Links *GetLinksForPage(PDFDoc *doc, int pageNo)
+{
+ if (pageNo <= 0)
+ return 0;
+
+ Catalog *catalog = doc->getCatalog();
+ ::Page *page = catalog->getPage(pageNo);
+
+ Object obj;
+ Object* annot = page->getAnnots(&obj);
+
+ Links *links = new Links(annot, catalog->getBaseURI());
+ obj.free();
+ return links;
+}
class LinkDestinationData {
public:
Index: poppler-qt.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-qt.h,v
retrieving revision 1.21
diff -u -r1.21 poppler-qt.h
--- poppler-qt.h 26 Jul 2006 18:16:01 -0000 1.21
+++ poppler-qt.h 7 Sep 2006 08:53:55 -0000
@@ -150,6 +150,8 @@
\param yres vertical resolution of the graphics device, in
dots per inch (defaults to 72 dpi)
+ \param doLinks draw links as rectangles
+
\returns a QImage of the page.
\sa renderToPixmap()
@@ -187,7 +189,7 @@
Orientation orientation() const;
/**
- Gets the links of the page once it has been rendered if doLinks was true
+ Gets the links of the page once it has been rendered
*/
QValueList<Link*> links() const;
Index: src/poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.24
diff -u -r1.24 poppler-page.cc
--- src/poppler-page.cc 1 Jun 2006 21:03:38 -0000 1.24
+++ src/poppler-page.cc 7 Sep 2006 08:54:16 -0000
@@ -314,7 +314,13 @@
{
QList<Link*> popplerLinks;
- Links *xpdfLinks = m_page->parentDoc->m_doc->doc.takeLinks();
+ Links *xpdfLinks = GetLinksForPage(&m_page->parentDoc->m_doc->doc, m_page->index + 1);
+
+ if (!xpdfLinks)
+ {
+ return popplerLinks;
+ }
+
for (int i = 0; i < xpdfLinks->getNumLinks(); ++i)
{
::Link *xpdfLink = xpdfLinks->getLink(i);
Index: src/poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-private.h,v
retrieving revision 1.13
diff -u -r1.13 poppler-private.h
--- src/poppler-private.h 24 Aug 2006 22:32:32 -0000 1.13
+++ src/poppler-private.h 7 Sep 2006 08:54:16 -0000
@@ -24,6 +24,7 @@
#include <GlobalParams.h>
#include <Link.h>
#include <Outline.h>
+#include <Page.h>
#include <PDFDoc.h>
#include <FontInfo.h>
#include <SplashOutputDev.h>
@@ -51,6 +52,22 @@
return new UGooString(u, len);
}
+ static Links *GetLinksForPage(PDFDoc *doc, int pageNo)
+ {
+ if (pageNo <= 0)
+ return 0;
+
+ Catalog *catalog = doc->getCatalog();
+ ::Page *page = catalog->getPage(pageNo);
+
+ Object obj;
+ Object* annot = page->getAnnots(&obj);
+
+ Links *links = new Links(annot, catalog->getBaseURI());
+ obj.free();
+ return links;
+ }
+
class LinkDestinationData
{
public:
Index: src/poppler-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.34
diff -u -r1.34 poppler-qt4.h
--- src/poppler-qt4.h 25 Jun 2006 16:59:31 -0000 1.34
+++ src/poppler-qt4.h 7 Sep 2006 08:54:16 -0000
@@ -255,7 +255,7 @@
\param yres vertical resolution of the graphics device, in
dots per inch
- \param doLinks calculate links
+ \param doLinks draw links as rectangles
\param rotate how to rotate the page
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler