[poppler] poppler/qt4/src: poppler-annotation.cc, 1.1,
1.2 poppler-annotation.h, 1.1, 1.2 poppler-page.cc, 1.24, 1.25
Albert Astals Cid
aacid at kemper.freedesktop.org
Mon Sep 11 14:20:58 PDT 2006
Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv15443/qt4/src
Modified Files:
poppler-annotation.cc poppler-annotation.h poppler-page.cc
Log Message:
2006-09-11 Albert Astals Cid <aacid at kde.org>
* qt4/src/poppler-annotation.cc:
* qt4/src/poppler-annotation.h:
* qt4/src/poppler-page.cc: Add support for LinkAnnotation. Patch by
Pino Toscano
Index: poppler-annotation.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-annotation.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- poppler-annotation.cc 12 May 2006 20:40:05 -0000 1.1
+++ poppler-annotation.cc 11 Sep 2006 21:20:56 -0000 1.2
@@ -24,6 +24,7 @@
// local includes
#include "poppler-annotation.h"
+#include "poppler-link.h"
namespace Poppler {
@@ -322,12 +323,12 @@
/** TextAnnotation [Annotation] */
TextAnnotation::TextAnnotation()
- : Annotation(), textType( Linked ), textIcon( "Comment" ),
+ : Annotation(), textType( Linked ), textIcon( "Note" ),
inplaceAlign( 0 ), inplaceIntent( Unknown )
{}
TextAnnotation::TextAnnotation( const QDomNode & node )
- : Annotation( node ), textType( Linked ), textIcon( "Comment" ),
+ : Annotation( node ), textType( Linked ), textIcon( "Note" ),
inplaceAlign( 0 ), inplaceIntent( Unknown )
{
// loop through the whole children looking for a 'text' element
@@ -667,11 +668,11 @@
/** StampAnnotation [Annotation] */
StampAnnotation::StampAnnotation()
- : Annotation(), stampIconName( "oKular" )
+ : Annotation(), stampIconName( "Draft" )
{}
StampAnnotation::StampAnnotation( const QDomNode & node )
- : Annotation( node ), stampIconName( "oKular" )
+ : Annotation( node ), stampIconName( "Draft" )
{
// loop through the whole children looking for a 'stamp' element
QDomNode subNode = node.firstChild();
@@ -701,7 +702,7 @@
node.appendChild( stampElement );
// append the optional attributes
- if ( stampIconName != "oKular" )
+ if ( stampIconName != "Draft" )
stampElement.setAttribute( "icon", stampIconName );
}
@@ -789,4 +790,223 @@
}
}
+
+/** LinkAnnotation [Annotation] */
+
+LinkAnnotation::LinkAnnotation()
+ : Annotation(), linkDestination( 0 ), linkHLMode( Invert )
+{}
+
+LinkAnnotation::LinkAnnotation( const QDomNode & node )
+ : Annotation( node ), linkDestination( 0 ), linkHLMode( Invert )
+{
+ // loop through the whole children looking for a 'link' element
+ QDomNode subNode = node.firstChild();
+ while( subNode.isElement() )
+ {
+ QDomElement e = subNode.toElement();
+ subNode = subNode.nextSibling();
+ if ( e.tagName() != "link" )
+ continue;
+
+ // parse the attributes
+ if ( e.hasAttribute( "hlmode" ) )
+ linkHLMode = (LinkAnnotation::HighlightMode)e.attribute( "hlmode" ).toInt();
+
+ // parse all 'quad' subnodes
+ QDomNode quadNode = e.firstChild();
+ for ( ; quadNode.isElement(); quadNode = quadNode.nextSibling() )
+ {
+ QDomElement qe = quadNode.toElement();
+ if ( qe.tagName() == "quad" )
+ {
+ linkRegion[0].setX(qe.attribute( "ax", "0.0" ).toDouble());
+ linkRegion[0].setY(qe.attribute( "ay", "0.0" ).toDouble());
+ linkRegion[1].setX(qe.attribute( "bx", "0.0" ).toDouble());
+ linkRegion[1].setY(qe.attribute( "by", "0.0" ).toDouble());
+ linkRegion[2].setX(qe.attribute( "cx", "0.0" ).toDouble());
+ linkRegion[2].setY(qe.attribute( "cy", "0.0" ).toDouble());
+ linkRegion[3].setX(qe.attribute( "dx", "0.0" ).toDouble());
+ linkRegion[3].setY(qe.attribute( "dy", "0.0" ).toDouble());
+ }
+ else if ( qe.tagName() == "link" )
+ {
+ QString type = qe.attribute( "type" );
+ if ( type == "GoTo" )
+ {
+ Poppler::LinkGoto * go = new Poppler::LinkGoto( QRect(), qe.attribute( "filename" ), LinkDestination( qe.attribute( "destination" ) ) );
+ linkDestination = go;
+ }
+ else if ( type == "Exec" )
+ {
+ Poppler::LinkExecute * exec = new Poppler::LinkExecute( QRect(), qe.attribute( "filename" ), qe.attribute( "parameters" ) );
+ linkDestination = exec;
+ }
+ else if ( type == "Browse" )
+ {
+ Poppler::LinkBrowse * browse = new Poppler::LinkBrowse( QRect(), qe.attribute( "url" ) );
+ linkDestination = browse;
+ }
+ else if ( type == "Action" )
+ {
+ Poppler::LinkAction::ActionType act;
+ QString actString = qe.attribute( "action" );
+ if ( actString == "PageFirst" )
+ act = Poppler::LinkAction::PageFirst;
+ else if ( actString == "PagePrev" )
+ act = Poppler::LinkAction::PagePrev;
+ else if ( actString == "PageNext" )
+ act = Poppler::LinkAction::PageNext;
+ else if ( actString == "PageLast" )
+ act = Poppler::LinkAction::PageLast;
+ else if ( actString == "HistoryBack" )
+ act = Poppler::LinkAction::HistoryBack;
+ else if ( actString == "HistoryForward" )
+ act = Poppler::LinkAction::HistoryForward;
+ else if ( actString == "Quit" )
+ act = Poppler::LinkAction::Quit;
+ else if ( actString == "Presentation" )
+ act = Poppler::LinkAction::Presentation;
+ else if ( actString == "EndPresentation" )
+ act = Poppler::LinkAction::EndPresentation;
+ else if ( actString == "Find" )
+ act = Poppler::LinkAction::Find;
+ else if ( actString == "GoToPage" )
+ act = Poppler::LinkAction::GoToPage;
+ else if ( actString == "Close" )
+ act = Poppler::LinkAction::Close;
+ Poppler::LinkAction * action = new Poppler::LinkAction( QRect(), act );
+ linkDestination = action;
+ }
+ else if ( type == "Movie" )
+ {
+ Poppler::LinkMovie * movie = new Poppler::LinkMovie( QRect() );
+ linkDestination = movie;
+ }
+ }
+ }
+
+ // loading complete
+ break;
+ }
+}
+
+LinkAnnotation::~LinkAnnotation()
+{
+ delete linkDestination;
+}
+
+void LinkAnnotation::store( QDomNode & node, QDomDocument & document ) const
+{
+ // recurse to parent objects storing properties
+ Annotation::store( node, document );
+
+ // create [hl] element
+ QDomElement linkElement = document.createElement( "link" );
+ node.appendChild( linkElement );
+
+ // append the optional attributes
+ if ( linkHLMode != Invert )
+ linkElement.setAttribute( "hlmode", (int)linkHLMode );
+
+ // saving region
+ QDomElement quadElement = document.createElement( "quad" );
+ linkElement.appendChild( quadElement );
+ quadElement.setAttribute( "ax", linkRegion[0].x() );
+ quadElement.setAttribute( "ay", linkRegion[0].y() );
+ quadElement.setAttribute( "bx", linkRegion[1].x() );
+ quadElement.setAttribute( "by", linkRegion[1].y() );
+ quadElement.setAttribute( "cx", linkRegion[2].x() );
+ quadElement.setAttribute( "cy", linkRegion[2].y() );
+ quadElement.setAttribute( "dx", linkRegion[3].x() );
+ quadElement.setAttribute( "dy", linkRegion[3].y() );
+
+ // saving link
+ QDomElement hyperlinkElement = document.createElement( "link" );
+ linkElement.appendChild( hyperlinkElement );
+ if ( linkDestination )
+ {
+ switch( linkDestination->linkType() )
+ {
+ case Poppler::Link::Goto:
+ {
+ Poppler::LinkGoto * go = static_cast< Poppler::LinkGoto * >( linkDestination );
+ hyperlinkElement.setAttribute( "type", "GoTo" );
+ hyperlinkElement.setAttribute( "filename", go->fileName() );
+ hyperlinkElement.setAttribute( "destionation", go->destination().toString() );
+ break;
+ }
+ case Poppler::Link::Execute:
+ {
+ Poppler::LinkExecute * exec = static_cast< Poppler::LinkExecute * >( linkDestination );
+ hyperlinkElement.setAttribute( "type", "Exec" );
+ hyperlinkElement.setAttribute( "filename", exec->fileName() );
+ hyperlinkElement.setAttribute( "parameters", exec->parameters() );
+ break;
+ }
+ case Poppler::Link::Browse:
+ {
+ Poppler::LinkBrowse * browse = static_cast< Poppler::LinkBrowse * >( linkDestination );
+ hyperlinkElement.setAttribute( "type", "Browse" );
+ hyperlinkElement.setAttribute( "url", browse->url() );
+ break;
+ }
+ case Poppler::Link::Action:
+ {
+ Poppler::LinkAction * action = static_cast< Poppler::LinkAction * >( linkDestination );
+ hyperlinkElement.setAttribute( "type", "Action" );
+ switch ( action->actionType() )
+ {
+ case Poppler::LinkAction::PageFirst:
+ hyperlinkElement.setAttribute( "action", "PageFirst" );
+ break;
+ case Poppler::LinkAction::PagePrev:
+ hyperlinkElement.setAttribute( "action", "PagePrev" );
+ break;
+ case Poppler::LinkAction::PageNext:
+ hyperlinkElement.setAttribute( "action", "PageNext" );
+ break;
+ case Poppler::LinkAction::PageLast:
+ hyperlinkElement.setAttribute( "action", "PageLast" );
+ break;
+ case Poppler::LinkAction::HistoryBack:
+ hyperlinkElement.setAttribute( "action", "HistoryBack" );
+ break;
+ case Poppler::LinkAction::HistoryForward:
+ hyperlinkElement.setAttribute( "action", "HistoryForward" );
+ break;
+ case Poppler::LinkAction::Quit:
+ hyperlinkElement.setAttribute( "action", "Quit" );
+ break;
+ case Poppler::LinkAction::Presentation:
+ hyperlinkElement.setAttribute( "action", "Presentation" );
+ break;
+ case Poppler::LinkAction::EndPresentation:
+ hyperlinkElement.setAttribute( "action", "EndPresentation" );
+ break;
+ case Poppler::LinkAction::Find:
+ hyperlinkElement.setAttribute( "action", "Find" );
+ break;
+ case Poppler::LinkAction::GoToPage:
+ hyperlinkElement.setAttribute( "action", "GoToPage" );
+ break;
+ case Poppler::LinkAction::Close:
+ hyperlinkElement.setAttribute( "action", "Close" );
+ break;
+ }
+ break;
+ }
+ case Poppler::Link::Movie:
+ {
+ Poppler::LinkMovie * movie = static_cast< Poppler::LinkMovie * >( linkDestination );
+ hyperlinkElement.setAttribute( "type", "Movie" );
+ break;
+ }
+ case Poppler::Link::None:
+ break;
+ }
+ }
+}
+
+
}
Index: poppler-annotation.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-annotation.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- poppler-annotation.h 12 May 2006 20:40:05 -0000 1.1
+++ poppler-annotation.h 11 Sep 2006 21:20:56 -0000 1.2
@@ -30,6 +30,7 @@
namespace Poppler {
class Annotation;
+class Link;
/**
* @short Helper class for (recoursive) annotation retrieval/storage.
@@ -70,7 +71,7 @@
// enum definitions
// WARNING!!! oKular uses that very same values so if you change them notify the author!
enum SubType { AText = 1, ALine = 2, AGeom = 3, AHighlight = 4, AStamp = 5,
- AInk = 6, A_BASE = 0 };
+ AInk = 6, ALink = 7, A_BASE = 0 };
enum Flag { Hidden = 1, FixedSize = 2, FixedRotation = 4, DenyPrint = 8,
DenyWrite = 16, DenyDelete = 32, ToggleHidingOnMouse = 64, External = 128 };
enum LineStyle { Solid = 1, Dashed = 2, Beveled = 4, Inset = 8, Underline = 16 };
@@ -170,7 +171,7 @@
// data fields
TextType textType; // Linked
- QString textIcon; // 'Comment'
+ QString textIcon; // 'Note'
QFont textFont; // app def font
int inplaceAlign; // 0:left, 1:center, 2:right
QString inplaceText; // '' overrides contents
@@ -240,7 +241,7 @@
AN_COMMONDECL( StampAnnotation, AStamp )
// data fields
- QString stampIconName; // 'kpdf'
+ QString stampIconName; // 'Draft'
};
struct InkAnnotation : public Annotation
@@ -252,6 +253,21 @@
QList< QLinkedList<QPointF> > inkPaths;
};
+struct LinkAnnotation : public Annotation
+{
+ // common stuff for Annotation derived classes
+ AN_COMMONDECL( LinkAnnotation, ALink );
+ virtual ~LinkAnnotation();
+
+ // local enums
+ enum HighlightMode { None, Invert, Outline, Push };
+
+ // data fields
+ Link * linkDestination; //
+ HighlightMode linkHLMode; // Invert
+ QPointF linkRegion[4]; //
+};
+
}
#endif
Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- poppler-page.cc 1 Jun 2006 21:03:38 -0000 1.24
+++ poppler-page.cc 11 Sep 2006 21:20:56 -0000 1.25
@@ -39,11 +39,109 @@
class PageData {
public:
+ Link* convertLinkActionToLink(::LinkAction * a, const QRectF &linkArea, DocumentData * doc);
+
const Document *parentDoc;
int index;
PageTransition *transition;
};
+Link* PageData::convertLinkActionToLink(::LinkAction * a, const QRectF &linkArea, DocumentData * doc)
+{
+ if ( !a )
+ return NULL;
+
+ Link * popplerLink = NULL;
+ 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(), 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(), 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;
+ }
+
+ return popplerLink;
+}
+
+
Page::Page(const Document *doc, int index) {
m_page = new PageData();
m_page->index = index;
@@ -333,97 +431,7 @@
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;
- }
- }
-
+ Link *popplerLink = m_page->convertLinkActionToLink(xpdfLink->getAction(), linkArea, m_page->parentDoc->m_doc);
if (popplerLink)
{
popplerLinks.append(popplerLink);
@@ -790,9 +798,50 @@
}
else if ( subType == "Link" )
{
- // ignore links (this may change in future)
- annot.free();
- continue;
+ // parse Link params
+ LinkAnnotation * l = new LinkAnnotation();
+ annotation = l;
+
+ // -> hlMode
+ QString hlModeString;
+ XPDFReader::lookupString( annotDict, "H", hlModeString );
+ if ( hlModeString == "N" )
+ l->linkHLMode = LinkAnnotation::None;
+ else if ( hlModeString == "I" )
+ l->linkHLMode = LinkAnnotation::Invert;
+ else if ( hlModeString == "O" )
+ l->linkHLMode = LinkAnnotation::Outline;
+ else if ( hlModeString == "P" )
+ l->linkHLMode = LinkAnnotation::Push;
+
+ // -> link region
+ double c[8];
+ int num = XPDFReader::lookupNumArray( annotDict, "QuadPoints", c, 8 );
+ if ( num > 0 && num != 8 )
+ {
+ qDebug() << "Wrong QuadPoints for a Link annotation." << endl;
+ delete annotation;
+ annot.free();
+ continue;
+ }
+ if ( num == 8 )
+ {
+ XPDFReader::transform( MTX, c[ 0 ], c[ 1 ], l->linkRegion[ 0 ] );
+ XPDFReader::transform( MTX, c[ 2 ], c[ 3 ], l->linkRegion[ 1 ] );
+ XPDFReader::transform( MTX, c[ 4 ], c[ 5 ], l->linkRegion[ 2 ] );
+ XPDFReader::transform( MTX, c[ 6 ], c[ 7 ], l->linkRegion[ 3 ] );
+ }
+
+ // reading link action
+ Object objPA;
+ annotDict->lookup( "PA", &objPA );
+ ::LinkAction * a = ::LinkAction::parseAction( &objPA, m_page->parentDoc->m_doc->doc.getCatalog()->getBaseURI() );
+ Link * popplerLink = m_page->convertLinkActionToLink( a, QRectF(), m_page->parentDoc->m_doc );
+ if ( popplerLink )
+ {
+ l->linkDestination = popplerLink;
+ }
+ objPA.free();
}
else
{
More information about the poppler
mailing list