[PATCH] add support for file attachment annotations

Thomas Viehmann tv at beamnet.de
Sat Jan 17 10:08:37 PST 2009


---
 glib/poppler-annot.cc      |   63 ++++++++++++++++++++++++++++++++++++++++++++
 glib/poppler-annot.h       |    8 +++++
 glib/poppler-attachment.cc |    4 +--
 glib/poppler-document.cc   |    2 +-
 glib/poppler-page.cc       |    3 ++
 glib/poppler-private.h     |    4 +-
 glib/poppler.h             |    1 +
 7 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 067afcc..15d7178 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -24,6 +24,8 @@ typedef struct _PopplerAnnotClass         PopplerAnnotClass;
 typedef struct _PopplerAnnotMarkupClass   PopplerAnnotMarkupClass;
 typedef struct _PopplerAnnotFreeTextClass PopplerAnnotFreeTextClass;
 typedef struct _PopplerAnnotTextClass     PopplerAnnotTextClass;
+typedef struct _PopplerAnnotMovieClass    PopplerAnnotMovieClass;
+typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass;
 
 struct _PopplerAnnot
 {
@@ -46,6 +48,16 @@ struct _PopplerAnnotMarkupClass
   PopplerAnnotClass parent_class;
 };
 
+struct _PopplerAnnotFileAttachment
+{
+  PopplerAnnotMarkup parent_instance;
+};
+
+struct _PopplerAnnotFileAttachmentClass
+{
+  PopplerAnnotMarkupClass parent_class;
+};
+
 struct _PopplerAnnotText
 {
   PopplerAnnotMarkup parent_instance;
@@ -68,6 +80,7 @@ struct _PopplerAnnotFreeTextClass
 
 G_DEFINE_TYPE (PopplerAnnot, poppler_annot, G_TYPE_OBJECT)
 G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT)
+G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLER_TYPE_ANNOT_MARKUP)
 G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP)
 G_DEFINE_TYPE (PopplerAnnotFreeText, poppler_annot_free_text, POPPLER_TYPE_ANNOT_MARKUP)
 
@@ -116,6 +129,27 @@ poppler_annot_markup_class_init (PopplerAnnotMarkupClass *klass)
 }
 
 static void
+poppler_annot_file_attachment_init (PopplerAnnotFileAttachment *poppler_annot)
+{
+}
+
+static void
+poppler_annot_file_attachment_class_init (PopplerAnnotFileAttachmentClass *klass)
+{
+}
+
+PopplerAnnot *
+_poppler_annot_file_attachment_new (Annot *annot)
+{
+  PopplerAnnot *poppler_annot;
+
+  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_FILE_ATTACHMENT, NULL));
+  poppler_annot->annot = annot;
+
+  return poppler_annot;
+}
+
+static void
 poppler_annot_text_init (PopplerAnnotText *poppler_annot)
 {
 }
@@ -532,6 +566,35 @@ poppler_annot_markup_get_external_data (PopplerAnnotMarkup *poppler_annot)
   return POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_UNKNOWN;
 }
 
+/* PopplerAnnotFileAttachment */
+/**
+ * poppler_annot_file_attachment_get_attachment:
+ * @annot: a #PopplerAnnotFileAttachment
+ *
+ * Creates a #PopplerAttachment for the file of the file attachment annotation @annot.
+ * The #PopplerAttachment must be freed with g_free by the caller.
+ *
+ * Return value: @PopplerAttachment
+ **/
+PopplerAttachment*
+poppler_annot_file_attachment_get_attachment (PopplerAnnotFileAttachment *annot)
+{
+  AnnotFileAttachment *annot_file_attachment;
+  PopplerAttachment *attachment;
+
+  g_return_val_if_fail (POPPLER_IS_ANNOT_FILE_ATTACHMENT (annot), FALSE);
+
+
+  annot_file_attachment = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT (annot)->annot);
+
+  EmbFile* emb_file = new EmbFile (annot_file_attachment->getFile(), annot_file_attachment->getContents());
+  attachment = _poppler_attachment_new (emb_file);
+  delete emb_file;
+
+
+  return attachment;
+}
+
 /* PopplerAnnotText */
 /**
  * poppler_annot_text_get_is_open:
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 3e38975..22a246e 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -33,6 +33,10 @@ G_BEGIN_DECLS
 #define POPPLER_ANNOT_MARKUP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_MARKUP, PopplerAnnotMarkup))
 #define POPPLER_IS_ANNOT_MARKUP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_MARKUP))
 
+#define POPPLER_TYPE_ANNOT_FILE_ATTACHMENT   (poppler_annot_file_attachment_get_type ())
+#define POPPLER_ANNOT_FILE_ATTACHMENT(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_MARKUP, PopplerAnnotFileAttachment))
+#define POPPLER_IS_ANNOT_FILE_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_FILE_ATTACHMENT))
+
 #define POPPLER_TYPE_ANNOT_TEXT              (poppler_annot_text_get_type ())
 #define POPPLER_ANNOT_TEXT(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_TEXT, PopplerAnnotText))
 #define POPPLER_IS_ANNOT_TEXT(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_TEXT))
@@ -148,6 +152,10 @@ gchar                        *poppler_annot_markup_get_subject                 (
 PopplerAnnotMarkupReplyType   poppler_annot_markup_get_reply_to                (PopplerAnnotMarkup *poppler_annot);
 PopplerAnnotExternalDataType  poppler_annot_markup_get_external_data           (PopplerAnnotMarkup *poppler_annot);
 
+/* PopplerAnnotFileAttachment */
+GType                         poppler_annot_file_attachment_get_type           (void) G_GNUC_CONST;
+PopplerAttachment            *poppler_annot_file_attachment_get_attachment     (PopplerAnnotFileAttachment *annot);
+
 /* PopplerAnnotText */
 GType                         poppler_annot_text_get_type                      (void) G_GNUC_CONST;
 gboolean                      poppler_annot_text_get_is_open                   (PopplerAnnotText *poppler_annot);
