diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index a96d89e..21a1e59 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -1348,3 +1348,128 @@ poppler_ps_file_free (PopplerPSFile *ps_ g_return_if_fail (ps_file != NULL); g_object_unref (ps_file); } + + +//NeedAppearances needs to be set to 'true' in the AcroForm entry of the Catalog to enable dynamic appearance generation +void +check_for_need_appearances (PopplerDocument *document) +{ + //FIXME: static var are bad in shared libs + static GBool appearanceSet = gFalse; + if(!appearanceSet) { + XRef* xref = document->doc->getXRef(); + Object* catalog = new Object(); + Object acroForm; + Ref catRef; + catRef.gen = xref->getRootGen(); + catRef.num = xref->getRootNum(); + catalog = xref->getCatalog(catalog); + catalog->dictLookup("AcroForm", &acroForm); + Object obj1; + obj1.initBool(true); + acroForm.dictSet("NeedAppearances", &obj1); + obj1.free(); + catalog->dictSet("AcroForm", &acroForm); + document->doc->getXRef()->setModifiedObject(catalog, catRef); + appearanceSet = gTrue; + } +} + +void decode_id (int id, int *pageNum, int *fieldNum) +{ + (*pageNum) = id >> 16; + (*fieldNum) = (id << 16) >> 16; +} + +void +poppler_document_set_form_field_button_state (PopplerDocument *document, int id, int index, gboolean state) +{ + int pageNum, fieldNum; + decode_id(id, &pageNum, &fieldNum); + Catalog *catalog = document->doc->getCatalog(); + FormField *tmp = catalog->getPage(pageNum)->getForm()->getField(fieldNum); + FormFieldButton *field = NULL; + if (tmp->getType() != fieldButton) { + g_warning("poppler_document_set_form_field_button_state, invalid field type: %i\n", tmp->getType()); + return; + } + field = static_cast(tmp); + if (field) { + field->setKidState(index, (GBool)state); + //FIXME: should be moved to Form + check_for_need_appearances(document); + } +} + +void +poppler_document_set_form_field_text_content (PopplerDocument *document, int id, char *content) +{ + int pageNum, fieldNum; + decode_id(id, &pageNum, &fieldNum); + + Catalog *catalog = document->doc->getCatalog(); + FormField *tmp = catalog->getPage(pageNum)->getForm()->getField(fieldNum); + FormFieldText *field = NULL; + if (tmp->getType() != fieldText) { + g_warning("poppler_document_set_form_field_text_content, invalid field type: %i\n", tmp->getType()); + return ; + } + field = static_cast(tmp); + if (field) { + field->setContentCopy(content); + //FIXME: should be moved to Form + check_for_need_appearances(document); + } +} + +gchar * +poppler_document_get_form_field_text_content (PopplerDocument *document, int id) +{ + PopplerFormField *field = poppler_document_find_form_field_by_id(document, id); + if (field && field->type == POPPLER_FORM_FIELD_TEXT) + return field->text.content; + else { + g_warning("poppler_document_get_form_field_text_content, unknown id: %i", id); + return NULL; + } +} + +PopplerFormField * +poppler_document_find_form_field_by_id (PopplerDocument *document, int id) +{ + Catalog *catalog = document->doc->getCatalog(); + //decode id + int pageNum = id >> 16; + int fieldNum = (id << 16) >> 16; + FormField *field = catalog->getPage(pageNum)->getForm()->getField(fieldNum); + if (field != NULL) { + PopplerFormField *poppler_field = _form_field_new_from_field (field); + return poppler_field; + } else + return NULL; +} + +PopplerFormField * +poppler_document_get_form_field_button_kid (PopplerDocument *document, int id, int index) +{ + Catalog *catalog = document->doc->getCatalog(); + int pageNum = id >> 16; + int fieldNum = (id << 16) >> 16; + FormField *field = catalog->getPage(pageNum)->getForm()->getField(fieldNum); + if (field && field->getType() == fieldButton) { + FormFieldButton *btn = static_cast(field); + ButtonKid *kid = btn->getKid(index); + if (kid != NULL) { + PopplerFormField *poppler_field; + poppler_field = g_new(PopplerFormField, 1); + poppler_field->area.x1 = kid->x1; + poppler_field->area.y1 = kid->y1; + poppler_field->area.x2 = kid->x2; + poppler_field->area.y2 = kid->y2; + poppler_field->id = btn->getID(); + poppler_field->type = (PopplerFormFieldType)btn->getButtonType(); + return poppler_field; + } + } + return NULL; +} diff --git a/glib/poppler-document.h b/glib/poppler-document.h index d0b1591..1d9c7f6 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -108,6 +108,23 @@ GList *poppler_document_get_at PopplerDest *poppler_document_find_dest (PopplerDocument *document, const gchar *link_name); +/* Form */ +void poppler_document_set_form_field_text_content (PopplerDocument *document, + int id, + char *content); +PopplerFormField *poppler_document_find_form_field_by_id (PopplerDocument *document, + int id); +void poppler_document_set_form_field_button_state (PopplerDocument *document, int id, int index, gboolean state); + +gchar * +poppler_document_get_form_field_text_content (PopplerDocument *document, int id); + +PopplerFormField *poppler_document_get_form_field_button_kid (PopplerDocument *document, int id, int index); + + + + + /* Interface for getting the Index of a poppler_document */ #define POPPLER_TYPE_INDEX_ITER (poppler_index_iter_get_type ()) GType poppler_index_iter_get_type (void) G_GNUC_CONST; diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index e2ef975..d48ce05 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -985,3 +985,119 @@ poppler_link_mapping_free (PopplerLinkMa 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); +} + +PopplerFormField * +_form_field_new_from_field (FormField* field) +{ + PopplerFormField *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->type = (PopplerFormFieldType)field->getType(); + poppler_field->id = field->getID(); + if (poppler_field->type == POPPLER_FORM_FIELD_TEXT) + poppler_field->text.content = static_cast(field)->getContentCopy(); + if (poppler_field->type == POPPLER_FORM_FIELD_BUTTON) + poppler_field->button.num_kids = static_cast(field)->getNumKids(); + return poppler_field; +} + +/** + * poppler_page_get_form_fields + **/ + +GList* +poppler_page_get_form_fields (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)); + form = page->page->getForm(); + + obj.free (); + if(form == NULL) + return NULL; + + + for(i = 0; i < form->getNumFields(); i++) { + PopplerFormField *poppler_field /*= poppler_document_get_form_field_by_id(page->document,form->getField(i)->getID())*/; + FormField *field; + field = form->getField(i); + poppler_field = _form_field_new_from_field (field); + + /*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->type = (PopplerFormFieldType)field->getType(); + poppler_field->id = field->getID(); + if (poppler_field->type == POPPLER_FORM_FIELD_TEXT) + poppler_field->text.content = static_cast(field)->getContentCopy(); + if (poppler_field->type == POPPLER_FORM_FIELD_BUTTON) + poppler_field->button.num_kids = static_cast(field)->getNumKids();*/ + field_list = g_list_prepend(field_list,poppler_field); + } + return field_list; + +} + +void +poppler_page_free_form_fields (GList *list) +{ + if (list == NULL) + return; + + g_list_foreach (list, (GFunc) (poppler_form_field_free), NULL); + g_list_free (list); + +} + +void +poppler_page_get_crop_box (PopplerPage *page, PopplerRectangle *rect) +{ + PDFRectangle* cropBox = page->page->getCropBox(); + rect->x1 = cropBox->x1; + rect->x2 = cropBox->x2; + rect->y1 = cropBox->y1; + rect->y2 = cropBox->y2; +} + diff --git a/glib/poppler-page.h b/glib/poppler-page.h index c613bf4..345ef69 100644 --- a/glib/poppler-page.h +++ b/glib/poppler-page.h @@ -80,6 +80,11 @@ void poppler_page_render_ PopplerRectangle *old_selection, GdkColor *glyph_color, GdkColor *background_color); +GList *poppler_page_get_form_fields (PopplerPage *page); +void poppler_page_free_form_fields (GList *list); + +void poppler_page_get_crop_box (PopplerPage *page, + PopplerRectangle *rect); /* A rectangle on a page, with coordinates in PDF points. */ @@ -112,6 +117,59 @@ PopplerLinkMapping *poppler_link_mapping 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 _PopplerTextField +{ + //flags + char multitine:1; + char password:1; + char fileselect:1; + char do_not_spell_check:1; + char do_not_scroll:1; + char comb:1; + char rich_text:1; + //content + gchar *content; +}; + +struct _PopplerButtonField +{ + char no_toggle_to_of:1; + char radio:1; + char pushbutton:1; + char radios_in_unison:1; + int num_kids; +}; + +struct _PopplerChoiceField +{ + char combo:1; + char edit:1; + char sort:1; + char multi_select:1; + char do_not_spell_check:1; + char commit_on_sel_change:1; +}; + +struct _PopplerFormField +{ + PopplerRectangle area; + PopplerFormFieldType type; + int id; + union { + PopplerTextField text; + PopplerButtonField button; + PopplerChoiceField choice; + }; + +}; + +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 --git a/glib/poppler-private.h b/glib/poppler-private.h index b39de2b..6f6e2f2 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,9 @@ struct _PopplerPage Gfx *gfx; }; +PopplerFormField *_form_field_new_from_field (FormField* field); + + PopplerPage *_poppler_page_new (PopplerDocument *document, Page *page, int index); diff --git a/glib/poppler.cc b/glib/poppler.cc diff --git a/glib/poppler.h b/glib/poppler.h index 78074e4..7ed640f 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -42,17 +42,34 @@ typedef enum POPPLER_ORIENTATION_SEASCAPE } PopplerOrientation; +/* MUST be the same than poppler/Form.h fieldType */ +typedef enum +{ + POPPLER_FORM_FIELD_BUTTON, + POPPLER_FORM_FIELD_TEXT, + POPPLER_FORM_FIELD_CHOICE, + POPPLER_FORM_FIELD_SIGNATURE, + //kid type + POPPLER_FORM_FIELD_BUTTON_CHECK, + POPPLER_FORM_FIELD_BUTTON_PUSH, + POPPLER_FORM_FIELD_BUTTON_RADIO +} PopplerFormFieldType; + + 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; typedef union _PopplerAction PopplerAction; typedef struct _PopplerDest PopplerDest; - +typedef struct _PopplerTextField PopplerTextField; +typedef struct _PopplerButtonField PopplerButtonField; +typedef struct _PopplerChoiceField PopplerChoiceField; typedef enum { diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 2e39f3a..83be3c7 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -27,13 +27,12 @@ Annot::Annot(XRef *xrefA, Dict *acroForm, Dict *dict) { Object apObj, asObj, obj1, obj2; - GBool regen, isTextField; double t; ok = gFalse; xref = xrefA; appearBuf = NULL; - + if (dict->lookup("Rect", &obj1)->isArray() && obj1.arrayGetLength() == 4) { //~ should check object types here @@ -71,43 +70,44 @@ Annot::Annot(XRef *xrefA, Dict *acroForm } obj1.free(); } + regen = gTrue; // check for a text-type field isTextField = dict->lookup("FT", &obj1)->isName("Tx"); obj1.free(); -#if 0 //~ appearance stream generation is not finished yet +#if 1 //~ appearance stream generation is not finished yet if (regen && isTextField) { generateAppearance(acroForm, dict); } else { #endif if (dict->lookup("AP", &apObj)->isDict()) { if (dict->lookup("AS", &asObj)->isName()) { - if (apObj.dictLookup("N", &obj1)->isDict()) { - if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) { - obj2.copy(&appearance); - ok = gTrue; - } else { - obj2.free(); - if (obj1.dictLookupNF("Off", &obj2)->isRef()) { - obj2.copy(&appearance); - ok = gTrue; - } - } - obj2.free(); - } - obj1.free(); + if (apObj.dictLookup("N", &obj1)->isDict()) { + if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) { + obj2.copy(&appearance); + ok = gTrue; + } else { + obj2.free(); + if (obj1.dictLookupNF("Off", &obj2)->isRef()) { + obj2.copy(&appearance); + ok = gTrue; + } + } + obj2.free(); + } + obj1.free(); } else { - if (apObj.dictLookupNF("N", &obj1)->isRef()) { - obj1.copy(&appearance); - ok = gTrue; - } - obj1.free(); + if (apObj.dictLookupNF("N", &obj1)->isRef()) { + obj1.copy(&appearance); + ok = gTrue; + } + obj1.free(); } asObj.free(); } apObj.free(); -#if 0 //~ appearance stream generation is not finished yet +#if 1 //~ appearance stream generation is not finished yet } #endif } @@ -119,6 +119,7 @@ Annot::~Annot() { } } + void Annot::generateAppearance(Dict *acroForm, Dict *dict) { MemStream *appearStream; Object daObj, vObj, drObj, appearDict, obj1, obj2; @@ -138,26 +139,26 @@ void Annot::generateAppearance(Dict *acr fontSize = 10; for (i1 = daStr->getLength() - 2; i1 >= 0; --i1) { if (daStr->getChar(i1) == 'T' && daStr->getChar(i1+1) == 'f') { - for (--i1; i1 >= 0 && Lexer::isSpace(daStr->getChar(i1)); --i1) ; - for (i0 = i1; i0 >= 0 && !Lexer::isSpace(daStr->getChar(i0)); --i0) ; - if (i0 >= 0) { - ++i0; - ++i1; - s = new GooString(daStr, i0, i1 - i0); - fontSize = atof(s->getCString()); - delete s; - - // autosize the font - if (fontSize == 0) { - fontSize = 0.67 * (yMax - yMin); - daStr1 = new GooString(daStr, 0, i0); - sprintf(buf, "%.2f", fontSize); - daStr1->append(buf); - daStr1->append(daStr->getCString() + i1, - daStr->getLength() - i1); - } - } - break; + for (--i1; i1 >= 0 && Lexer::isSpace(daStr->getChar(i1)); --i1) ; + for (i0 = i1; i0 >= 0 && !Lexer::isSpace(daStr->getChar(i0)); --i0) ; + if (i0 >= 0) { + ++i0; + ++i1; + s = new GooString(daStr, i0, i1 - i0); + fontSize = atof(s->getCString()); + delete s; + + // autosize the font + if (fontSize == 0) { + fontSize = 0.67 * (yMax - yMin); + daStr1 = new GooString(daStr, 0, i0); + sprintf(buf, "%.2f", fontSize); + daStr1->append(buf); + daStr1->append(daStr->getCString() + i1, + daStr->getLength() - i1); + } + } + break; } } @@ -167,44 +168,53 @@ void Annot::generateAppearance(Dict *acr appearBuf->append("q BT\n"); appearBuf->append(daStr1 ? daStr1 : daStr)->append("\n"); if (dict->lookup("V", &vObj)->isString()) { - //~ handle quadding -- this requires finding the font and using - //~ the encoding and char widths - sprintf(buf, "1 0 0 1 %.2f %.2f Tm\n", 2.0, yMax - yMin - fontSize); - appearBuf->append(buf); - sprintf(buf, "%g TL\n", fontSize); - appearBuf->append(buf); - vStr = vObj.getString(); - i0 = 0; - while (i0 < vStr->getLength()) { - for (i1 = i0; - i1 < vStr->getLength() && - vStr->getChar(i1) != '\n' && vStr->getChar(i1) != '\r'; - ++i1) ; - if (i0 > 0) { - appearBuf->append("T*\n"); - } - appearBuf->append('('); - for (; i0 < i1; ++i0) { - c = vStr->getChar(i0); - if (c == '(' || c == ')' || c == '\\') { - appearBuf->append('\\'); - appearBuf->append(c); - } else if (c < 0x20 || c >= 0x80) { - sprintf(buf, "\\%03o", c); + //~ handle quadding -- this requires finding the font and using + //~ the encoding and char widths + sprintf(buf, "1 0 0 1 %.2f %.2f Tm\n", 2.0, yMax - yMin - fontSize); appearBuf->append(buf); - } else { - appearBuf->append(c); - } - } - appearBuf->append(") Tj\n"); - if (i1 + 1 < vStr->getLength() && - vStr->getChar(i1) == '\r' && vStr->getChar(i1 + 1) == '\n') { - i0 = i1 + 2; - } else { - i0 = i1 + 1; - } - } + sprintf(buf, "%g TL\n", fontSize); + appearBuf->append(buf); + //FIXME: perhaps unicode handling could be better + UGooString tmp (*vObj.getString()); + vStr = new GooString(tmp.getCString()); + i0 = 0; + while (i0 < vStr->getLength()) { + for (i1 = i0; + i1 < vStr->getLength() && + vStr->getChar(i1) != '\n' && vStr->getChar(i1) != '\r'; + ++i1) ; + if (i0 > 0) { + appearBuf->append("T*\n"); + } + appearBuf->append('('); + for (; i0 < i1; ++i0) { + c = vStr->getChar(i0); + if (c == '(' || c == ')' || c == '\\') { + appearBuf->append('\\'); + appearBuf->append(c); + } else if (c < 0x20 || c >= 0x80) { + if (c == 0xFF || c == 0xFE) { + sprintf(buf, ""); + printf("fu\n"); + } + else + sprintf(buf, "\\%03o", c); + appearBuf->append(buf); + } else { + appearBuf->append(c); + } + } + appearBuf->append(") Tj\n"); + if (i1 + 1 < vStr->getLength() && + vStr->getChar(i1) == '\r' && vStr->getChar(i1 + 1) == '\n') { + i0 = i1 + 2; + } else { + i0 = i1 + 1; + } + } + delete vStr; } + vObj.free(); appearBuf->append("ET Q\n"); appearBuf->append("EMC\n"); @@ -225,21 +235,21 @@ void Annot::generateAppearance(Dict *acr if (!drObj.isDict()) { dict->lookup("Parent", &obj1); while (obj1.isDict()) { - drObj.free(); - obj1.dictLookup("DR", &drObj); - if (drObj.isDict()) { - break; - } - obj1.dictLookup("Parent", &obj2); - obj1.free(); - obj1 = obj2; + drObj.free(); + obj1.dictLookup("DR", &drObj); + if (drObj.isDict()) { + break; + } + obj1.dictLookup("Parent", &obj2); + obj1.free(); + obj1 = obj2; } obj1.free(); if (!drObj.isDict()) { - if (acroForm) { - drObj.free(); - acroForm->lookup("DR", &drObj); - } + if (acroForm) { + drObj.free(); + acroForm->lookup("DR", &drObj); + } } } if (drObj.isDict()) { @@ -249,7 +259,7 @@ void Annot::generateAppearance(Dict *acr // build the appearance stream appearStream = new MemStream(appearBuf->getCString(), 0, - appearBuf->getLength(), &appearDict); + appearBuf->getLength(), &appearDict); appearance.initStream(appearStream); ok = gTrue; @@ -262,7 +272,6 @@ void Annot::generateAppearance(Dict *acr void Annot::draw(Gfx *gfx) { Object obj; - if (appearance.fetch(xref, &obj)->isStream()) { gfx->doAnnot(&obj, xMin, yMin, xMax, yMax); } @@ -289,16 +298,16 @@ Annots::Annots(XRef *xref, Catalog *cata if (annotsObj->isArray()) { for (i = 0; i < annotsObj->arrayGetLength(); ++i) { if (annotsObj->arrayGet(i, &obj1)->isDict()) { - annot = new Annot(xref, acroForm, obj1.getDict()); - if (annot->isOk()) { - if (nAnnots >= size) { - size += 16; - annots = (Annot **)greallocn(annots, size, sizeof(Annot *)); - } - annots[nAnnots++] = annot; - } else { - delete annot; - } + annot = new Annot(xref, acroForm, obj1.getDict()); + if (annot->isOk()) { + if (nAnnots >= size) { + size += 16; + annots = (Annot **)greallocn(annots, size, sizeof(Annot *)); + } + annots[nAnnots++] = annot; + } else { + delete annot; + } } obj1.free(); } diff --git a/poppler/Annot.h b/poppler/Annot.h index 935066a..e29a638 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -27,23 +27,27 @@ public: Annot(XRef *xrefA, Dict *acroForm, Dict *dict); ~Annot(); GBool isOk() { return ok; } + GBool textField() { return isTextField; } void draw(Gfx *gfx); // Get appearance object. Object *getAppearance(Object *obj) { return appearance.fetch(xref, obj); } - + double getXMin() { return xMin; } + double getYMin() { return yMin; } private: void generateAppearance(Dict *acroForm, Dict *dict); - XRef *xref; // the xref table for this PDF file - Object appearance; // a reference to the Form XObject stream - // for the normal appearance + XRef *xref; // the xref table for this PDF file + Object appearance; // a reference to the Form XObject stream + // for the normal appearance GooString *appearBuf; - double xMin, yMin, // annotation rectangle + double xMin, yMin, // annotation rectangle xMax, yMax; GBool ok; + + GBool regen, isTextField; }; //------------------------------------------------------------------------ diff --git a/poppler/Form.cc b/poppler/Form.cc new file mode 100644 index 0000000..a95e668 --- /dev/null +++ b/poppler/Form.cc @@ -0,0 +1,392 @@ +//======================================================================== +// +// 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" +#include "XRef.h" + + +//======================================================================== +// FormField +//======================================================================== + +FormField::FormField(XRef* xrefA, Object *aobj, unsigned id, Ref aref) { + Object obj1, obj2, obj3i; + double t; + ref = aref; + ID = id; + ok = gFalse; + xref = xrefA; + aobj->copy(&obj); + Dict *dict = obj.getDict(); + + // 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; + } + + + + 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; +} + +FormField::~FormField() +{ + obj.free(); +} + +//------------------------------------------------------------------------ +// FormFieldButton +//------------------------------------------------------------------------ +FormFieldButton::FormFieldButton(XRef *xrefA, Object *aobj, unsigned id, Ref ref) : FormField(xrefA, aobj, id, ref) +{ + type = fieldButton; + Object obj1; + Dict *dict = aobj->getDict(); + + btype = fieldButtonCheck; //check box by default + if (dict->lookup("Ff", &obj1)->isInt()) { + int flags = obj1.getInt(); + if (flags & 0x10000) { //push button + btype = fieldButtonPush; + } else if (flags & 0x8000) {//radio button + btype = fieldButtonRadio; + } + } + obj1.free(); + if (dict->lookup("Kids", &obj1)->isArray()) { //we have a field of buttons + size = obj1.getArray()->getLength(); + kids = new ButtonKid[size]; + if (btype == fieldButtonPush) { + printf("%i kids of type Push Button\n", obj1.getArray()->getLength()); + } else if (btype == fieldButtonRadio) { + printf("%i kids of type Radio Button\n", obj1.getArray()->getLength()); + } + } else { //single button + printf("single button\n"); + size = 1; + kids = new ButtonKid[size]; + this->getRect(&kids[0].x1, &kids[0].y1, &kids[0].x2, &kids[0].y2); + aobj->copy(&kids[0].obj); + kids[0].ref = ref; + } + obj1.free(); + + if (dict->lookup("Opt", &obj1)->isArray()) { + printf("Opt entry found\n"); + } + obj1.free(); + + //dump AP dict + //TODO:Browse the AP dictionnary to find the name of the state(/Yes, /No) + if (dict->lookup("AP", &obj1)->isDict()) { + Dict *dict = obj1.getDict(); + int length = dict->getLength(); + printf("AP length: %i\n", length); + for(int i=0; igetKey(i)->getCString()); + dict->getValNF(i, &obj2); + if(obj2.isDict()) { + Dict *dict2 = obj2.getDict(); + int l2 = dict2->getLength(); + for(int j=0; jgetValNF(j, &obj3); + printf("\t\t/%s", dict2->getKey(j)->getCString()); + printf(" %i %i\n", obj3.getRef().num, obj3.getRef().gen); + obj3.free(); + } + } + obj2.free(); + } + } + obj1.free(); +} + +void FormFieldButton::setKidState (int index, GBool state) +{ + if(index < 0 || index > size) { + error(-1, "FormFieldButton::setKidState, out of bound index"); + return; + } + ButtonKid *kid = &kids[index]; + char* value; + if(state) value = "Yes"; + else value = "No"; + + Object *obj1 = new Object(); + obj1->initName(value); + printf("setKidState on %i, state %s", index, value); + kid->obj.getDict()->set("V", obj1); + obj1 = new Object(); + obj1->initName(value); + //modify the Appearance State entry as well + kid->obj.getDict()->set("AS", obj1); + + //notify the xref about the update + xref->setModifiedObject(&kid->obj, kid->ref); +} + +ButtonKid* FormFieldButton::getKid (int index) +{ + if (index < 0 || index >= size) + return NULL; + return &kids[index]; +} + +FormFieldButton::~FormFieldButton() +{ + delete [] kids; +} + +//------------------------------------------------------------------------ +// FormFieldText +//------------------------------------------------------------------------ +FormFieldText::FormFieldText(XRef *xrefA, Object *aobj, unsigned id, Ref ref) : FormField(xrefA, aobj, id, ref) +{ + type = fieldText; + content = NULL; + Dict *dict = aobj->getDict(); + Object obj1; + + if (dict->lookup("V", &obj1)->isString()) { + if(obj1.getString()->getLength() == 2 && obj1.getString()->hasUnicodeMarker()) { + printf("Form.cc:44, skipped empty unicode string\n"); + UGooString c(*obj1.getString()); + printf("ugoo: %s\n", c.getCString()); + content = c.getCString(); + } else { + printf("Form.cc:46, V : %s\n", obj1.getString()->getCString()); + content = strdup(obj1.getString()->getCString()); + } + } + obj1.free(); + +} + +FormFieldText::~FormFieldText() +{ + +} + +void FormFieldText::setContentCopy(char* new_content) +{ + Object obj1; + + if(content) + delete [] content; + + if (new_content == NULL) + content = NULL; + else { + content = strdup(new_content); + + GooString *cont = new GooString(content); + Object *obj1 = new Object(); + obj1->initString(cont); + //printf("%s, %s, %s\n", content, cont->getCString(), obj1->getString()); + obj.getDict()->set("V", obj1); + //notify the xref about the update + xref->setModifiedObject(&obj, ref); + } +} + + +//------------------------------------------------------------------------ +// FormFieldChoice +//------------------------------------------------------------------------ +FormFieldChoice::FormFieldChoice(XRef *xrefA, Object *dict, unsigned id, Ref ref) : FormField(xrefA, dict, id, ref) +{ + type = fieldChoice; +} + +FormFieldChoice::~FormFieldChoice() +{ + +} + +//------------------------------------------------------------------------ +// FormFieldSignature +//------------------------------------------------------------------------ +FormFieldSignature::FormFieldSignature(XRef *xrefA, Object *dict, unsigned id, Ref ref): FormField(xrefA, dict, id, ref) +{ + type = fieldSignature; +} + +FormFieldSignature::~FormFieldSignature() +{ + +} + +//------------------------------------------------------------------------ +// Form +//------------------------------------------------------------------------ + +Form::Form(XRef *xrefA, Object* annots, unsigned page) +{ + FormField* field; + Object obj1, obj2; + int size; + int i; + unsigned count = 0; + + fields = NULL; + size = 0; + numFields = 0; + pageNum = page; + + if (annots->isArray()) { + for (i = 0; i < annots->arrayGetLength(); ++i) { + if (annots->arrayGet(i, &obj1)->isDict()) { + if (obj1.dictLookup("Subtype", &obj2)->isName("Widget")) { + unsigned id = ((unsigned)pageNum << 16) + count; + obj2.free(); + annots->arrayGetNF(i, &obj2); //store the indirect ref for further update + Ref objRef = obj2.getRef(); + obj2.free(); + //printf("num: %i\t gen:%i\n", objRef.num, objRef.gen); + if(obj1.dictLookup("FT", &obj2)->isName("Btn")) { + field = new FormFieldButton(xrefA, &obj1,id,objRef); + count++; + } else if (obj2.isName("Tx")) { + field = new FormFieldText(xrefA, &obj1,id,objRef); + count++; + } else if (obj2.isName("Ch")) { + field = new FormFieldChoice(xrefA, &obj1,id,objRef); + count++; + } else if (obj2.isName("Sig")) { + field = new FormFieldSignature(xrefA, &obj1,id,objRef); + count++; + } else { + goto err1; + } + if (field->isOk()) { + if (numFields >= size) { + size += 16; + fields = (FormField**)greallocn(fields,size,sizeof(FormField*)); + } + fields[numFields++] = field; + } else { + delete field; + } + + } +err1: + 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; +} + +FormField* Form::getFieldById (unsigned int id) const { + int i; + for (i=0; igetID() == id) { + 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 --git a/poppler/Form.h b/poppler/Form.h new file mode 100644 index 0000000..9e68c57 --- /dev/null +++ b/poppler/Form.h @@ -0,0 +1,189 @@ +//======================================================================== +// +// 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, + //kid type + fieldButtonCheck, + fieldButtonPush, + fieldButtonRadio +}; + +class FormField { +public: + virtual ~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; } + unsigned getID () { return ID; } + Object* getObj() { return &obj; } + Ref getRef() { return ref; } + +protected: + // Build a FormField from the dict, only callable from child-classes + FormField(XRef* xrefa, Object *aobj, unsigned id, Ref aref); + FormFieldType type; // field type + GBool ok; // set if created successfully + Ref ref; + Object obj; + XRef *xref; + + + +private: + FormField() {} + FormField(FormField *dest); + /* + Field ID is a 32bits integer, calculated as follow : + the first 16 bits are the field number, relative to the page + the last 16 bits are the page number + [page number | field number] + (encoding) id = (pageNum << 16) + fieldNum; + (decoding) pageNum = id >> 16; fieldNum = (id << 16) >> 16; + */ + unsigned ID; + + double x1, y1; // lower left corner + double x2, y2; // upper right corner +}; + + +//------------------------------------------------------------------------ +// FormFieldButton +//------------------------------------------------------------------------ + +struct ButtonKid +{ + double x1, y1, x2, y2; + Object obj; + Ref ref; +}; + +class FormFieldButton: public FormField { +public: + FormFieldButton(XRef *xrefA, Object *dict, unsigned id, Ref ref); + + int getNumKids() { return size; } + ButtonKid* getKid(int index); + FormFieldType getButtonType () { return btype; } + + void setKidState(int index, GBool state); + + virtual ~FormFieldButton(); +protected: + FormFieldType btype; + int size; + ButtonKid *kids; +}; + +//------------------------------------------------------------------------ +// FormFieldText +//------------------------------------------------------------------------ + +class FormFieldText: public FormField { +public: + FormFieldText(XRef *xrefA, Object *dict, unsigned id, Ref ref); + + char* getContent() { return content; } + char* getContentCopy() { if (content == NULL) return NULL; + else return strdup(content); } + void setContentCopy(char* new_content); + + virtual ~FormFieldText(); +protected: + char* content; +}; + +//------------------------------------------------------------------------ +// FormFieldChoice +//------------------------------------------------------------------------ + +class FormFieldChoice: public FormField { +public: + FormFieldChoice(XRef *xrefA, Object *dict, unsigned id, Ref ref); + + virtual ~FormFieldChoice(); +}; + +//------------------------------------------------------------------------ +// FormFieldSignature +//------------------------------------------------------------------------ + +class FormFieldSignature: public FormField { +public: + FormFieldSignature(XRef *xrefA, Object *dict, unsigned id, Ref ref); + + virtual ~FormFieldSignature(); +}; + +//------------------------------------------------------------------------ +// Form +//------------------------------------------------------------------------ + +class Form { +public: + // Extract form from array of annotations + Form(XRef *xrefA, Object* annots, unsigned page); + + ~Form(); + + // Iterate through list of fields. + int getNumFields() const { return numFields; } + FormField* getField(int i) const { return fields[i]; } + FormField* getFieldById (unsigned int id) const; + + // 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; + unsigned pageNum; +}; +#endif + diff --git a/poppler/Makefile.am b/poppler/Makefile.am index 2592853..0b0f2fb 100644 --- a/poppler/Makefile.am +++ b/poppler/Makefile.am @@ -112,6 +112,7 @@ poppler_include_HEADERS = \ Error.h \ FontEncodingTables.h \ FontInfo.h \ + Form.h \ Function.cc \ Function.h \ Gfx.h \ @@ -174,6 +175,7 @@ libpoppler_la_SOURCES = \ Error.cc \ FontEncodingTables.cc \ FontInfo.cc \ + Form.cc \ Function.cc \ Gfx.cc \ GfxFont.cc \ diff --git a/poppler/Page.cc b/poppler/Page.cc index 8cc7a69..ea8bed2 100644 --- a/poppler/Page.cc +++ b/poppler/Page.cc @@ -26,6 +26,7 @@ #include "GfxState.h" #include "Annot.h" #include "TextOutputDev.h" +#include "Form.h" #endif #include "Error.h" #include "Page.h" @@ -170,10 +171,10 @@ GBool PageAttrs::readBox(Dict *dict, cha obj2.free(); if (ok) { if (tmp.x1 > tmp.x2) { - t = tmp.x1; tmp.x1 = tmp.x2; tmp.x2 = t; + t = tmp.x1; tmp.x1 = tmp.x2; tmp.x2 = t; } if (tmp.y1 > tmp.y2) { - t = tmp.y1; tmp.y1 = tmp.y2; tmp.y2 = t; + t = tmp.y1; tmp.y1 = tmp.y2; tmp.y2 = t; } *box = tmp; } @@ -189,6 +190,7 @@ GBool PageAttrs::readBox(Dict *dict, cha //------------------------------------------------------------------------ Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA) { + Object obj; ok = gTrue; xref = xrefA; num = numA; @@ -200,7 +202,7 @@ Page::Page(XRef *xrefA, int numA, Dict * pageDict->lookupNF("Trans", &trans); if (!(trans.isDict() || trans.isNull())) { error(-1, "Page transition object (page %d) is wrong type (%s)", - num, trans.getTypeName()); + num, trans.getTypeName()); trans.free(); } @@ -208,17 +210,21 @@ Page::Page(XRef *xrefA, int numA, Dict * pageDict->lookupNF("Annots", &annots); if (!(annots.isRef() || annots.isArray() || annots.isNull())) { error(-1, "Page annotations object (page %d) is wrong type (%s)", - num, annots.getTypeName()); + num, annots.getTypeName()); annots.free(); goto err2; } + // forms + form = new Form(xrefA, this->getAnnots(&obj),num); + obj.free(); + // contents pageDict->lookupNF("Contents", &contents); if (!(contents.isRef() || contents.isArray() || - contents.isNull())) { + contents.isNull())) { error(-1, "Page contents object (page %d) is wrong type (%s)", - num, contents.getTypeName()); + num, contents.getTypeName()); contents.free(); goto err1; } @@ -249,25 +255,25 @@ Page::~Page() { } void Page::display(OutputDev *out, double hDPI, double vDPI, - int rotate, GBool useMediaBox, GBool crop, - Links *links, Catalog *catalog, - GBool (*abortCheckCbk)(void *data), - void *abortCheckCbkData, + int rotate, GBool useMediaBox, GBool crop, + Links *links, Catalog *catalog, + GBool (*abortCheckCbk)(void *data), + void *abortCheckCbkData, GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data), void *annotDisplayDecideCbkData) { displaySlice(out, hDPI, vDPI, rotate, useMediaBox, crop, -1, -1, -1, -1, links, catalog, - abortCheckCbk, abortCheckCbkData, + abortCheckCbk, abortCheckCbkData, annotDisplayDecideCbk, annotDisplayDecideCbkData); } Gfx *Page::createGfx(OutputDev *out, double hDPI, double vDPI, - int rotate, GBool useMediaBox, GBool crop, - int sliceX, int sliceY, int sliceW, int sliceH, - Links *links, Catalog *catalog, - GBool (*abortCheckCbk)(void *data), - void *abortCheckCbkData, - GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data), - void *annotDisplayDecideCbkData) { + int rotate, GBool useMediaBox, GBool crop, + int sliceX, int sliceY, int sliceW, int sliceH, + Links *links, Catalog *catalog, + GBool (*abortCheckCbk)(void *data), + void *abortCheckCbkData, + GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data), + void *annotDisplayDecideCbkData) { PDFRectangle *mediaBox, *cropBox, *baseBox; PDFRectangle box; Gfx *gfx; @@ -288,11 +294,11 @@ Gfx *Page::createGfx(OutputDev *out, dou ky = 72.0 / vDPI; if (rotate == 90) { if (out->upsideDown()) { - box.x1 = baseBox->x1 + ky * sliceY; - box.x2 = baseBox->x1 + ky * (sliceY + sliceH); + box.x1 = baseBox->x1 + ky * sliceY; + box.x2 = baseBox->x1 + ky * (sliceY + sliceH); } else { - box.x1 = baseBox->x2 - ky * (sliceY + sliceH); - box.x2 = baseBox->x2 - ky * sliceY; + box.x1 = baseBox->x2 - ky * (sliceY + sliceH); + box.x2 = baseBox->x2 - ky * sliceY; } box.y1 = baseBox->y1 + kx * sliceX; box.y2 = baseBox->y1 + kx * (sliceX + sliceW); @@ -300,19 +306,19 @@ Gfx *Page::createGfx(OutputDev *out, dou box.x1 = baseBox->x2 - kx * (sliceX + sliceW); box.x2 = baseBox->x2 - kx * sliceX; if (out->upsideDown()) { - box.y1 = baseBox->y1 + ky * sliceY; - box.y2 = baseBox->y1 + ky * (sliceY + sliceH); + box.y1 = baseBox->y1 + ky * sliceY; + box.y2 = baseBox->y1 + ky * (sliceY + sliceH); } else { - box.y1 = baseBox->y2 - ky * (sliceY + sliceH); - box.y2 = baseBox->y2 - ky * sliceY; + box.y1 = baseBox->y2 - ky * (sliceY + sliceH); + box.y2 = baseBox->y2 - ky * sliceY; } } else if (rotate == 270) { if (out->upsideDown()) { - box.x1 = baseBox->x2 - ky * (sliceY + sliceH); - box.x2 = baseBox->x2 - ky * sliceY; + box.x1 = baseBox->x2 - ky * (sliceY + sliceH); + box.x2 = baseBox->x2 - ky * sliceY; } else { - box.x1 = baseBox->x1 + ky * sliceY; - box.x2 = baseBox->x1 + ky * (sliceY + sliceH); + box.x1 = baseBox->x1 + ky * sliceY; + box.x2 = baseBox->x1 + ky * (sliceY + sliceH); } box.y1 = baseBox->y2 - kx * (sliceX + sliceW); box.y2 = baseBox->y2 - kx * sliceX; @@ -320,11 +326,11 @@ Gfx *Page::createGfx(OutputDev *out, dou box.x1 = baseBox->x1 + kx * sliceX; box.x2 = baseBox->x1 + kx * (sliceX + sliceW); if (out->upsideDown()) { - box.y1 = baseBox->y2 - ky * (sliceY + sliceH); - box.y2 = baseBox->y2 - ky * sliceY; + box.y1 = baseBox->y2 - ky * (sliceY + sliceH); + box.y2 = baseBox->y2 - ky * sliceY; } else { - box.y1 = baseBox->y1 + ky * sliceY; - box.y2 = baseBox->y1 + ky * (sliceY + sliceH); + box.y1 = baseBox->y1 + ky * sliceY; + box.y2 = baseBox->y1 + ky * (sliceY + sliceH); } } } else if (useMediaBox) { @@ -336,25 +342,25 @@ Gfx *Page::createGfx(OutputDev *out, dou if (globalParams->getPrintCommands()) { printf("***** MediaBox = ll:%g,%g ur:%g,%g\n", - mediaBox->x1, mediaBox->y1, mediaBox->x2, mediaBox->y2); + mediaBox->x1, mediaBox->y1, mediaBox->x2, mediaBox->y2); printf("***** CropBox = ll:%g,%g ur:%g,%g\n", - cropBox->x1, cropBox->y1, cropBox->x2, cropBox->y2); + cropBox->x1, cropBox->y1, cropBox->x2, cropBox->y2); printf("***** Rotate = %d\n", attrs->getRotate()); } gfx = new Gfx(xref, out, num, attrs->getResourceDict(), - hDPI, vDPI, &box, crop ? cropBox : (PDFRectangle *)NULL, - rotate, abortCheckCbk, abortCheckCbkData); + hDPI, vDPI, &box, crop ? cropBox : (PDFRectangle *)NULL, + rotate, abortCheckCbk, abortCheckCbkData); return gfx; } void Page::displaySlice(OutputDev *out, double hDPI, double vDPI, - int rotate, GBool useMediaBox, GBool crop, - int sliceX, int sliceY, int sliceW, int sliceH, - Links *links, Catalog *catalog, - GBool (*abortCheckCbk)(void *data), - void *abortCheckCbkData, + int rotate, GBool useMediaBox, GBool crop, + int sliceX, int sliceY, int sliceW, int sliceH, + Links *links, Catalog *catalog, + GBool (*abortCheckCbk)(void *data), + void *abortCheckCbkData, GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data), void *annotDisplayDecideCbkData) { Gfx *gfx; @@ -364,10 +370,10 @@ void Page::displaySlice(OutputDev *out, int i; gfx = createGfx(out, hDPI, vDPI, rotate, useMediaBox, crop, - sliceX, sliceY, sliceW, sliceH, - links, catalog, - abortCheckCbk, abortCheckCbkData, - annotDisplayDecideCbk, annotDisplayDecideCbkData); + sliceX, sliceY, sliceW, sliceH, + links, catalog, + abortCheckCbk, abortCheckCbkData, + annotDisplayDecideCbk, annotDisplayDecideCbkData); contents.fetch(xref, &obj); if (!obj.isNull()) { @@ -399,8 +405,9 @@ void Page::displaySlice(OutputDev *out, Annot *annot = annotList->getAnnot(i); if ((annotDisplayDecideCbk && (*annotDisplayDecideCbk)(annot, annotDisplayDecideCbkData)) || - !annotDisplayDecideCbk) - annot->draw(gfx); + !annotDisplayDecideCbk) { + annot->draw(gfx); + } } out->dump(); } @@ -422,8 +429,8 @@ void Page::display(Gfx *gfx) { } GBool Page::loadThumb(unsigned char **data_out, - int *width_out, int *height_out, - int *rowstride_out) + int *width_out, int *height_out, + int *rowstride_out) { ImageStream *imgstr; unsigned char *pixbufdata; @@ -447,14 +454,14 @@ GBool Page::loadThumb(unsigned char **da dict = fetched_thumb.streamGetDict(); str = fetched_thumb.getStream(); - + if (!dict->lookupInt("Width", "W", &width)) goto fail1; if (!dict->lookupInt("Height", "H", &height)) goto fail1; if (!dict->lookupInt("BitsPerComponent", "BPC", &bits)) goto fail1; - + /* Check for invalid dimensions and integer overflow. */ if (width <= 0 || height <= 0) goto fail1; @@ -490,8 +497,8 @@ GBool Page::loadThumb(unsigned char **da pixbufdata = (unsigned char *) gmalloc(pixbufdatasize); p = pixbufdata; imgstr = new ImageStream(str, width, - colorMap->getNumPixelComps(), - colorMap->getBits()); + colorMap->getNumPixelComps(), + colorMap->getBits()); imgstr->reset(); for (row = 0; row < height; ++row) { for (col = 0; col < width; ++col) { @@ -527,7 +534,7 @@ GBool Page::loadThumb(unsigned char **da } void Page::getDefaultCTM(double *ctm, double hDPI, double vDPI, - int rotate, GBool upsideDown) { + int rotate, GBool upsideDown) { GfxState *state; int i; rotate += getRotate(); diff --git a/poppler/Page.h b/poppler/Page.h index 4cba942..e71af70 100644 --- a/poppler/Page.h +++ b/poppler/Page.h @@ -23,6 +23,7 @@ class Catalog; class Annots; class Annot; class Gfx; +class Form; //------------------------------------------------------------------------ @@ -151,6 +152,9 @@ public: // Get transition. Object *getTrans(Object *obj) { return trans.fetch(xref, obj); } + // Get form. + Form *getForm() { return form; } + Gfx *createGfx(OutputDev *out, double hDPI, double vDPI, int rotate, GBool useMediaBox, GBool crop, int sliceX, int sliceY, int sliceW, int sliceH, @@ -195,6 +199,7 @@ private: Object thumb; // page thumbnail Object trans; // page transition GBool ok; // true if page is valid + Form *form; // the form for that page }; #endif diff --git a/poppler/poppler-config.h.in b/poppler/poppler-config.h.in