On Sat, Aug 23, 2008 at 6:54 PM, Hugo Mercier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Here is a patch that exports Movie actions and annotations to the glib
> part.
> Feel free, of course, to comment.
> If you are OK with the proposed structure, I'll complete the patch and go
> on with Screen annotation and Rendition action support.
>
>
Hi all,
After discussions with IƱigo and Carlos (thanks to them !), you can find in
attachment a revised patch regarding the glib movie support.
In the previous patch, the way movie parameters are accessed within the
PopplerAnnotMovie was not very clear. It should now be better:
PopplerAnnotMovie provides access to AnnotMovie-specific fields (title) and
to a generic PopplerMovie data sttucture that holds movie parameters
(wrapper to the Movie class). This data structure will also be used to store
Media object parameters.
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 95f46ff..a893ba0 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -65,6 +65,7 @@ poppler_glib_public_headers = \
poppler-attachment.h \
poppler-form-field.h \
poppler-annot.h \
+ poppler-movie.h \
poppler.h
poppler_glib_includedir = $(includedir)/poppler/glib
@@ -83,6 +84,7 @@ libpoppler_glib_la_SOURCES = \
poppler-attachment.cc \
poppler-form-field.cc \
poppler-annot.cc \
+ poppler-movie.cc \
poppler.cc \
poppler-private.h
diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index 080eb27..bca5bff 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -118,7 +118,9 @@ poppler_action_free (PopplerAction *action)
g_free (action->named.named_dest);
break;
case POPPLER_ACTION_MOVIE:
- /* TODO */
+ if (action->movie.has_annotation_title) {
+ g_free(action->movie.annotation_title);
+ }
break;
default:
break;
@@ -174,7 +176,8 @@ poppler_action_copy (PopplerAction *action)
new_action->named.named_dest = g_strdup (action->named.named_dest);
break;
case POPPLER_ACTION_MOVIE:
- /* TODO */
+ if (action->movie.has_annotation_title)
+ new_action->movie.annotation_title = g_strdup (action->movie.annotation_title);
break;
default:
break;
@@ -372,9 +375,43 @@ build_named (PopplerAction *action,
static void
build_movie (PopplerAction *action,
- LinkAction *link)
+ LinkMovie *link)
{
- /* FIXME: Write */
+ PopplerActionMovieOperationType nop;
+
+ switch(link->getOperation ()) {
+ case LinkMovie::operationTypePause:
+ nop = POPPLER_ACTION_MOVIE_OPERATION_PAUSE;
+ break;
+ case LinkMovie::operationTypeResume:
+ nop = POPPLER_ACTION_MOVIE_OPERATION_RESUME;
+ break;
+ case LinkMovie::operationTypeStop:
+ nop = POPPLER_ACTION_MOVIE_OPERATION_STOP;
+ break;
+ default:
+ case LinkMovie::operationTypePlay:
+ nop = POPPLER_ACTION_MOVIE_OPERATION_PLAY;
+ break;
+ }
+ action->movie.operation = nop;
+
+ action->movie.has_annotation_ref = link->hasAnnotRef ();
+ action->movie.has_annotation_title = link->hasAnnotTitle ();
+
+ if (link->hasAnnotRef ()) {
+ Ref* ref = link->getAnnotRef ();
+ action->movie.annotation_id = ref->num;
+ } else {
+ action->movie.annotation_id = 0;
+ }
+
+ if (link->hasAnnotTitle ()) {
+ action->movie.annotation_title = g_strdup(link->getAnnotTitle()->getCString ());
+ } else {
+ action->movie.annotation_title = NULL;
+ }
+
}
PopplerAction *
@@ -417,7 +454,7 @@ _poppler_action_new (PopplerDocument *document,
break;
case actionMovie:
action->type = POPPLER_ACTION_MOVIE;
- build_movie (action, link);
+ build_movie (action, dynamic_cast<LinkMovie*> (link));
break;
case actionUnknown:
default:
diff --git a/glib/poppler-action.h b/glib/poppler-action.h
index a89351a..44d14e5 100644
--- a/glib/poppler-action.h
+++ b/glib/poppler-action.h
@@ -50,6 +50,14 @@ typedef enum
POPPLER_DEST_NAMED
} PopplerDestType;
+typedef enum
+{
+ POPPLER_ACTION_MOVIE_OPERATION_PLAY,
+ POPPLER_ACTION_MOVIE_OPERATION_PAUSE,
+ POPPLER_ACTION_MOVIE_OPERATION_RESUME,
+ POPPLER_ACTION_MOVIE_OPERATION_STOP
+} PopplerActionMovieOperationType;
+
/* Define the PopplerAction types */
typedef struct _PopplerActionAny PopplerActionAny;
typedef struct _PopplerActionGotoDest PopplerActionGotoDest;
@@ -126,8 +134,15 @@ struct _PopplerActionNamed
struct _PopplerActionMovie
{
- PopplerActionType type;
- gchar *title;
+ PopplerActionType type;
+ gchar *title;
+
+ PopplerActionMovieOperationType operation;
+
+ gboolean has_annotation_ref;
+ gboolean has_annotation_title;
+ gchar *annotation_title;
+ gint annotation_id;
};
union _PopplerAction
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index b7e5819..7e1d212 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -24,6 +24,7 @@ typedef struct _PopplerAnnotClass PopplerAnnotClass;
typedef struct _PopplerAnnotMarkupClass PopplerAnnotMarkupClass;
typedef struct _PopplerAnnotFreeTextClass PopplerAnnotFreeTextClass;
typedef struct _PopplerAnnotTextClass PopplerAnnotTextClass;
+typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass;
struct _PopplerAnnot
{
@@ -66,10 +67,22 @@ struct _PopplerAnnotFreeTextClass
PopplerAnnotMarkupClass parent_class;
};
+struct _PopplerAnnotMovie
+{
+ PopplerAnnot parent_instance;
+};
+
+struct _PopplerAnnotMovieClass
+{
+ GObjectClass parent_class;
+};
+
+
G_DEFINE_TYPE (PopplerAnnot, poppler_annot, G_TYPE_OBJECT);
G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT);
G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP);
G_DEFINE_TYPE (PopplerAnnotFreeText, poppler_annot_free_text, POPPLER_TYPE_ANNOT_MARKUP);
+G_DEFINE_TYPE (PopplerAnnotMovie, poppler_annot_movie, POPPLER_TYPE_ANNOT);
static void
poppler_annot_finalize (GObject *object)
@@ -157,6 +170,30 @@ _poppler_annot_free_text_new (Annot *annot)
return poppler_annot;
}
+
+static void
+poppler_annot_movie_init (PopplerAnnotMovie *poppler_annot)
+{
+}
+
+static void
+poppler_annot_movie_class_init (PopplerAnnotMovieClass *klass)
+{
+}
+
+
+PopplerAnnot *
+_poppler_annot_movie_new (Annot *annot)
+{
+ PopplerAnnot *poppler_annot;
+
+ poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_MOVIE, NULL));
+ poppler_annot->annot = annot;
+
+ return poppler_annot;
+}
+
+
/* Public methods */
/**
* poppler_annot_get_annot_type:
@@ -354,6 +391,27 @@ poppler_annot_get_color (PopplerAnnot *poppler_annot)
return NULL;
}
+/**
+ * poppler_annot_get_id:
+ * @poppler_annot: a #PopplerAnnot
+ *
+ * Retrieves the ID of @poppler_annot.
+ *
+ * Return value: na integer that represents the annotation's ID
+ **/
+gint
+poppler_annot_get_id (PopplerAnnot *poppler_annot)
+{
+ gint id;
+
+ g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
+
+ id = poppler_annot->annot->getId();
+
+ return id;
+}
+
+
/* PopplerAnnotMarkup */
/**
* poppler_annot_markup_get_label:
@@ -757,3 +815,54 @@ poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout)
{
g_free (callout);
}
+
+
+/* PopplerAnnotMovie */
+/**
+* poppler_annot_movie_get_title:
+* @poppler_annot: a #PopplerAnnotMovie
+*
+* Retrieves the movie title of @poppler_annot.
+*
+* Return value: the title text of @poppler_annot.
+*/
+gchar *
+poppler_annot_movie_get_title (PopplerAnnotMovie *poppler_annot)
+{
+ AnnotMovie *annot;
+ GooString *title;
+
+ g_return_val_if_fail (POPPLER_IS_ANNOT_MOVIE (poppler_annot), NULL);
+
+ annot = static_cast<AnnotMovie *>(POPPLER_ANNOT (poppler_annot)->annot);
+
+ title = annot->getTitle ();
+
+ return title ? _poppler_goo_string_to_utf8 (title) : NULL;
+}
+
+
+
+
+/**
+* poppler_annot_movie_get_movie:
+* @poppler_annot: a #PopplerAnnotMovie
+*
+* Retrieves the movie object (PopplerMovie) stored in the @poppler_annot.
+*
+* Return value: the movie object stored in the @poppler_annot.
+*/
+PopplerMovie *
+poppler_annot_movie_get_movie (PopplerAnnotMovie *poppler_annot)
+{
+ AnnotMovie *annot;
+ PopplerMovie *movie;
+
+ g_return_val_if_fail (POPPLER_IS_ANNOT_MOVIE (poppler_annot), NULL);
+
+ annot = static_cast<AnnotMovie *>(POPPLER_ANNOT (poppler_annot)->annot);
+
+ movie = _poppler_movie_new(annot->getMovie());
+
+ return movie;
+}
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 3e38975..c290362 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -43,6 +43,11 @@ G_BEGIN_DECLS
#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ())
+#define POPPLER_TYPE_ANNOT_MOVIE (poppler_annot_movie_get_type ())
+#define POPPLER_ANNOT_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_MOVIE, PopplerAnnotMovie))
+#define POPPLER_IS_ANNOT_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_MOVIE))
+
+
typedef enum
{
POPPLER_ANNOT_UNKNOWN,
@@ -137,6 +142,7 @@ gchar *poppler_annot_get_name (
gchar *poppler_annot_get_modified (PopplerAnnot *poppler_annot);
PopplerAnnotFlag poppler_annot_get_flags (PopplerAnnot *poppler_annot);
PopplerColor *poppler_annot_get_color (PopplerAnnot *poppler_annot);
+gint poppler_annot_get_id (PopplerAnnot *poppler_annot);
/* PopplerAnnotMarkup */
GType poppler_annot_markup_get_type (void) G_GNUC_CONST;
@@ -165,6 +171,12 @@ PopplerAnnotCalloutLine *poppler_annot_callout_line_new (
PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout);
void poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout);
+/* PopplerAnnotMovie */
+GType poppler_annot_movie_get_type (void) G_GNUC_CONST;
+gchar *poppler_annot_movie_get_title (PopplerAnnotMovie *poppler_annot);
+PopplerMovie *poppler_annot_movie_get_movie (PopplerAnnotMovie *poppler_annot);
+
+
G_END_DECLS
#endif /* __POPPLER_ANNOT_H__ */
diff --git a/glib/poppler-movie.cc b/glib/poppler-movie.cc
new file mode 100644
index 0000000..3d74633
--- /dev/null
+++ b/glib/poppler-movie.cc
@@ -0,0 +1,175 @@
+/* poppler-movie.cc: glib interface to Movie
+ *
+ * Copyright (C) 2008 Hugo Mercier <[EMAIL PROTECTED]>
+ *
+ * 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.h"
+#include "poppler-private.h"
+
+typedef struct _PopplerMovieClass PopplerMovieClass;
+
+
+struct _PopplerMovie
+{
+ GObject parent_instance;
+
+ Movie *movie;
+ gboolean has_ownership;
+};
+
+struct _PopplerMovieClass
+{
+ GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (PopplerMovie, poppler_movie, G_TYPE_OBJECT);
+
+static void poppler_movie_finalize(GObject *object)
+{
+ PopplerMovie* movie = POPPLER_MOVIE(object);
+
+ if (movie->has_ownership)
+ delete movie->movie;
+
+ G_OBJECT_CLASS (poppler_movie_parent_class)->finalize (object);
+}
+
+static void poppler_movie_class_init(PopplerMovieClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = poppler_movie_finalize;
+}
+
+static void poppler_movie_init(PopplerMovie *movie)
+{
+ movie->movie = NULL;
+ movie->has_ownership = FALSE;
+}
+
+PopplerMovie* _poppler_movie_new(Movie* cc_movie)
+{
+ PopplerMovie *movie;
+
+ movie = POPPLER_MOVIE(g_object_new(POPPLER_TYPE_MOVIE, NULL));
+ movie->movie = cc_movie;
+ movie->has_ownership = FALSE;
+
+ return movie;
+}
+
+PopplerMovie* poppler_movie_copy(PopplerMovie* movie) {
+ PopplerMovie *new_movie;
+
+ new_movie = POPPLER_MOVIE(g_object_new(POPPLER_TYPE_MOVIE, NULL));
+ new_movie->movie = movie->movie->copy();
+ new_movie->has_ownership = TRUE;
+
+ return new_movie;
+}
+
+
+/**
+* poppler_movie_is_embedded:
+* @poppler_movie: a #PopplerMovie
+*
+* Tests whether the movie is embedded in the PDF. If the result is TRUE, the embedded stream
+* should be extracted with the poppler_movie_output_to_file() function. If the result is FALSE,
+* the movie filename can be retrieved with the poppler_movie_get_file_name() function.
+*
+* Return value: a boolean
+*/
+
+gboolean
+poppler_movie_is_embedded (PopplerMovie *poppler_movie)
+{
+ Movie *movie;
+
+ g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), NULL);
+
+ movie = static_cast<Movie *>(POPPLER_MOVIE (poppler_movie)->movie);
+
+ return movie->getIsEmbedded () ? TRUE : FALSE ;
+}
+
+
+/**
+* poppler_movie_get_file_name:
+* @poppler_movie: a #PopplerMovie
+*
+* Returns the movie filename, in case of non-embedded movie.
+*
+* Return value: a gchar* that represents a filename
+*/
+gchar *
+poppler_movie_get_file_name (PopplerMovie *poppler_movie)
+{
+ Movie *movie;
+ GooString *filename;
+
+ g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), NULL);
+
+ movie = static_cast<Movie *>(POPPLER_MOVIE (poppler_movie)->movie);
+
+ filename = movie->getFileName ();
+
+ return filename ? _poppler_goo_string_to_utf8 (filename) : NULL;
+}
+
+/**
+* poppler_movie_get_content_type:
+* @poppler_movie: a #PopplerMovie
+*
+* Returns the movie file content type.
+*
+* Return value: a gchar* that represents a content-type
+*/
+gchar *
+poppler_movie_get_content_type (PopplerMovie *poppler_movie)
+{
+ Movie *movie;
+ GooString *content_type;
+
+ g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), NULL);
+
+ movie = static_cast<Movie *>(POPPLER_MOVIE (poppler_movie)->movie);
+
+ content_type = movie->getContentType ();
+
+ return content_type ? _poppler_goo_string_to_utf8 (content_type) : NULL;
+}
+
+/**
+* poppler_movie_output_to_file:
+* @poppler_movie: a #PopplerMovie
+* @fp: a file descriptor
+*
+* Extract the embedded movie stream to an already opened file.
+*
+* Return value: void
+*/
+void
+poppler_movie_output_to_file (PopplerMovie *poppler_movie, FILE *fp)
+{
+ Movie *movie;
+
+ g_return_if_fail (POPPLER_IS_MOVIE (poppler_movie));
+
+ movie = static_cast<Movie *>(POPPLER_MOVIE (poppler_movie)->movie);
+
+ movie->outputToFile(fp);
+}
diff --git a/glib/poppler-movie.h b/glib/poppler-movie.h
new file mode 100644
index 0000000..6a46a47
--- /dev/null
+++ b/glib/poppler-movie.h
@@ -0,0 +1,46 @@
+/* poppler-movie.h: glib interface to Movie
+ *
+ * Copyright (C) 2008 Hugo Mercier <[EMAIL PROTECTED]>
+ *
+ * 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_MOVIE_H__
+#define __POPPLER_MOVIE_H__
+
+
+#include <glib-object.h>
+#include "poppler.h"
+
+G_BEGIN_DECLS
+
+#define POPPLER_TYPE_MOVIE (poppler_movie_get_type ())
+#define POPPLER_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_MOVIE, PopplerMovie))
+#define POPPLER_IS_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_MOVIE))
+
+
+GType poppler_movie_get_type (void) G_GNUC_CONST;
+PopplerMovie* poppler_movie_copy (PopplerMovie* movie);
+
+gboolean poppler_movie_is_embedded (PopplerMovie* movie);
+gchar* poppler_movie_get_file_name (PopplerMovie* movie);
+gchar* poppler_movie_get_content_type (PopplerMovie* movie);
+void poppler_movie_output_to_file (PopplerMovie* movie, FILE* fp);
+
+G_END_DECLS
+
+
+#endif
+
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index cf737cd..1c0cec8 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1640,6 +1640,9 @@ poppler_page_get_annot_mapping (PopplerPage *page)
case Annot::typeFreeText:
mapping->annot = _poppler_annot_free_text_new (annot);
break;
+ case Annot::typeMovie:
+ mapping->annot = _poppler_annot_movie_new (annot);
+ break;
default:
mapping->annot = _poppler_annot_new (annot);
break;
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index 539714c..c6a0663 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -10,6 +10,7 @@
#include <FontInfo.h>
#include <TextOutputDev.h>
#include <Catalog.h>
+#include <Movie.h>
#if defined (HAVE_CAIRO)
#include <CairoOutputDev.h>
@@ -83,6 +84,9 @@ PopplerAttachment *_poppler_attachment_new (PopplerDocument *document,
PopplerAnnot *_poppler_annot_new (Annot *annot);
PopplerAnnot *_poppler_annot_text_new (Annot *annot);
PopplerAnnot *_poppler_annot_free_text_new (Annot *annot);
+PopplerAnnot *_poppler_annot_movie_new (Annot *annot);
+
+PopplerMovie *_poppler_movie_new (Movie* movie);
char *_poppler_goo_string_to_utf8(GooString *s);
gboolean _poppler_convert_pdf_date_to_gtime (GooString *date,
diff --git a/glib/poppler.h b/glib/poppler.h
index 88a330c..b34e7be 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -101,6 +101,8 @@ typedef struct _PopplerAnnotMarkup PopplerAnnotMarkup;
typedef struct _PopplerAnnotText PopplerAnnotText;
typedef struct _PopplerAnnotFreeText PopplerAnnotFreeText;
typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
+typedef struct _PopplerAnnotMovie PopplerAnnotMovie;
+typedef struct _PopplerMovie PopplerMovie;
typedef enum
{
@@ -122,5 +124,6 @@ G_END_DECLS
#include "poppler-enums.h"
#include "poppler-attachment.h"
#include "poppler-annot.h"
+#include "poppler-movie.h"
#endif /* __POPPLER_GLIB_H__ */
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler