* glib movie support.
Sam Kaplan (none)
skaplan at fermatjr.
Sat Nov 7 17:13:28 PST 2009
---
glib/CMakeLists.txt | 2 +
glib/Makefile.am | 2 +
glib/demo/annots.c | 32 ++++++++++++
glib/poppler-annot.cc | 56 ++++++++++++++++++++
glib/poppler-annot.h | 9 +++
glib/poppler-movie.cc | 133 ++++++++++++++++++++++++++++++++++++++++++++++++
glib/poppler-movie.h | 40 ++++++++++++++
glib/poppler-page.cc | 3 +
glib/poppler-private.h | 3 +
glib/poppler.h | 4 ++
10 files changed, 284 insertions(+), 0 deletions(-)
create mode 100644 glib/poppler-movie.cc
create mode 100644 glib/poppler-movie.h
diff --git a/glib/CMakeLists.txt b/glib/CMakeLists.txt
index 2cb207b..103a94d 100644
--- a/glib/CMakeLists.txt
+++ b/glib/CMakeLists.txt
@@ -30,6 +30,7 @@ set(poppler_glib_public_headers
poppler-attachment.h
poppler-form-field.h
poppler-annot.h
+ poppler-movie.h
poppler.h
)
@@ -83,6 +84,7 @@ set(poppler_glib_SRCS
poppler-form-field.cc
poppler-annot.cc
poppler-layer.cc
+ poppler-movie.cc
poppler.cc
${CMAKE_CURRENT_BINARY_DIR}/poppler-enums.c
)
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 3c065fe..b921511 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -52,6 +52,7 @@ poppler_glib_public_headers = \
poppler-form-field.h \
poppler-annot.h \
poppler-layer.h \
+ poppler-movie.h \
poppler.h
poppler_glib_includedir = $(includedir)/poppler/glib
@@ -72,6 +73,7 @@ libpoppler_glib_la_SOURCES = \
poppler-form-field.cc \
poppler-annot.cc \
poppler-layer.cc \
+ poppler-movie.cc \
poppler.cc \
poppler-private.h
diff --git a/glib/demo/annots.c b/glib/demo/annots.c
index 7865f1d..6ab2934 100644
--- a/glib/demo/annots.c
+++ b/glib/demo/annots.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 Inigo Martinez <inigomartinez at gmail.com>
+ * Copyright (C) 2009 Sam Kaplan <skaplan at ualberta.ca>
*
* 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
@@ -369,6 +370,34 @@ pgd_annot_view_set_annot_free_text (GtkWidget *table,
}
static void
+pgd_annot_view_set_annot_screen (GtkWidget *table,
+ PopplerAnnotScreen *annot,
+ gint *row)
+{
+ PopplerMovie *poppler_movie;
+ poppler_movie = poppler_annot_screen_get_movie (annot);
+ GtkWidget *dialog;
+ dialog = gtk_file_chooser_dialog_new ("Save Movie",
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
+ TRUE);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), "HOME");
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "movie");
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ char *filename;
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ poppler_movie_save (poppler_movie, filename, NULL);
+ g_free (filename);
+ }
+ gtk_widget_destroy (dialog);
+}
+
+static void
pgd_annot_view_set_annot (GtkWidget *annot_view,
PopplerAnnot *annot)
{
@@ -427,6 +456,9 @@ pgd_annot_view_set_annot (GtkWidget *annot_view,
case POPPLER_ANNOT_FREE_TEXT:
pgd_annot_view_set_annot_free_text (table, POPPLER_ANNOT_FREE_TEXT (annot), &row);
break;
+ case POPPLER_ANNOT_SCREEN:
+ pgd_annot_view_set_annot_screen (table, POPPLER_ANNOT_SCREEN (annot), &row);
+ break;
default:
break;
}
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 29051f9..008b618 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -2,6 +2,7 @@
*
* Copyright (C) 2007 Inigo Martinez <inigomartinez at gmail.com>
* Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
+ * Copyright (C) 2009 Sam Kaplan <skaplan at ualberta.ca>
*
* 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
@@ -25,6 +26,7 @@ typedef struct _PopplerAnnotClass PopplerAnnotClass;
typedef struct _PopplerAnnotMarkupClass PopplerAnnotMarkupClass;
typedef struct _PopplerAnnotFreeTextClass PopplerAnnotFreeTextClass;
typedef struct _PopplerAnnotTextClass PopplerAnnotTextClass;
+typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass;
struct _PopplerAnnot
{
@@ -67,10 +69,21 @@ struct _PopplerAnnotFreeTextClass
PopplerAnnotMarkupClass parent_class;
};
+struct _PopplerAnnotScreen
+{
+ PopplerAnnotClass parent_instance;
+};
+
+struct _PopplerAnnotScreenClass
+{
+ PopplerAnnotClass 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 (PopplerAnnotScreen, poppler_annot_screen, POPPLER_TYPE_ANNOT)
static void
poppler_annot_finalize (GObject *object)
@@ -158,6 +171,27 @@ _poppler_annot_free_text_new (Annot *annot)
return poppler_annot;
}
+static void
+poppler_annot_screen_init (PopplerAnnotScreen *poppler_annot)
+{
+}
+
+static void
+poppler_annot_screen_class_init (PopplerAnnotScreenClass *klass)
+{
+}
+
+PopplerAnnot *
+_poppler_annot_screen_new (Annot *annot)
+{
+ PopplerAnnot *poppler_annot;
+
+ poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_SCREEN, NULL));
+ poppler_annot->annot = annot;
+
+ return poppler_annot;
+}
+
/* Public methods */
/**
* poppler_annot_get_annot_type:
@@ -741,6 +775,28 @@ poppler_annot_free_text_get_quadding (PopplerAnnotFreeText *poppler_annot)
return POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED;
}
+PopplerMovie *
+poppler_annot_screen_get_movie (PopplerAnnotScreen *poppler_annot)
+{
+
+ AnnotScreen *annot;
+ LinkAction *link;
+
+ annot = static_cast<AnnotScreen *>(POPPLER_ANNOT (poppler_annot)->annot);
+ link = LinkAction::parseAction(annot->getAction(), NULL);
+
+ if (link->getKind() == actionRendition) {
+ PopplerMovie *poppler_movie;
+ Movie *movie;
+ movie = (static_cast<LinkRendition *>(link))->getMovie();
+ poppler_movie = _poppler_movie_new (movie);
+ return poppler_movie;
+ }
+
+ return NULL;
+
+}
+
/**
* poppler_annot_free_text_get_callout_line:
* @poppler_annot: a #PopplerAnnotFreeText
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 4648027..256c9da 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -2,6 +2,7 @@
*
* Copyright (C) 2007 Inigo Martinez <inigomartinez at gmail.com>
* Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
+ * Copyright (C) 2009 Sam Kaplan <skaplan at ualberta.ca>
*
* 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
@@ -42,6 +43,10 @@ G_BEGIN_DECLS
#define POPPLER_ANNOT_FREE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_FREE_TEXT, PopplerAnnotFreeText))
#define POPPLER_IS_ANNOT_FREE_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_FREE_TEXT))
+#define POPPLER_TYPE_ANNOT_SCREEN (poppler_annot_screen_get_type ())
+#define POPPLER_ANNOT_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_SCREEN, PopplerAnnotScreen))
+#define POPPLER_IS_ANNOT_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_SCREEN))
+
#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ())
typedef enum
@@ -165,6 +170,10 @@ GType poppler_annot_free_text_get_type (
PopplerAnnotFreeTextQuadding poppler_annot_free_text_get_quadding (PopplerAnnotFreeText *poppler_annot);
PopplerAnnotCalloutLine *poppler_annot_free_text_get_callout_line (PopplerAnnotFreeText *poppler_annot);
+/* PopplerAnnotScreen */
+GType poppler_annot_screen_get_type (void) G_GNUC_CONST;
+PopplerMovie *poppler_annot_screen_get_movie (PopplerAnnotScreen *poppler_annot);
+
/* PopplerCalloutLine */
GType poppler_annot_callout_line_get_type (void) G_GNUC_CONST;
PopplerAnnotCalloutLine *poppler_annot_callout_line_new (void);
diff --git a/glib/poppler-movie.cc b/glib/poppler-movie.cc
new file mode 100644
index 0000000..cbaecff
--- /dev/null
+++ b/glib/poppler-movie.cc
@@ -0,0 +1,133 @@
+/* poppler-movie.cc: glib interface to poppler
+ *
+ * Copyright (C) 2009 Sam Kaplan <skaplan at ualberta.ca>
+ *
+ * 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 "config.h"
+#include <errno.h>
+#include <glib/gstdio.h>
+
+#include "poppler.h"
+#include "poppler-private.h"
+
+/* FIXME: We need to add gettext support sometime */
+#define _(x) (x)
+
+typedef struct _PopplerMovieClass PopplerMovieClass;
+
+struct _PopplerMovie
+{
+ GObject parent_instance;
+ Movie *movie;
+};
+
+struct _PopplerMovieClass
+{
+ GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (PopplerMovie, poppler_movie, G_TYPE_OBJECT)
+
+static void
+poppler_movie_finalize (GObject *object)
+{
+ PopplerMovie *poppler_movie = POPPLER_MOVIE (object);
+
+ poppler_movie->movie = NULL;
+
+ G_OBJECT_CLASS (poppler_movie_parent_class)->finalize (object);
+}
+
+static void
+poppler_movie_init (PopplerMovie *poppler_movie)
+{
+}
+
+static void
+poppler_movie_class_init (PopplerMovieClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = poppler_movie_finalize;
+}
+
+PopplerMovie *
+_poppler_movie_new (Movie *movie)
+{
+ PopplerMovie *poppler_movie;
+
+ poppler_movie = POPPLER_MOVIE (g_object_new (POPPLER_TYPE_MOVIE, NULL));
+ poppler_movie->movie = movie;
+
+ return poppler_movie;
+}
+
+/**
+ * @poppler_movie: A #PopplerMovie.
+ * @filename: name of file to save.
+ * @error: return location for error, of %NULL.
+ *
+ * Saves @poppler_movie to a file indicated by @filename. If @error is set, %FALSE
+ * will be returned. Possible errors include those in the #G_FILE_ERROR domain
+ * and whatever the save function generates.
+ *
+ * Return value: %TRUE, if the file successfully saved
+ **/
+gboolean
+poppler_movie_save (PopplerMovie *poppler_movie,
+ const char *filename,
+ GError **error)
+{
+ gboolean result;
+ FILE *f;
+
+ g_return_val_if_fail (POPPLER_IS_MOVIE (poppler_movie), FALSE);
+
+ f = g_fopen (filename, "wb");
+
+ if (f == NULL)
+ {
+ gchar *display_name = g_filename_display_name (filename);
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ _("Failed to open '%s' for writing: %s"),
+ display_name,
+ g_strerror (errno));
+ g_free (display_name);
+ return FALSE;
+ }
+
+ poppler_movie->movie->outputToFile (f);
+
+ fclose (f);
+
+ if (fclose (f) < 0)
+ {
+ gchar *display_name = g_filename_display_name (filename);
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ _("Failed to close '%s', all data may not have been saved: %s"),
+ display_name,
+ g_strerror (errno));
+ g_free (display_name);
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/glib/poppler-movie.h b/glib/poppler-movie.h
new file mode 100644
index 0000000..e098b04
--- /dev/null
+++ b/glib/poppler-movie.h
@@ -0,0 +1,40 @@
+/* poppler-movie.h: glib interface to poppler
+ *
+ * Copyright (C) 2009 Sam Kaplan <skaplan at ualberta.ca>
+ *
+ * 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.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;
+gboolean poppler_movie_save (PopplerMovie *poppler_movie,
+ const char *filename, GError **error);
+
+G_END_DECLS
+
+#endif /* __POPPLER_MOVIE_H__ */
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 225c97b..7a7e241 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1700,6 +1700,9 @@ poppler_page_get_annot_mapping (PopplerPage *page)
case Annot::typeFreeText:
mapping->annot = _poppler_annot_free_text_new (annot);
break;
+ case Annot::typeScreen:
+ mapping->annot = _poppler_annot_screen_new (annot);
+ break;
default:
mapping->annot = _poppler_annot_new (annot);
break;
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index e8ace14..1b55786 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -11,6 +11,7 @@
#include <TextOutputDev.h>
#include <Catalog.h>
#include <OptionalContent.h>
+#include <Movie.h>
#if defined (HAVE_CAIRO)
#include <CairoOutputDev.h>
@@ -108,6 +109,8 @@ 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_screen_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 b1a7730..6d42c9b 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -1,5 +1,6 @@
/* poppler.h: glib interface to poppler
* Copyright (C) 2004, Red Hat, Inc.
+ * Copyright (C) 2009, Sam Kaplan <skaplan at ualberta.ca>
*
* 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
@@ -102,7 +103,9 @@ typedef struct _PopplerAnnot PopplerAnnot;
typedef struct _PopplerAnnotMarkup PopplerAnnotMarkup;
typedef struct _PopplerAnnotText PopplerAnnotText;
typedef struct _PopplerAnnotFreeText PopplerAnnotFreeText;
+typedef struct _PopplerAnnotScreen PopplerAnnotScreen;
typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
+typedef struct _PopplerMovie PopplerMovie;
typedef enum
{
@@ -126,5 +129,6 @@ G_END_DECLS
#include "poppler-attachment.h"
#include "poppler-annot.h"
#include "poppler-date.h"
+#include "poppler-movie.h"
#endif /* __POPPLER_GLIB_H__ */
--
1.6.3.3
More information about the poppler
mailing list