A Dijous 21 Setembre 2006 00:53, Wilfried Huss va escriure:
> Am Wednesday, 20. September 2006 23:14 schrieb Albert Astals Cid:
> > A Dijous 07 Setembre 2006 23:10, Wilfried Huss va escriure:
> > > Am Thursday, 7. September 2006 11:48 schrieb Brad Hards:
> > > > On Thursday 07 September 2006 19:07, Wilfried Huss wrote:
> > > > > 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.
> > > >
> > > > I'm not sure I fully understand this code, but it looks like you are
> > > > recalculating the links every time.
> > > >
> > > > Have you timed this?
> > >
> > > No I havn't. With the current code, if you want to access link
> > > information, you also need to call renderToImage() first, which is
> > > definitely not a cheap operation.
> >
> > It is if you want to show the page ;-)
> >
> > > > Is it worth trying to cache it?
> > >
> > > One could try to remember if the last time renderToImage() had been
> > > called with doLinks=true, and then use the cached version of the link
> > > data structure. But I'm not sure if it is really worth it.
> >
> > Could you please time the diferences in
> > render + getlinks that are there already
> > and
> > render + getlinks using your code
> > .
> >
> > I agree that making the library more functional using your patch may be a
> > good thing, but there is no necessity in making it slower for the rest,
> > no?
> >
> > BTW if you don't have time for it, tellme and i'll test it next week at
> > aKademy.
>
> Probably the easiest thing, would be to just use a flag in Poppler::Page to
> remember if the last call to render had doLinks=true. If yes use the cached
> Links like we do now, and if not create a link structure like in the new
> code.
Ok, i profiled a bit and the time spent reasking the links after you already
had them because you drawed the image was non trivial so i added the flag.
Do you agree with this patch?
Albert
>
> Greetings,
> Wilfried.
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
Index: qt/poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-page.cc,v
retrieving revision 1.17
diff -u -r1.17 poppler-page.cc
--- qt/poppler-page.cc 16 Aug 2006 14:35:14 -0000 1.17
+++ qt/poppler-page.cc 12 Oct 2006 15:55:18 -0000
@@ -37,6 +37,7 @@
const Document *doc;
int index;
PageTransition *transition;
+ bool didLinks;
};
Page::Page(const Document *doc, int index) {
@@ -44,6 +45,7 @@
data->index = index;
data->doc = doc;
data->transition = 0;
+ data->didLinks = false;
}
Page::~Page()
@@ -70,6 +72,7 @@
SplashColorPtr color_ptr;
output_dev = data->doc->data->getOutputDev();
+ data->didLinks = doLinks;
data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, xres, yres,
0, false, false, doLinks, -1, -1, -1, -1);
bitmap = output_dev->getBitmap ();
@@ -219,8 +222,16 @@
QValueList<Link*> Page::links() const
{
QValueList<Link*> popplerLinks;
+ Links *xpdfLinks;
- Links *xpdfLinks = data->doc->data->doc.takeLinks();
+ if (data->didLinks) xpdfLinks = data->doc->data->doc.takeLinks();
+ else 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: qt/poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-private.h,v
retrieving revision 1.8
diff -u -r1.8 poppler-private.h
--- qt/poppler-private.h 26 Jul 2006 18:16:01 -0000 1.8
+++ qt/poppler-private.h 12 Oct 2006 15:55:18 -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: qt/poppler-qt.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-qt.h,v
retrieving revision 1.21
diff -u -r1.21 poppler-qt.h
--- qt/poppler-qt.h 26 Jul 2006 18:16:01 -0000 1.21
+++ qt/poppler-qt.h 12 Oct 2006 15:55:18 -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
+
\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
*/
QValueList<Link*> links() const;
Index: qt4/src/poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.25.2.1
diff -u -r1.25.2.1 poppler-page.cc
--- qt4/src/poppler-page.cc 30 Sep 2006 16:25:15 -0000 1.25.2.1
+++ qt4/src/poppler-page.cc 12 Oct 2006 15:55:18 -0000
@@ -44,6 +44,7 @@
const Document *parentDoc;
int index;
PageTransition *transition;
+ bool didLinks;
};
Link* PageData::convertLinkActionToLink(::LinkAction * a, const QRectF &linkArea, DocumentData * doc)
@@ -147,6 +148,7 @@
m_page->index = index;
m_page->parentDoc = doc;
m_page->transition = 0;
+ m_page->didLinks = false;
}
Page::~Page()
@@ -161,6 +163,7 @@
int rotation = (int)rotate * 90;
+ m_page->didLinks = doLinks;
m_page->parentDoc->m_doc->doc.displayPageSlice(output_dev, m_page->index + 1, xres, yres,
rotation, false, true, doLinks, x, y, w, h);
@@ -411,8 +414,16 @@
QList<Link*> Page::links() const
{
QList<Link*> popplerLinks;
+ Links *xpdfLinks;
- Links *xpdfLinks = m_page->parentDoc->m_doc->doc.takeLinks();
+ if (m_page->didLinks) xpdfLinks = m_page->parentDoc->m_doc->doc.takeLinks();
+ else 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: qt4/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
--- qt4/src/poppler-private.h 24 Aug 2006 22:32:32 -0000 1.13
+++ qt4/src/poppler-private.h 12 Oct 2006 15:55:18 -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: qt4/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
--- qt4/src/poppler-qt4.h 25 Jun 2006 16:59:31 -0000 1.34
+++ qt4/src/poppler-qt4.h 12 Oct 2006 15:55:18 -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
\param rotate how to rotate the page
@@ -396,7 +396,7 @@
void defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown);
/**
- Gets the links of the page once it has been rendered if doLinks was true
+ Gets the links of the page
*/
QList<Link*> links() const;
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler