[poppler] qt4/src

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Mar 11 15:29:52 PDT 2012


 qt4/src/CMakeLists.txt               |    1 
 qt4/src/poppler-annotation-private.h |    4 +
 qt4/src/poppler-annotation.h         |    4 +
 qt4/src/poppler-link.cc              |   42 ++++++++++++----
 qt4/src/poppler-link.h               |   43 ++++++++++++++--
 qt4/src/poppler-objectreference.cc   |   89 +++++++++++++++++++++++++++++++++++
 qt4/src/poppler-objectreference_p.h  |   77 ++++++++++++++++++++++++++++++
 qt4/src/poppler-page.cc              |   39 +++++++++++----
 8 files changed, 276 insertions(+), 23 deletions(-)

New commits:
commit 448cfc431b7067af38da51e725ac0f1b2a0bc8f8
Author: Tobias Koenig <tokoe at kdab.com>
Date:   Sun Mar 11 23:22:18 2012 +0100

    support for LinkMovie object in Qt4 frontend
    
    Bug #40561

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..5040da0 100644
--- a/qt4/src/poppler-annotation-private.h
+++ b/qt4/src/poppler-annotation-private.h
@@ -1,5 +1,6 @@
 /* poppler-link-extractor-private.h: qt interface to poppler
  * Copyright (C) 2007, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  *
  * 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
@@ -21,6 +22,8 @@
 
 #include "poppler-annotation.h"
 
+#include "poppler-objectreference_p.h"
+
 namespace Poppler
 {
 
@@ -42,6 +45,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..4124c74 100644
--- a/qt4/src/poppler-annotation.h
+++ b/qt4/src/poppler-annotation.h
@@ -3,6 +3,7 @@
  * Copyright (C) 2006, 2008 Pino Toscano <pino at kde.org>
  * Copyright (C) 2007, Brad Hards <bradh at frogmouth.net>
  * Copyright (C) 2010, Philip Lorenz <lorenzph+freedesktop at gmail.com>
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -93,6 +94,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..81ba39f 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -2,6 +2,7 @@
  * Copyright (C) 2006-2007, Albert Astals Cid
  * Copyright (C) 2007-2008, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -25,6 +26,9 @@
 
 #include <QtCore/QStringList>
 
+#include "poppler-annotation-private.h"
+#include "poppler-objectreference_p.h"
+
 #include "Link.h"
 
 namespace Poppler {
@@ -167,18 +171,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 +573,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 +587,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.isValid() && 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..b12ce8b 100644
--- a/qt4/src/poppler-link.h
+++ b/qt4/src/poppler-link.h
@@ -2,6 +2,7 @@
  * Copyright (C) 2006, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2007-2008, 2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010, Guillermo Amaral <gamaral at kdab.com>
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -40,6 +41,7 @@ class LinkJavaScriptPrivate;
 class LinkMoviePrivate;
 class LinkDestinationData;
 class LinkDestinationPrivate;
+class ObjectReference;
 class SoundObject;
 
 /**
@@ -471,21 +473,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..cb32314
--- /dev/null
+++ b/qt4/src/poppler-objectreference.cc
@@ -0,0 +1,89 @@
+/* poppler-objectreference.h: qt interface to poppler
+ *
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
+ *
+ * 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
+{
+  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..52af958
--- /dev/null
+++ b/qt4/src/poppler-objectreference_p.h
@@ -0,0 +1,77 @@
+/* poppler-objectreference.h: qt interface to poppler
+ *
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
+ *
+ * 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.
+   */
+  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..34d8e5e 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -10,6 +10,7 @@
  * Copyright (C) 2010 Suzuki Toshiya <mpsuzuki at hiroshima-u.ac.jp>
  * Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau at gmail.com>
  * Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
+ * Copyright (C) 2012 Tobias Koenig <tokoe at kdab.com>
  *
  * 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
@@ -171,15 +172,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 +1048,8 @@ QList<Annotation*> 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


More information about the poppler mailing list