[poppler] poppler/Link.cc poppler/Link.h qt4/src
Albert Astals Cid
aacid at kemper.freedesktop.org
Mon Oct 8 14:56:52 PDT 2012
poppler/Link.cc | 34 ++++++++++++++++++-----
poppler/Link.h | 17 +++++++++--
qt4/src/poppler-annotation.cc | 2 -
qt4/src/poppler-annotation.h | 1
qt4/src/poppler-link.cc | 60 +++++++++++++++++++++++++++++++++++++++---
qt4/src/poppler-link.h | 57 +++++++++++++++++++++++++++++++++++++--
qt4/src/poppler-page.cc | 8 ++++-
7 files changed, 158 insertions(+), 21 deletions(-)
New commits:
commit b112602334a5de84ae30c2e90d9bc6d4609f7f96
Author: Tobias Koening <tobias.koenig at kdab.com>
Date: Mon Oct 8 22:32:34 2012 +0200
[qt4] make LinkRendition properties available
Bug #55378
diff --git a/poppler/Link.cc b/poppler/Link.cc
index b90b1c1..b5b2bd3 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -19,6 +19,7 @@
// Copyright (C) 2008-2010, 2012 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
// Copyright (C) 2009 Ilya Gorenbein <igorenbein at finjan.com>
+// Copyright (C) 2012 Tobias Koening <tobias.koenig at kdab.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -700,9 +701,10 @@ LinkSound::~LinkSound() {
//------------------------------------------------------------------------
LinkRendition::LinkRendition(Object *obj) {
- operation = -1;
+ operation = NoRendition;
media = NULL;
js = NULL;
+ int operationCode = -1;
if (obj->isDict()) {
Object tmp;
@@ -721,25 +723,43 @@ LinkRendition::LinkRendition(Object *obj) {
tmp.free();
if (obj->dictLookup("OP", &tmp)->isInt()) {
- operation = tmp.getInt();
- if (!js && (operation < 0 || operation > 4)) {
- error(errSyntaxWarning, -1, "Invalid Rendition Action: unrecognized operation valued: {0:d}", operation);
+ operationCode = tmp.getInt();
+ if (!js && (operationCode < 0 || operationCode > 4)) {
+ error(errSyntaxWarning, -1, "Invalid Rendition Action: unrecognized operation valued: {0:d}", operationCode);
} else {
Object obj1;
// retrieve rendition object
if (obj->dictLookup("R", &renditionObj)->isDict()) {
media = new MediaRendition(&renditionObj);
- } else if (operation == 0 || operation == 4) {
- error(errSyntaxWarning, -1, "Invalid Rendition Action: no R field with op = {0:d}", operation);
+ } else if (operationCode == 0 || operationCode == 4) {
+ error(errSyntaxWarning, -1, "Invalid Rendition Action: no R field with op = {0:d}", operationCode);
renditionObj.free();
}
if (!obj->dictLookupNF("AN", &screenRef)->isRef() && operation >= 0 && operation <= 4) {
- error(errSyntaxWarning, -1, "Invalid Rendition Action: no AN field with op = {0:d}", operation);
+ error(errSyntaxWarning, -1, "Invalid Rendition Action: no AN field with op = {0:d}", operationCode);
screenRef.free();
}
}
+
+ switch (operationCode) {
+ case 0:
+ operation = PlayRendition;
+ break;
+ case 1:
+ operation = StopRendition;
+ break;
+ case 2:
+ operation = PauseRendition;
+ break;
+ case 3:
+ operation = ResumeRendition;
+ break;
+ case 4:
+ operation = PlayRendition;
+ break;
+ }
} else if (!js) {
error(errSyntaxWarning, -1, "Invalid Rendition action: no OP or JS field defined");
}
diff --git a/poppler/Link.h b/poppler/Link.h
index 8e2df24..fc2abe6 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -16,6 +16,7 @@
// Copyright (C) 2006, 2008 Pino Toscano <pino at kde.org>
// Copyright (C) 2008 Hugo Mercier <hmercier31 at gmail.com>
// Copyright (C) 2010, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
+// Copyright (C) 2012 Tobias Koening <tobias.koenig at kdab.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -51,7 +52,7 @@ enum LinkActionKind {
actionURI, // URI
actionNamed, // named action
actionMovie, // movie action
- actionRendition,
+ actionRendition, // rendition action
actionSound, // sound action
actionJavaScript, // JavaScript action
actionOCGState, // Set-OCG-State action
@@ -319,6 +320,16 @@ private:
class LinkRendition: public LinkAction {
public:
+ /**
+ * Describes the possible rendition operations.
+ */
+ enum RenditionOperation {
+ NoRendition,
+ PlayRendition,
+ StopRendition,
+ PauseRendition,
+ ResumeRendition
+ };
LinkRendition(Object *Obj);
@@ -334,7 +345,7 @@ public:
GBool hasScreenAnnot() { return screenRef.isRef(); }
Ref getScreenAnnot() { return screenRef.getRef(); }
- int getOperation() { return operation; }
+ RenditionOperation getOperation() { return operation; }
MediaRendition* getMedia() { return media; }
@@ -344,7 +355,7 @@ private:
Object screenRef;
Object renditionObj;
- int operation;
+ RenditionOperation operation;
MediaRendition* media;
diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc
index 825bbf6..5ecea80 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -527,8 +527,6 @@ Link* AnnotationPrivate::additionalAction( Annotation::AdditionalActionType type
if ( linkAction )
link = PageData::convertLinkActionToLink( linkAction, parentDoc, QRectF() );
- delete linkAction;
-
return link;
}
diff --git a/qt4/src/poppler-annotation.h b/qt4/src/poppler-annotation.h
index 5adc9a8..9208ca7 100644
--- a/qt4/src/poppler-annotation.h
+++ b/qt4/src/poppler-annotation.h
@@ -107,6 +107,7 @@ class POPPLER_QT4_EXPORT Annotation
{
friend class AnnotationUtils;
friend class LinkMovie;
+ friend class LinkRendition;
public:
// enum definitions
diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc
index a4bc55b..199e2db 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -168,16 +168,40 @@ class LinkSoundPrivate : public LinkPrivate
class LinkRenditionPrivate : public LinkPrivate
{
public:
- LinkRenditionPrivate( const QRectF &area, ::MediaRendition *rendition );
+ LinkRenditionPrivate( const QRectF &area, ::MediaRendition *rendition, ::LinkRendition::RenditionOperation operation, const QString &script, const Ref &annotationReference );
~LinkRenditionPrivate();
MediaRendition *rendition;
+ LinkRendition::RenditionAction action;
+ QString script;
+ Ref annotationReference;
};
- LinkRenditionPrivate::LinkRenditionPrivate( const QRectF &area, ::MediaRendition *r )
+ LinkRenditionPrivate::LinkRenditionPrivate( const QRectF &area, ::MediaRendition *r, ::LinkRendition::RenditionOperation operation, const QString &javaScript, const Ref &ref )
: LinkPrivate( area )
- , rendition( new MediaRendition( r ) )
+ , rendition( r ? new MediaRendition( r ) : 0 )
+ , action( LinkRendition::PlayRendition )
+ , script( javaScript )
+ , annotationReference( ref )
{
+ switch ( operation )
+ {
+ case ::LinkRendition::NoRendition:
+ action = LinkRendition::NoRendition;
+ break;
+ case ::LinkRendition::PlayRendition:
+ action = LinkRendition::PlayRendition;
+ break;
+ case ::LinkRendition::StopRendition:
+ action = LinkRendition::StopRendition;
+ break;
+ case ::LinkRendition::PauseRendition:
+ action = LinkRendition::PauseRendition;
+ break;
+ case ::LinkRendition::ResumeRendition:
+ action = LinkRendition::ResumeRendition;
+ break;
+ }
}
LinkRenditionPrivate::~LinkRenditionPrivate()
@@ -579,10 +603,15 @@ class LinkMoviePrivate : public LinkPrivate
// LinkRendition
LinkRendition::LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition )
- : Link( *new LinkRenditionPrivate( linkArea, rendition ) )
+ : Link( *new LinkRenditionPrivate( linkArea, rendition, ::LinkRendition::NoRendition, QString(), Ref() ) )
{
}
+ LinkRendition::LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition, int operation, const QString &script, const Ref &annotationReference )
+ : Link( *new LinkRenditionPrivate( linkArea, rendition, static_cast<enum ::LinkRendition::RenditionOperation>(operation), script, annotationReference ) )
+ {
+ }
+
LinkRendition::~LinkRendition()
{
}
@@ -598,6 +627,29 @@ class LinkMoviePrivate : public LinkPrivate
return d->rendition;
}
+ LinkRendition::RenditionAction LinkRendition::action() const
+ {
+ Q_D( const LinkRendition );
+ return d->action;
+ }
+
+ QString LinkRendition::script() const
+ {
+ Q_D( const LinkRendition );
+ return d->script;
+ }
+
+ bool LinkRendition::isReferencedAnnotation( const ScreenAnnotation *annotation ) const
+ {
+ Q_D( const LinkRendition );
+ if ( d->annotationReference.num != -1 && d->annotationReference == annotation->d_ptr->pdfObjectReference() )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
// LinkJavaScript
LinkJavaScript::LinkJavaScript( const QRectF &linkArea, const QString &js )
: Link( *new LinkJavaScriptPrivate( linkArea ) )
diff --git a/qt4/src/poppler-link.h b/qt4/src/poppler-link.h
index a2ef2d3..ef93bf0 100644
--- a/qt4/src/poppler-link.h
+++ b/qt4/src/poppler-link.h
@@ -455,12 +455,40 @@ class POPPLER_QT4_EXPORT LinkRendition : public Link
{
public:
/**
- * Create a new media rendition link.
+ * Describes the possible rendition actions.
+ *
+ * \since 0.22
+ */
+ enum RenditionAction {
+ NoRendition,
+ PlayRendition,
+ StopRendition,
+ PauseRendition,
+ ResumeRendition
+ };
+
+ /**
+ * Create a new rendition link.
+ *
+ * \param linkArea the active area of the link
+ * \param rendition the media rendition object
+ *
+ * \deprecated Use the constructor that takes all parameter instead
+ */
+ Q_DECL_DEPRECATED LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition );
+
+ /**
+ * Create a new rendition link.
*
* \param linkArea the active area of the link
- * \param rendition
+ * \param rendition the media rendition object
+ * \param operation the numeric operation (action) (@see ::LinkRendition::RenditionOperation)
+ * \param script the java script code
+ * \param annotationReference the object reference of the screen annotation associated with this rendition action
+ * \since 0.22
*/
- LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition );
+ LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition, int operation, const QString &script, const Ref &annotationReference );
+
/**
* Destructor.
*/
@@ -469,10 +497,31 @@ class POPPLER_QT4_EXPORT LinkRendition : public Link
LinkType linkType() const;
/**
- *
+ * Returns the media rendition object if the redition provides one, @c 0 otherwise
*/
MediaRendition *rendition() const;
+ /**
+ * Returns the action that should be executed if a rendition object is provided.
+ *
+ * \since 0.22
+ */
+ RenditionAction action() const;
+
+ /**
+ * The JS code that shall be executed or an empty string.
+ *
+ * \since 0.22
+ */
+ QString script() const;
+
+ /**
+ * Returns whether the given @p annotation is the referenced screen annotation for this rendition @p link.
+ *
+ * \since 0.22
+ */
+ bool isReferencedAnnotation( const ScreenAnnotation *annotation ) const;
+
private:
Q_DECLARE_PRIVATE( LinkRendition )
Q_DISABLE_COPY( LinkRendition )
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 349a1bb..03aa1bb 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -197,7 +197,13 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
case actionRendition:
{
::LinkRendition *lrn = (::LinkRendition *)a;
- popplerLink = new LinkRendition( linkArea, lrn->getMedia() );
+
+ Ref reference;
+ reference.num = reference.gen = -1;
+ if ( lrn->hasScreenAnnot() )
+ reference = lrn->getScreenAnnot();
+
+ popplerLink = new LinkRendition( linkArea, lrn->getMedia(), lrn->getOperation(), UnicodeParsedString( lrn->getScript() ), reference );
}
break;
More information about the poppler
mailing list