diff --git a/qt4/src/CMakeLists.txt b/qt4/src/CMakeLists.txt index 99dce58..c958379 100644 --- a/qt4/src/CMakeLists.txt +++ b/qt4/src/CMakeLists.txt @@ -15,6 +15,7 @@ set(poppler_qt4_SRCS poppler-link.cc poppler-link-extractor.cc poppler-movie.cc + poppler-objectreference.cc poppler-optcontent.cc poppler-page.cc poppler-base-converter.cc diff --git a/qt4/src/poppler-annotation-private.h b/qt4/src/poppler-annotation-private.h index b428347..562a694 100644 --- a/qt4/src/poppler-annotation-private.h +++ b/qt4/src/poppler-annotation-private.h @@ -21,6 +21,8 @@ #include "poppler-annotation.h" +#include "poppler-objectreference_p.h" + namespace Poppler { @@ -42,6 +44,7 @@ class AnnotationPrivate QRectF boundary; QLinkedList< Annotation::Revision > revisions; + ObjectReference pdfObjectReference; }; } diff --git a/qt4/src/poppler-annotation.h b/qt4/src/poppler-annotation.h index ae90d71..0b6c8bd 100644 --- a/qt4/src/poppler-annotation.h +++ b/qt4/src/poppler-annotation.h @@ -93,6 +93,9 @@ class POPPLER_QT4_EXPORT AnnotationUtils */ class POPPLER_QT4_EXPORT Annotation { + friend class LinkMovie; + friend class Page; + public: // enum definitions // WARNING!!! oKular uses that very same values so if you change them notify the author! diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc index 68c607a..29146dc 100644 --- a/qt4/src/poppler-link.cc +++ b/qt4/src/poppler-link.cc @@ -25,6 +25,9 @@ #include +#include "poppler-annotation-private.h" +#include "poppler-objectreference_p.h" + #include "Link.h" namespace Poppler { @@ -167,18 +170,20 @@ class LinkJavaScriptPrivate : public LinkPrivate { } -#if 0 class LinkMoviePrivate : public LinkPrivate { public: - LinkMoviePrivate( const QRectF &area ); + LinkMoviePrivate( const QRectF &area, LinkMovie::Operation operation, const QString &title, const ObjectReference &reference ); + + LinkMovie::Operation operation; + QString annotationTitle; + ObjectReference annotationReference; }; - LinkMoviePrivate::LinkMoviePrivate( const QRectF &area ) - : LinkPrivate( area ) + LinkMoviePrivate::LinkMoviePrivate( const QRectF &area, LinkMovie::Operation _operation, const QString &title, const ObjectReference &reference ) + : LinkPrivate( area ), operation( _operation ), annotationTitle( title ), annotationReference( reference ) { } -#endif static void cvtUserToDev(::Page *page, double xu, double yu, int *xd, int *yd) { double ctm[6]; @@ -567,10 +572,9 @@ class LinkMoviePrivate : public LinkPrivate return d->js; } -#if 0 // LinkMovie - LinkMovie::LinkMovie( const QRectF &linkArea ) - : Link( *new LinkMoviePrivate( linkArea ) ) + LinkMovie::LinkMovie( const QRectF &linkArea, Operation operation, const QString &annotationTitle, const ObjectReference &annotationReference ) + : Link( *new LinkMoviePrivate( linkArea, operation, annotationTitle, annotationReference ) ) { } @@ -582,6 +586,25 @@ class LinkMoviePrivate : public LinkPrivate { return Movie; } -#endif + + LinkMovie::Operation LinkMovie::operation() const + { + Q_D( const LinkMovie ); + return d->operation; + } + bool LinkMovie::isReferencedAnnotation( const MovieAnnotation *annotation ) const + { + Q_D( const LinkMovie ); + if ( d->annotationReference == annotation->d_ptr->pdfObjectReference ) + { + return true; + } + else if ( !d->annotationTitle.isNull() ) + { + return ( annotation->movieTitle() == d->annotationTitle ); + } + + return false; + } } diff --git a/qt4/src/poppler-link.h b/qt4/src/poppler-link.h index 1aa6d78..925b5bf 100644 --- a/qt4/src/poppler-link.h +++ b/qt4/src/poppler-link.h @@ -40,6 +40,7 @@ class LinkJavaScriptPrivate; class LinkMoviePrivate; class LinkDestinationData; class LinkDestinationPrivate; +class ObjectReference; class SoundObject; /** @@ -471,21 +472,52 @@ class POPPLER_QT4_EXPORT LinkJavaScript : public Link Q_DISABLE_COPY( LinkJavaScript ) }; -#if 0 -/** Movie: Not yet defined -> think renaming to 'Media' link **/ +/** + * Movie: a movie to be played. + * + * \since 0.20 + */ class POPPLER_QT4_EXPORT LinkMovie : public Link -// TODO this (Movie link) { public: - LinkMovie( const QRectF &linkArea ); + /** + * Describes the operation to be performed on the movie. + */ + enum Operation { Play, + Stop, + Pause, + Resume + }; + + /** + * Create a new Movie link. + * + * \param linkArea the active area of the link + * \param operation the operation to be performed on the movie + * \param annotationTitle the title of the movie annotation identifying the movie to be played + * \param annotationReference the object reference of the movie annotation identifying the movie to be played + * + * Note: This constructor is supposed to be used by Poppler::Page only. + */ + LinkMovie( const QRectF &linkArea, Operation operation, const QString &annotationTitle, const ObjectReference &annotationReference ); + /** + * Destructor. + */ ~LinkMovie(); LinkType linkType() const; + /** + * Returns the operation to be performed on the movie. + */ + Operation operation() const; + /** + * Returns whether the given @p annotation is the referenced movie annotation for this movie @p link. + */ + bool isReferencedAnnotation( const MovieAnnotation *annotation ) const; private: Q_DECLARE_PRIVATE( LinkMovie ) Q_DISABLE_COPY( LinkMovie ) }; -#endif } diff --git a/qt4/src/poppler-objectreference.cc b/qt4/src/poppler-objectreference.cc new file mode 100644 index 0000000..fc87cd2 --- /dev/null +++ b/qt4/src/poppler-objectreference.cc @@ -0,0 +1,92 @@ +/* poppler-objectreference.h: qt interface to poppler + * + * Copyright (C) 2012, Tobias Koenig + * + * 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-objectreference_p.h" + +namespace Poppler { + + class ObjectReferencePrivate + { + public: + ObjectReferencePrivate() + : m_number( -1 ), m_generation( -1 ) + { + } + + ObjectReferencePrivate( int number, int generation ) + : m_number( number ), m_generation( generation ) + { + } + + int m_number; + int m_generation; + }; + +} + +using namespace Poppler; + +ObjectReference::ObjectReference() + : d( new ObjectReferencePrivate() ) +{ +} + +ObjectReference::ObjectReference( int number, int generation ) + : d( new ObjectReferencePrivate( number, generation ) ) +{ +} + +ObjectReference::ObjectReference( const ObjectReference &other ) + : d( new ObjectReferencePrivate( other.d->m_number, other.d->m_generation ) ) +{ +} + +ObjectReference::~ObjectReference() +{ + delete d; +} + +ObjectReference& ObjectReference::operator=( const ObjectReference &other ) +{ + if ( this != &other ) + { + d->m_number = other.d->m_number; + d->m_generation = other.d->m_generation; + } + + return *this; +} + +bool ObjectReference::isValid() const +{ + return ( d->m_number != -1 ); +} + +bool ObjectReference::operator==( const ObjectReference &other ) const +{ + if ( !isValid() || !other.isValid() ) + return false; + + return ( ( d->m_number == other.d->m_number ) && ( d->m_generation == other.d->m_generation ) ); +} + +bool ObjectReference::operator!=( const ObjectReference &other ) const +{ + return !operator==( other ); +} diff --git a/qt4/src/poppler-objectreference_p.h b/qt4/src/poppler-objectreference_p.h new file mode 100644 index 0000000..f682aca --- /dev/null +++ b/qt4/src/poppler-objectreference_p.h @@ -0,0 +1,79 @@ +/* poppler-objectreference.h: qt interface to poppler + * + * Copyright (C) 2012, Tobias Koenig + * + * 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_OBJECTREFERENCE_H +#define POPPLER_OBJECTREFERENCE_H + +#include "poppler-export.h" + +namespace Poppler +{ + class ObjectReferencePrivate; + + /** + * \brief Reference of a PDF object + * + * ObjectReference is a class that encapsulates a reference to a PDF object. + * It is needed to store (and later on resolve) references between various PDF entities. + * + * \since 0.20 + */ + class POPPLER_QT4_EXPORT ObjectReference + { + public: + /** + * Creates a new, invalid ObjectReference. + */ + ObjectReference(); + + /** + * Creates a new ObjectReference. + * + * @param number The number of the PDF object. + * @param generation The generation of the PDF object. + */ + ObjectReference( int number, int generation ); + + /** + * Creates a new ObjectReference from an @p other one. + */ + ObjectReference( const ObjectReference &other ); + + /** + * Destroys the ObjectReference. + */ + ~ObjectReference(); + + ObjectReference& operator=( const ObjectReference &other ); + + /** + * Returns whether the object reference is valid. + */ + bool isValid() const; + + bool operator==( const ObjectReference &other ) const; + + bool operator!=( const ObjectReference &other ) const; + + private: + ObjectReferencePrivate * const d; + }; +} + +#endif diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index 398a69b..2830f1d 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -171,15 +171,33 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo 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; + { + ::LinkMovie *lm = (::LinkMovie *)a; + + const QString title = ( lm->hasAnnotTitle() ? UnicodeParsedString( lm->getAnnotTitle() ) : QString() ); + + const ObjectReference reference = ( lm->hasAnnotRef() ? ObjectReference( lm->getAnnotRef()->num, lm->getAnnotRef()->gen ) : ObjectReference() ); + + LinkMovie::Operation operation = LinkMovie::Play; + switch ( lm->getOperation() ) + { + case ::LinkMovie::operationTypePlay: + operation = LinkMovie::Play; + break; + case ::LinkMovie::operationTypePause: + operation = LinkMovie::Pause; + break; + case ::LinkMovie::operationTypeResume: + operation = LinkMovie::Resume; + break; + case ::LinkMovie::operationTypeStop: + operation = LinkMovie::Stop; + break; + }; + + popplerLink = new LinkMovie( linkArea, operation, title, reference ); + } + break; case actionUnknown: break; @@ -1029,6 +1047,8 @@ QList Page::annotations() const //annotation->rUnscaledHeight = (r[3] > r[1]) ? r[3] - r[1] : r[1] - r[3]; } annotation->setBoundary( boundaryRect ); + // -> PDF object reference + annotation->d_ptr->pdfObjectReference = ObjectReference( ann->getRef().num, ann->getRef().gen ); // -> contents annotation->setContents( UnicodeParsedString( ann->getContents() ) ); // -> uniqueName