[PATCH] extend test-poppler-glib to show more page annotations and actions
Thomas Viehmann
tv at beamnet.de
Sat Jan 17 10:11:42 PST 2009
---
glib/test-poppler-glib.cc | 114 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 96 insertions(+), 18 deletions(-)
diff --git a/glib/test-poppler-glib.cc b/glib/test-poppler-glib.cc
index 1ff7010..7f2c1e5 100644
--- a/glib/test-poppler-glib.cc
+++ b/glib/test-poppler-glib.cc
@@ -364,6 +364,29 @@ form_field_print (PopplerFormField *field)
printf ("\n");
}
+static void
+dump_attachment(char* filename, PopplerAttachment* attachment)
+{
+ char *strdate;
+ g_print ("\t\tname: %s\n", attachment->name);
+ g_print ("\t\tdescription: %s\n", attachment->description);
+ g_print ("\t\tsize: %" G_GSIZE_FORMAT "\n", attachment->size);
+ strdate = poppler_format_date (attachment->ctime);
+ if (strdate)
+ {
+ g_print ("\t\tcreation date: %s\n", strdate);
+ g_free (strdate);
+ }
+ strdate = poppler_format_date (attachment->mtime);
+ if (strdate)
+ {
+ g_print ("\t\tmodification date: %s\n", strdate);
+ g_free (strdate);
+ }
+ poppler_attachment_save (attachment, filename, NULL);
+ g_print ("\n");
+}
+
int main (int argc, char *argv[])
{
PopplerDocument *document;
@@ -539,7 +562,78 @@ int main (int argc, char *argv[])
form_field_print (field);
g_object_unref (field);
}
+
+ list = poppler_page_get_link_mapping (page);
+ if (g_list_length (list)>0)
+ printf ("\tFound the following links:\n");
+ else
+ printf ("\tNo links found\n");
+
+ for (l = list; l != NULL; l = l->next)
+ {
+ PopplerLinkMapping *mapping = (PopplerLinkMapping *)l->data;
+
+ printf ("\t\t(%f, %f) - (%f, %f)\n",
+ mapping->area.x1,
+ mapping->area.y1,
+ mapping->area.x2,
+ mapping->area.y2);
+ enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ACTION_TYPE),
+ mapping->action->type);
+ g_print ("\t\t\tAction: %s (%d)\n", enum_value->value_name, mapping->action->type);
+ switch (mapping->action->type)
+ {
+ case POPPLER_ACTION_GOTO_DEST:
+ printf("\t\t\tDest title: %s\n", mapping->action->goto_dest.title);
+ printf("\t\t\tNamed dest: %s\n", mapping->action->goto_dest.dest->named_dest);
+ break;
+ default:
+ printf("\t\t\tDetails unimplemented for this dest\n");
+ }
+
+ }
+ poppler_page_free_link_mapping (list);
+
+ list = poppler_page_get_annot_mapping (page);
+ if (g_list_length (list)>0)
+ {
+ printf ("\tFound the following annotations:\n");
+ int i = 0;
+ for (l = list; l != NULL; l = l->next)
+ {
+ PopplerAnnotMapping *mapping = (PopplerAnnotMapping *)l->data;
+
+ printf ("\t\t(%f, %f) - (%f, %f)\n",
+ mapping->area.x1,
+ mapping->area.y1,
+ mapping->area.x2,
+ mapping->area.y2);
+ enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
+ poppler_annot_get_annot_type(mapping->annot));
+ g_print ("\t\tAnnot type: %s (%d)\n", enum_value->value_name,
+ poppler_annot_get_annot_type (mapping->annot));
+ PopplerAttachment* attachment;
+ char *filename;
+ switch (poppler_annot_get_annot_type(mapping->annot))
+ {
+ case POPPLER_ANNOT_FILE_ATTACHMENT:
+ attachment = poppler_annot_file_attachment_get_attachment((PopplerAnnotFileAttachment*) mapping->annot);
+ filename = g_strdup_printf ("annot-attach%d", i);
+ dump_attachment(filename, attachment);
+ g_free (filename);
+ i++;
+ break;
+ default:
+ printf("\t\tDetails unimplemented for this annotation type\n");
+ }
+ }
+ }
+ else
+ printf ("\tNo annotations found\n");
+
+ poppler_page_free_annot_mapping (list);
+
if (poppler_document_has_attachments (document))
{
int i = 0;
@@ -550,28 +644,12 @@ int main (int argc, char *argv[])
for (l = list; l; l = l->next)
{
PopplerAttachment *attachment;
- char *filename, *strdate;
+ char *filename;
filename = g_strdup_printf ("/tmp/attach%d", i);
attachment = (PopplerAttachment *)l->data;
- g_print ("\tname: %s\n", attachment->name);
- g_print ("\tdescription: %s\n", attachment->description);
- g_print ("\tsize: %" G_GSIZE_FORMAT "\n", attachment->size);
- strdate = poppler_format_date (attachment->ctime);
- if (strdate)
- {
- g_print ("\tcreation date: %s\n", strdate);
- g_free (strdate);
- }
- strdate = poppler_format_date (attachment->mtime);
- if (strdate)
- {
- g_print ("\tmodification date: %s\n", strdate);
- g_free (strdate);
- }
- poppler_attachment_save (attachment, filename, NULL);
+ dump_attachment(filename, attachment);
g_free (filename);
- g_print ("\n");
i++;
}
g_list_foreach (list, (GFunc) g_object_unref, NULL);
--
1.5.6.5
--------------000508090702040409040608
Content-Type: text/x-patch;
name="poppler.signedness-of-PopplerAttachment.size.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="poppler.signedness-of-PopplerAttachment.size.patch"
More information about the poppler
mailing list