diff --git a/glib/poppler-attachment.cc b/glib/poppler-attachment.cc
index 1c3eef0..e959a06 100644
--- a/glib/poppler-attachment.cc
+++ b/glib/poppler-attachment.cc
@@ -77,12 +77,10 @@ poppler_attachment_finalize (GObject *obj)
 /* Public functions */
 
 PopplerAttachment *
-_poppler_attachment_new (PopplerDocument *document,
-			 EmbFile         *emb_file)
+_poppler_attachment_new (EmbFile         *emb_file)
 {
   PopplerAttachment *attachment;
 
-  g_assert (document != NULL);
   g_assert (emb_file != NULL);
 
   attachment = (PopplerAttachment *) g_object_new (POPPLER_TYPE_ATTACHMENT, NULL);
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 352149b..b83dd6e 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -430,7 +430,7 @@ poppler_document_get_attachments (PopplerDocument *document)
       EmbFile *emb_file;
 
       emb_file = catalog->embeddedFile (i);
-      attachment = _poppler_attachment_new (document, emb_file);
+      attachment = _poppler_attachment_new (emb_file);
       delete emb_file;
 
       retval = g_list_prepend (retval, attachment);
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 29d124d..9d48198 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1692,6 +1692,9 @@ poppler_page_get_annot_mapping (PopplerPage *page)
 
     switch (annot->getType ())
       {
+      case Annot::typeFileAttachment:
+        mapping->annot = _poppler_annot_file_attachment_new (annot);
+	break;
       case Annot::typeText:
         mapping->annot = _poppler_annot_text_new (annot);
 	break;
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index c4380ea..02c60d9 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -103,9 +103,9 @@ PopplerDest   *_poppler_dest_new_goto (PopplerDocument *document,
 				       LinkDest        *link_dest);
 PopplerFormField *_poppler_form_field_new (PopplerDocument *document,
 					   FormWidget      *field);
-PopplerAttachment *_poppler_attachment_new (PopplerDocument *document,
-					    EmbFile         *file);
+PopplerAttachment *_poppler_attachment_new (EmbFile         *file);
 PopplerAnnot      *_poppler_annot_new           (Annot *annot);
+PopplerAnnot      *_poppler_annot_file_attachment_new (Annot *annot);
 PopplerAnnot      *_poppler_annot_text_new      (Annot *annot);
 PopplerAnnot      *_poppler_annot_free_text_new (Annot *annot);
 
diff --git a/glib/poppler.h b/glib/poppler.h
index d554093..c9a6758 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -100,6 +100,7 @@ typedef struct _PopplerFormField        PopplerFormField;
 typedef struct _PopplerAttachment       PopplerAttachment;
 typedef struct _PopplerAnnot            PopplerAnnot;
 typedef struct _PopplerAnnotMarkup      PopplerAnnotMarkup;
+typedef struct _PopplerAnnotFileAttachment PopplerAnnotFileAttachment;
 typedef struct _PopplerAnnotText        PopplerAnnotText;
 typedef struct _PopplerAnnotFreeText    PopplerAnnotFreeText;
 typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine;
-- 
1.5.6.5


--------------000508090702040409040608
Content-Type: text/x-patch;
 name="poppler.extend-test-poppler-glib-to-show-more-page-annotatio.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename*0="poppler.extend-test-poppler-glib-to-show-more-page-annotatio";
 filename*1=".patch"



More information about the poppler mailing list