[poppler] poppler/qt4/src: Makefile.am, 1.9,
1.10 poppler-document.cc, 1.18, 1.19 poppler-link.cc, 1.1,
1.2 poppler-link.h, NONE, 1.1 poppler-page.cc, 1.19,
1.20 poppler-private.h, 1.9, 1.10 poppler-qt4.h, 1.30, 1.31
Albert Astals Cid
aacid at kemper.freedesktop.org
Tue May 9 13:07:08 PDT 2006
Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv22989/qt4/src
Modified Files:
Makefile.am poppler-document.cc poppler-link.cc
poppler-page.cc poppler-private.h poppler-qt4.h
Added Files:
poppler-link.h
Log Message:
* qt4/src/Makefile.am:
* qt4/src/poppler-document.cc:
* qt4/src/poppler-link.cc:
* qt4/src/poppler-page.cc:
* qt4/src/poppler-private.h:
* qt4/src/poppler-qt4.h: Adding links extraction code, should work as
it is basically stripped out from kpdf, but comments are obviously welcome as always
Index: Makefile.am
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Makefile.am 8 Apr 2006 10:44:43 -0000 1.9
+++ Makefile.am 9 May 2006 20:07:06 -0000 1.10
@@ -9,6 +9,7 @@
poppler_include_HEADERS = \
poppler-qt4.h \
+ poppler-link.h \
../../qt/poppler-page-transition.h
lib_LTLIBRARIES = libpoppler-qt4.la
Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-document.cc,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- poppler-document.cc 1 May 2006 13:32:31 -0000 1.18
+++ poppler-document.cc 9 May 2006 20:07:06 -0000 1.19
@@ -389,15 +389,10 @@
LinkDestination *Document::linkDestination( const QString &name )
{
UGooString * namedDest = QStringToUGooString( name );
- LinkDest * destination = m_doc->doc.findDest( namedDest );
- if ( destination )
- {
- LinkDestinationData ldd(destination, &m_doc->doc);
- LinkDestination *ld = new LinkDestination(ldd);
- delete namedDest;
- return ld;
- }
- else return NULL;
+ LinkDestinationData ldd(NULL, namedDest, m_doc);
+ LinkDestination *ld = new LinkDestination(ldd);
+ delete namedDest;
+ return ld;
}
bool Document::print(const QString &file, const QList<int> pageList, double hDPI, double vDPI, int rotate)
Index: poppler-link.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-link.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- poppler-link.cc 2 Apr 2006 18:07:59 -0000 1.1
+++ poppler-link.cc 9 May 2006 20:07:06 -0000 1.2
@@ -31,6 +31,11 @@
{
LinkDest *ld = data.ld;
+ if ( data.namedDest && !ld )
+ ld = data.doc->doc.findDest( data.namedDest );
+
+ if (!ld) return;
+
if (ld->getKind() == ::destXYZ) m_kind = destXYZ;
else if (ld->getKind() == ::destFit) m_kind = destFit;
else if (ld->getKind() == ::destFitH) m_kind = destFitH;
@@ -44,16 +49,26 @@
else
{
Ref ref = ld->getPageRef();
- m_pageNum = data.doc->findPage( ref.num, ref.gen );
+ m_pageNum = data.doc->doc.findPage( ref.num, ref.gen );
}
- m_left = ld->getLeft();
- m_bottom = ld->getBottom();
- m_right = ld->getRight();
- m_top = ld->getTop();
+ double left = ld->getLeft();
+ double bottom = ld->getBottom();
+ double right = ld->getRight();
+ double top = ld->getTop();
m_zoom = ld->getZoom();
m_changeLeft = ld->getChangeLeft();
m_changeTop = ld->getChangeTop();
m_changeZoom = ld->getChangeZoom();
+
+ int leftAux, topAux, rightAux, bottomAux;
+
+ data.doc->m_splashOutputDev->cvtUserToDev( left, top, &leftAux, &topAux );
+ data.doc->m_splashOutputDev->cvtUserToDev( right, bottom, &rightAux, &bottomAux );
+
+ m_left = leftAux;
+ m_top = topAux;
+ m_right = rightAux;
+ m_bottom = bottomAux;
}
LinkDestination::LinkDestination(const QString &description)
@@ -134,5 +149,109 @@
s += ";" + QString::number( (qint8)m_changeZoom );
return s;
}
+
+
+ // Link
+ Link::~Link()
+ {
+ }
+
+ Link::Link(const QRectF &linkArea) : m_linkArea(linkArea)
+ {
+ }
+
+ Link::LinkType Link::linkType() const
+ {
+ return None;
+ }
+
+ QRectF Link::linkArea() const
+ {
+ return m_linkArea;
+ }
+
+ // LinkGoto
+ LinkGoto::LinkGoto( const QRectF &linkArea, QString extFileName, const LinkDestination & destination ) : Link(linkArea), m_extFileName(extFileName), m_destination(destination)
+ {
+ }
+
+ bool LinkGoto::isExternal() const
+ {
+ return !m_extFileName.isEmpty();
+ }
+
+ const QString &LinkGoto::fileName() const
+ {
+ return m_extFileName;
+ }
+
+ const LinkDestination &LinkGoto::destination() const
+ {
+ return m_destination;
+ }
+
+ Link::LinkType LinkGoto::linkType() const
+ {
+ return Goto;
+ }
+
+ // LinkExecute
+ LinkExecute::LinkExecute( const QRectF &linkArea, const QString & file, const QString & params ) : Link(linkArea), m_fileName(file), m_parameters(params)
+ {
+ }
+
+ const QString & LinkExecute::fileName() const
+ {
+ return m_fileName;
+ }
+ const QString & LinkExecute::parameters() const
+ {
+ return m_parameters;
+ }
+
+ Link::LinkType LinkExecute::linkType() const
+ {
+ return Execute;
+ }
+
+ // LinkBrowse
+ LinkBrowse::LinkBrowse( const QRectF &linkArea, const QString &url ) : Link(linkArea), m_url(url)
+ {
+ }
+
+ const QString & LinkBrowse::url() const
+ {
+ return m_url;
+ }
+
+ Link::LinkType LinkBrowse::linkType() const
+ {
+ return Browse;
+ }
+
+ // LinkAction
+ LinkAction::LinkAction( const QRectF &linkArea, ActionType actionType ) : Link(linkArea), m_type(actionType)
+ {
+ }
+
+ LinkAction::ActionType LinkAction::actionType() const
+ {
+ return m_type;
+ }
+
+ Link::LinkType LinkAction::linkType() const
+ {
+ return Action;
+ }
+
+ // LinkMovie
+ LinkMovie::LinkMovie( const QRectF &linkArea ) : Link(linkArea)
+ {
+ }
+
+ Link::LinkType LinkMovie::linkType() const
+ {
+ return Movie;
+ }
}
--- NEW FILE: poppler-link.h ---
/* poppler-link.cc: qt interface to poppler
* Copyright (C) 2006, Albert Astals Cid <aacid at kde.org>
* Adapting code from
* Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
*
* 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
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _POPPLER_LINK_H_
#define _POPPLER_LINK_H_
#include <QtCore/QString>
#include <QtCore/QRectF>
namespace Poppler {
class LinkDestinationData;
class LinkDestination
{
public:
enum Kind
{
destXYZ = 1,
destFit = 2,
destFitH = 3,
destFitV = 4,
destFitR = 5,
destFitB = 6,
destFitBH = 7,
destFitBV = 8
};
LinkDestination(const LinkDestinationData &data);
LinkDestination(const QString &description);
// Accessors.
Kind kind() const;
int pageNumber() const;
double left() const;
double bottom() const;
double right() const;
double top() const;
double zoom() const;
bool isChangeLeft() const;
bool isChangeTop() const;
bool isChangeZoom() const;
QString toString() const;
private:
Kind m_kind; // destination type
int m_pageNum; // page number
double m_left, m_bottom; // position
double m_right, m_top;
double m_zoom; // zoom factor
bool m_changeLeft, m_changeTop; // for destXYZ links, which position
bool m_changeZoom; // components to change
};
/**
* @short Encapsulates data that describes a link.
*
* This is the base class for links. It makes mandatory for inherited
* widgets to reimplement the 'linkType' method and return the type of
* the link described by the reimplemented class.
*/
class Link
{
public:
Link( const QRectF &linkArea );
// get link type (inherited classes mustreturn an unique identifier)
enum LinkType { None, Goto, Execute, Browse, Action, Movie };
virtual LinkType linkType() const;
// virtual destructor
virtual ~Link();
QRectF linkArea() const;
private:
QRectF m_linkArea;
};
/** Goto: a viewport and maybe a reference to an external filename **/
class LinkGoto : public Link
{
public:
LinkGoto( const QRectF &linkArea, QString extFileName, const LinkDestination & destination );
// query for goto parameters
bool isExternal() const;
const QString & fileName() const;
const LinkDestination & destination() const;
LinkType linkType() const;
private:
QString m_extFileName;
LinkDestination m_destination;
};
/** Execute: filename and parameters to execute **/
class LinkExecute : public Link
{
public:
// query for filename / parameters
const QString & fileName() const;
const QString & parameters() const;
// create a Link_Execute
LinkExecute( const QRectF &linkArea, const QString & file, const QString & params );
LinkType linkType() const;
private:
QString m_fileName;
QString m_parameters;
};
/** Browse: an URL to open, ranging from 'http://' to 'mailto:' etc.. **/
class LinkBrowse : public Link
{
public:
// query for URL
const QString & url() const;
// create a Link_Browse
LinkBrowse( const QRectF &linkArea, const QString &url );
LinkType linkType() const;
private:
QString m_url;
};
/** Action: contains an action to perform on document / viewer **/
class LinkAction : public Link
{
public:
// define types of actions
enum ActionType { PageFirst, PagePrev, PageNext, PageLast, HistoryBack, HistoryForward,
Quit, Presentation, EndPresentation, Find, GoToPage, Close };
// query for action type
ActionType actionType() const;
// create a Link_Action
LinkAction( const QRectF &linkArea, ActionType actionType );
LinkType linkType() const;
private:
ActionType m_type;
};
/** Movie: Not yet defined -> think renaming to 'Media' link **/
class LinkMovie : public Link
// TODO this (Movie link)
{
public:
LinkMovie( const QRectF &linkArea );
LinkType linkType() const;
};
}
#endif
Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- poppler-page.cc 6 May 2006 10:57:07 -0000 1.19
+++ poppler-page.cc 9 May 2006 20:07:06 -0000 1.20
@@ -56,30 +56,20 @@
delete m_page;
}
-QImage Page::splashRenderToImage(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, bool doLinks) const
{
SplashOutputDev *output_dev = m_page->parentDoc->m_doc->getSplashOutputDev();
m_page->parentDoc->m_doc->doc.displayPageSlice(output_dev, m_page->index + 1, xres, yres,
- 0, false, true, false, x, y, w, h);
+ 0, false, true, doLinks, x, y, w, h);
SplashBitmap *bitmap = output_dev->getBitmap ();
int bw = bitmap->getWidth();
int bh = bitmap->getHeight();
- // Produce a QImage and copy the image there pixel-by-pixel. This is
- // quite slow and rather ugly, and the following two lines would be
- // much nicer. But it does not work since the change to xpdf 3.01
- // it's worth investigating
-
- // --------
- // SplashColorPtr color_ptr = bitmap->getDataPtr ();
- // QImage *img = new QImage( (uchar*)color_ptr, bw, bh, QImage::Format_RGB32 );
- // --------
-
SplashColorPtr dataPtr = output_dev->getBitmap()->getDataPtr();
// construct a qimage SHARING the raw bitmap data in memory
- QImage img( dataPtr, bw, bh, QImage::Format_RGB32 );
+ QImage img( dataPtr, bw, bh, QImage::Format_ARGB32 );
img = img.copy();
// unload underlying xpdf bitmap
output_dev->startPage( 0, NULL );
@@ -87,9 +77,9 @@
return img;
}
-QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int w, int h) const
+QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int w, int h, bool doLinks) const
{
- QImage img = splashRenderToImage(xres, yres, x, y, w, h);
+ QImage img = splashRenderToImage(xres, yres, x, y, w, h, doLinks);
// Turn the QImage into a QPixmap
QPixmap* out = new QPixmap(QPixmap::fromImage(img));
@@ -296,4 +286,123 @@
p->getDefaultCTM(CTM, dpiX, dpiY, rotate, upsideDown);
}
+QList<Link*> Page::links() const
+{
+ QList<Link*> popplerLinks;
+
+ Links *xpdfLinks = m_page->parentDoc->m_doc->doc.takeLinks();
+ for (int i = 0; i < xpdfLinks->getNumLinks(); ++i)
+ {
+ ::Link *xpdfLink = xpdfLinks->getLink(i);
+
+ double left, top, right, bottom;
+ int leftAux, topAux, rightAux, bottomAux;
+ xpdfLink->getRect( &left, &top, &right, &bottom );
+ QRectF linkArea;
+
+ m_page->parentDoc->m_doc->m_splashOutputDev->cvtUserToDev( left, top, &leftAux, &topAux );
+ m_page->parentDoc->m_doc->m_splashOutputDev->cvtUserToDev( right, bottom, &rightAux, &bottomAux );
+ linkArea.setLeft(leftAux);
+ linkArea.setTop(topAux);
+ linkArea.setRight(rightAux);
+ linkArea.setBottom(bottomAux);
+
+ if (!xpdfLink->isOk()) continue;
+
+ Link *popplerLink = NULL;
+ ::LinkAction *a = xpdfLink->getAction();
+ if ( a )
+ {
+ switch ( a->getKind() )
+ {
+ case actionGoTo:
+ {
+ LinkGoTo * g = (LinkGoTo *) a;
+ // create link: no ext file, namedDest, object pointer
+ popplerLink = new LinkGoto( linkArea, QString::null, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), m_page->parentDoc->m_doc ) ) );
+ }
+ break;
+
+ case actionGoToR:
+ {
+ LinkGoToR * g = (LinkGoToR *) a;
+ // copy link file
+ const char * fileName = g->getFileName()->getCString();
+ // ceate link: fileName, namedDest, object pointer
+ popplerLink = new LinkGoto( linkArea, (QString)fileName, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), m_page->parentDoc->m_doc ) ) );
+ }
+ break;
+
+ case actionLaunch:
+ LinkLaunch * e = (LinkLaunch *)a;
+ GooString * p = e->getParams();
+ popplerLink = new LinkExecute( linkArea, e->getFileName()->getCString(), p ? p->getCString() : 0 );
+ break;
+
+ case actionNamed:
+ const char * name = ((LinkNamed *)a)->getName()->getCString();
+ if ( !strcmp( name, "NextPage" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::PageNext );
+ else if ( !strcmp( name, "PrevPage" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::PagePrev );
+ else if ( !strcmp( name, "FirstPage" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::PageFirst );
+ else if ( !strcmp( name, "LastPage" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::PageLast );
+ else if ( !strcmp( name, "GoBack" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::HistoryBack );
+ else if ( !strcmp( name, "GoForward" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::HistoryForward );
+ else if ( !strcmp( name, "Quit" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::Quit );
+ else if ( !strcmp( name, "GoToPage" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::GoToPage );
+ else if ( !strcmp( name, "Find" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::Find );
+ else if ( !strcmp( name, "FullScreen" ) )
+ popplerLink = new LinkAction( linkArea, LinkAction::Presentation );
+ else if ( !strcmp( name, "Close" ) )
+ {
+ // acroread closes the document always, doesnt care whether
+ // its presentation mode or not
+ // popplerLink = new LinkAction( linkArea, LinkAction::EndPresentation );
+ popplerLink = new LinkAction( linkArea, LinkAction::Close );
+ }
+ else
+ {
+ // TODO
+ }
+ break;
+
+ case actionURI:
+ popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI()->getCString() );
+ break;
+
+ case actionMovie:
+/* TODO this (Movie link)
+ m_type = Movie;
+ LinkMovie * m = (LinkMovie *) a;
+ // copy Movie parameters (2 IDs and a const char *)
+ Ref * r = m->getAnnotRef();
+ m_refNum = r->num;
+ m_refGen = r->gen;
+ copyString( m_uri, m->getTitle()->getCString() );
+*/ break;
+
+ case actionUnknown:
+ break;
+ }
+ }
+
+ if (popplerLink)
+ {
+ popplerLinks.append(popplerLink);
+ }
+ }
+
+ delete xpdfLinks;
+
+ return popplerLinks;
+}
+
}
Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-private.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- poppler-private.h 1 May 2006 18:33:47 -0000 1.9
+++ poppler-private.h 9 May 2006 20:07:06 -0000 1.10
@@ -53,12 +53,13 @@
class LinkDestinationData
{
public:
- LinkDestinationData( LinkDest *l, PDFDoc *pdfdoc ) : ld(l), doc(pdfdoc)
+ LinkDestinationData( LinkDest *l, UGooString *nd, Poppler::DocumentData *pdfdoc ) : ld(l), namedDest(nd), doc(pdfdoc)
{
}
LinkDest *ld;
- PDFDoc *doc;
+ UGooString *namedDest;
+ Poppler::DocumentData *doc;
};
class DocumentData {
@@ -113,7 +114,7 @@
parent->appendChild( item );
// 2. find the page the link refers to
- LinkAction * a = outlineItem->getAction();
+ ::LinkAction * a = outlineItem->getAction();
if ( a && ( a->getKind() == actionGoTo || a->getKind() == actionGoToR ) )
{
// page number is contained/referenced in a LinkGoTo
@@ -130,7 +131,7 @@
}
else if ( destination && destination->isOk() )
{
- LinkDestinationData ldd(destination, &doc);
+ LinkDestinationData ldd(destination, NULL, this);
item.setAttribute( "Destination", LinkDestination(ldd).toString() );
}
if ( a->getKind() == actionGoToR )
Index: poppler-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- poppler-qt4.h 4 May 2006 19:10:55 -0000 1.30
+++ poppler-qt4.h 9 May 2006 20:07:06 -0000 1.31
@@ -29,6 +29,7 @@
#include <QtXml/QDomDocument>
#include <poppler-page-transition.h>
+#include <poppler-link.h>
class EmbFile;
@@ -250,6 +251,8 @@
\param yres vertical resolution of the graphics device, in
dots per inch
+
+ \param doLinks calculate links
\warning The parameter (x,y,w,h) are not
well-tested. Unusual or meaningless parameters may lead to
@@ -257,7 +260,7 @@
\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;
+ QImage splashRenderToImage(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1, bool doLinks = false) const;
/**
Render the page to a QPixmap using the Splash renderer
@@ -280,7 +283,7 @@
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;
+ QPixmap *splashRenderToPixmap(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1, bool doLinks = false) const;
/**
Render the page to a pixmap using the Arthur (Qt4) renderer
@@ -387,55 +390,16 @@
*/
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
+ */
+ QList<Link*> links() const;
+
private:
Page(const Document *doc, int index);
PageData *m_page;
};
- class LinkDestinationData;
-
- class LinkDestination
- {
- public:
- enum Kind
- {
- destXYZ = 1,
- destFit = 2,
- destFitH = 3,
- destFitV = 4,
- destFitR = 5,
- destFitB = 6,
- destFitBH = 7,
- destFitBV = 8
- };
-
- LinkDestination(const LinkDestinationData &data);
- LinkDestination(const QString &description);
-
- // Accessors.
- Kind kind() const;
- int pageNumber() const;
- double left() const;
- double bottom() const;
- double right() const;
- double top() const;
- double zoom() const;
- bool isChangeLeft() const;
- bool isChangeTop() const;
- bool isChangeZoom() const;
-
- QString toString() const;
-
- private:
- Kind m_kind; // destination type
- int m_pageNum; // page number
- double m_left, m_bottom; // position
- double m_right, m_top;
- double m_zoom; // zoom factor
- bool m_changeLeft, m_changeTop; // for destXYZ links, which position
- bool m_changeZoom; // components to change
- };
-
class DocumentData;
/**
More information about the poppler
mailing list