diff -urN poppler/glib/poppler.h poppler_s/glib/poppler.h --- poppler/glib/poppler.h 2006-04-17 00:59:44.000000000 +0200 +++ poppler_s/glib/poppler.h 2006-04-25 22:43:01.000000000 +0200 @@ -42,11 +42,15 @@ POPPLER_ORIENTATION_SEASCAPE } PopplerOrientation; + + + typedef struct _PopplerDocument PopplerDocument; typedef struct _PopplerIndexIter PopplerIndexIter; typedef struct _PopplerFontsIter PopplerFontsIter; typedef struct _PopplerRectangle PopplerRectangle; typedef struct _PopplerLinkMapping PopplerLinkMapping; +typedef struct _PopplerFormField PopplerFormField; typedef struct _PopplerPage PopplerPage; typedef struct _PopplerFontInfo PopplerFontInfo; typedef struct _PopplerPSFile PopplerPSFile; diff -urN poppler/glib/poppler-page.cc poppler_s/glib/poppler-page.cc --- poppler/glib/poppler-page.cc 2006-04-12 04:07:07.000000000 +0200 +++ poppler_s/glib/poppler-page.cc 2006-04-25 22:43:01.000000000 +0200 @@ -971,3 +971,84 @@ g_free (mapping); } + + +/* Form Type */ +GType +poppler_form_field_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static("PopplerFormField", + (GBoxedCopyFunc) poppler_form_field_copy, + (GBoxedFreeFunc) poppler_form_field_free); + return our_type; +} + +PopplerFormField* +poppler_form_field_new (void) +{ + return (PopplerFormField *) g_new0 (PopplerFormField, 1); +} + +PopplerFormField* +poppler_form_field_copy (PopplerFormField* field) +{ + PopplerFormField* new_field; + new_field = poppler_form_field_new(); + new_field = field; + return new_field; +} + +void +poppler_form_field_free (PopplerFormField* field) +{ + g_free (field); +} + +/** + * poppler_page_get_form + * @page: The #Page from which we get the form + * @return: A list of #PopplerLinkMappings + * + * Return a list of PopplerForm, one for each form widget on the given page + **/ + +GList* +poppler_page_get_form_field (PopplerPage *page) +{ + GList *field_list = NULL; + Form *form; + gint i; + Object obj; + + g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); + + form = new Form(page->page->getAnnots (&obj)); + + obj.free (); + if(form == NULL) + return NULL; + + printf("form->getNumFields : %i\n",form->getNumFields()); + + for(i = 0; i < form->getNumFields(); i++) { + PopplerFormField *poppler_field; + FormField *field; + field = form->getField(i); + + poppler_field = g_new(PopplerFormField, 1); + field->getRect (&(poppler_field->area.x1), &(poppler_field->area.y1), + &(poppler_field->area.x2), &(poppler_field->area.y2)); + +/* poppler_field->area.x1 -= page->page->getCropBox()->x1; + poppler_field->area.x2 -= page->page->getCropBox()->x1; + poppler_field->area.y1 -= page->page->getCropBox()->y1; + poppler_field->area.y2 -= page->page->getCropBox()->y1;*/ + + field_list = g_list_prepend(field_list,poppler_field); + } + return field_list; + +} + diff -urN poppler/glib/poppler-page.h poppler_s/glib/poppler-page.h --- poppler/glib/poppler-page.h 2006-04-12 04:07:07.000000000 +0200 +++ poppler_s/glib/poppler-page.h 2006-04-25 22:43:01.000000000 +0200 @@ -80,6 +80,7 @@ PopplerRectangle *old_selection, GdkColor *glyph_color, GdkColor *background_color); +GList *poppler_page_get_form_field (PopplerPage *page); /* A rectangle on a page, with coordinates in PDF points. */ @@ -112,6 +113,18 @@ PopplerLinkMapping *poppler_link_mapping_copy (PopplerLinkMapping *mapping); void poppler_link_mapping_free (PopplerLinkMapping *mapping); +/* FormField */ +#define POPPLER_TYPE_FORM_FIELD (poppler_form_field_get_type ()) +struct _PopplerFormField +{ + PopplerRectangle area; +}; + +GType poppler_form_field_get_type (void) G_GNUC_CONST; +PopplerFormField *poppler_form_field_new (void); +PopplerFormField *poppler_form_field_copy (PopplerFormField *field); +void poppler_form_field_free (PopplerFormField *field); + G_END_DECLS #endif /* __POPPLER_PAGE_H__ */ diff -urN poppler/glib/poppler-private.h poppler_s/glib/poppler-private.h --- poppler/glib/poppler-private.h 2006-04-17 00:59:44.000000000 +0200 +++ poppler_s/glib/poppler-private.h 2006-04-25 22:43:01.000000000 +0200 @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff -urN poppler/glib/test-poppler-glib.c poppler_s/glib/test-poppler-glib.c --- poppler/glib/test-poppler-glib.c 2006-02-28 19:25:00.000000000 +0100 +++ poppler_s/glib/test-poppler-glib.c 2006-04-25 22:43:01.000000000 +0200 @@ -224,6 +224,17 @@ else g_print ("no attachment\n"); + /* forms */ + { + GList *lst,*k; + lst = poppler_page_get_form_field(page); + for (k = lst; k != NULL; k = k->next) { + PopplerFormField *field = k->data; + printf("field : x1=%f y1=%f x2=%f y2=%f\n", field->area.x1, field->area.y1, field->area.x2, field->area.y2); + } + g_list_free(lst); + } + g_object_unref (G_OBJECT (page)); g_object_unref (G_OBJECT (document)); diff -urN poppler/poppler/Form.cc poppler_s/poppler/Form.cc --- poppler/poppler/Form.cc 1970-01-01 01:00:00.000000000 +0100 +++ poppler_s/poppler/Form.cc 2006-04-25 22:43:07.000000000 +0200 @@ -0,0 +1,163 @@ +//======================================================================== +// +// Form.cc +// +// Copyright 1996-2003 Glyph & Cog, LLC +// Copyright 2006 Julien Rebetez +// +//======================================================================== + +#include + +#ifdef USE_GCC_PRAGMAS +#pragma implementation +#endif + +#include +#include +#include "goo/gmem.h" +#include "goo/GooString.h" +#include "Error.h" +#include "Object.h" +#include "Array.h" +#include "Dict.h" +#include "Form.h" +#include "UGooString.h" + + +//======================================================================== +// FormField +//======================================================================== + +FormField::FormField(Dict *dict) { + Object obj1, obj2, obj3i; + double t; + + ok = gFalse; + // get rectangle + if (!dict->lookup("Rect", &obj1)->isArray()) { + error(-1, "Annotation rectangle is wrong type"); + goto err2; + } + if (!obj1.arrayGet(0, &obj2)->isNum()) { + error(-1, "Bad annotation rectangle"); + goto err1; + } + x1 = obj2.getNum(); + obj2.free(); + if (!obj1.arrayGet(1, &obj2)->isNum()) { + error(-1, "Bad annotation rectangle"); + goto err1; + } + y1 = obj2.getNum(); + obj2.free(); + if (!obj1.arrayGet(2, &obj2)->isNum()) { + error(-1, "Bad annotation rectangle"); + goto err1; + } + x2 = obj2.getNum(); + obj2.free(); + if (!obj1.arrayGet(3, &obj2)->isNum()) { + error(-1, "Bad annotation rectangle"); + goto err1; + } + y2 = obj2.getNum(); + obj2.free(); + obj1.free(); + //swap coords if needed + if (x1 > x2) { + t = x1; + x1 = x2; + x2 = t; + } + if (y1 > y2) { + t = y1; + y1 = y2; + y2 = t; + } + + //TODO: lookup for type + type = fieldButton; + + ok = gTrue; + + err1: + obj2.free(); + err2: + obj1.free(); +} + +FormField::FormField(FormField *dest) +{ + x1 = dest->x1; + y1 = dest->y1; + x2 = dest->x2; + y2 = dest->x2; + + ok = dest->ok; + + type = dest->type; +} +//------------------------------------------------------------------------ +// Form +//------------------------------------------------------------------------ + +Form::Form(Object* annots) +{ + FormField* field; + Object obj1, obj2; + int size; + int i; + + fields = NULL; + size = 0; + numFields = 0; + + if (annots->isArray()) { + for (i = 0; i < annots->arrayGetLength(); ++i) { + if (annots->arrayGet(i, &obj1)->isDict()) { + if (obj1.dictLookup("Subtype", &obj2)->isName("Widget")) { + field = new FormField(obj1.getDict()); + if (field->isOk()) { + if (numFields >= size) { + size += 16; + fields = (FormField**)greallocn(fields,size,sizeof(FormField*)); + } + fields[numFields++] = field; + } else { + delete field; + } + } + obj2.free(); + } + obj1.free(); + } + } +} + +Form::~Form() { + int i; + for(i = 0; i< numFields; ++i) + delete fields[i]; + gfree(fields); +} + +FormField *Form::find(double x, double y) const { + int i; + for (i = numFields -1; i>= 0; --i) { + if (fields[i]->inRect(x, y)) { + return fields[i]; + } + } + return NULL; +} + +GBool Form::onField(double x, double y) const { + int i; + for (i =0; iinRect(x,y)) + return gTrue; + } + return gFalse; +} + diff -urN poppler/poppler/Form.h poppler_s/poppler/Form.h --- poppler/poppler/Form.h 1970-01-01 01:00:00.000000000 +0100 +++ poppler_s/poppler/Form.h 2006-04-25 22:43:07.000000000 +0200 @@ -0,0 +1,106 @@ +//======================================================================== +// +// Form.h +// +// Copyright 2006 Julien Rebetez +// Copyright 1996-2003 Glyph & Cog, LLC +// +//======================================================================== + +#ifndef FORM_H +#define FORM_H + +#ifdef USE_GCC_PRAGMAS +#pragma interface +#endif + +#include "Object.h" + +class GooString; +class UGooString; +class Array; +class Dict; + + +//------------------------------------------------------------------------ +// FormFieldType +//------------------------------------------------------------------------ + +enum FormFieldType { + fieldButton, + fieldText, + fieldChoice, + fieldSignature +}; + +class FormField { +public: + // Build a FormField from the dict + FormField(Dict *dict); + + // Copy a FormField + FormField *copy() { return new FormField(this); } + + // Was the FormField created successfully ? + GBool isOk() { return ok; } + + // Check if point is inside the field rectangle + GBool inRect(double x, double y) + { return x1 <= x && x <= x2 && y1 <= y && y <= y2; } + + // Get the field rectangle + void getRect(double *xa1, double *ya1, double *xa2, double *ya2) + { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; } + + // Accessors. + FormFieldType getType() { return type; } +private: + + FormFieldType type; // field type + GBool ok; // set if created successfully + + FormField(FormField *dest); + + double x1, y1; // lower left corner + double x2, y2; // upper right corner +}; + + +//------------------------------------------------------------------------ +// FieldButton +//------------------------------------------------------------------------ + +/*class FormFieldButton: public FormField { +public: + // Build a fieldButton from flags + FormFieldButton(Object *flagObj); + + // Destructor + virtual ~FormFieldButton(); +};*/ + +class Form { +public: + // Extract form from array of annotations + Form(Object* annots); + + // Destructor + ~Form(); + + // Iterate through list of fields. + int getNumFields() const { return numFields; } + FormField* getField(int i) const { return fields[i]; } + + // If point , is in a field, return the associated field; + // else return NULL + FormField *find(double x, double y) const; + + // Return true if , is in a field. + GBool onField(double x, double y) const; + +private: + FormField** fields; + int numFields; +}; +#endif + diff -urN poppler/poppler/Makefile.am poppler_s/poppler/Makefile.am --- poppler/poppler/Makefile.am 2006-04-08 12:44:43.000000000 +0200 +++ poppler_s/poppler/Makefile.am 2006-04-25 22:43:01.000000000 +0200 @@ -110,6 +110,7 @@ Error.h \ FontEncodingTables.h \ FontInfo.h \ + Form.h \ Function.cc \ Function.h \ Gfx.h \ @@ -169,6 +170,7 @@ Error.cc \ FontEncodingTables.cc \ FontInfo.cc \ + Form.cc \ Function.cc \ Gfx.cc \ GfxFont.cc \