poppler/Form.cc | 165 ++++++++++++++++++++++++++++++-------------------------- poppler/Form.h | 26 +++++--- 2 files changed, 107 insertions(+), 84 deletions(-)
New commits: commit 2dd7e1ba09d4501adf9d10ab4cb8ee003cace74a Author: Carlos Garcia Campos <[email protected]> Date: Wed Mar 9 10:25:00 2011 +0100 forms: Move modified flag from FormWidget to FormField diff --git a/poppler/Form.cc b/poppler/Form.cc index 4acf010..2af8d3d 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -68,7 +68,6 @@ FormWidget::FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormFi double t; ID = 0; fontSize = 0.0; - modified = gFalse; childNum = num; xref = xrefA; aobj->copy(&obj); @@ -133,6 +132,10 @@ bool FormWidget::isReadOnly() const return field->isReadOnly(); } +GBool FormWidget::isModified() const { + return field->isModified(); +} + int FormWidget::encodeID (unsigned pageNum, unsigned fieldNum) { return (pageNum << 4*sizeof(unsigned)) + fieldNum; @@ -244,8 +247,6 @@ FormButtonType FormWidgetButton::getButtonType () const } void FormWidgetButton::setAppearanceState(char *state) { - modified = gTrue; - Object obj1; obj1.initName(state); obj.getDict()->set("AS", &obj1); @@ -342,7 +343,6 @@ void FormWidgetText::setContent(GooString* new_content) return; } - modified = gTrue; parent->setContentCopy(new_content); } @@ -373,7 +373,6 @@ void FormWidgetChoice::select (int i) return; } if (!_checkRange(i)) return; - modified = gTrue; parent->select(i); } @@ -384,7 +383,6 @@ void FormWidgetChoice::toggle (int i) return; } if (!_checkRange(i)) return; - modified = gTrue; parent->toggle(i); } @@ -394,7 +392,6 @@ void FormWidgetChoice::deselectAll () error(-1, "FormWidgetChoice::deselectAll called on a read only field\n"); return; } - modified = gTrue; parent->deselectAll(); } @@ -424,7 +421,6 @@ void FormWidgetChoice::setEditChoice (GooString* new_content) return; } - modified = gTrue; parent->setEditChoice(new_content); } @@ -496,6 +492,7 @@ FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, std::set<int> * fullyQualifiedName = NULL; quadding = quaddingLeftJustified; hasQuadding = gFalse; + modified = gFalse; ref = aref; @@ -837,6 +834,7 @@ GBool FormFieldButton::setState(char *state) } } updateState(state); + modified = gTrue; } return gTrue; @@ -933,6 +931,7 @@ void FormFieldText::setContentCopy (GooString* new_content) obj1.initString(content ? content->copy() : new GooString("")); obj.getDict()->set("V", &obj1); xref->setModifiedObject(&obj, ref); + modified = gTrue; } FormFieldText::~FormFieldText() @@ -1097,6 +1096,7 @@ void FormFieldChoice::updateSelection() { obj.getDict()->set("V", &obj1); xref->setModifiedObject(&obj, ref); + modified = gTrue; } void FormFieldChoice::unselectAll () diff --git a/poppler/Form.h b/poppler/Form.h index 4913fa2..b5b4edd 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -97,7 +97,7 @@ public: GooString *getMappingName() const; GooString *getFullyQualifiedName(); - GBool isModified () { return modified; } + GBool isModified () const; bool isReadOnly() const; @@ -118,7 +118,6 @@ protected: Object obj; Ref ref; XRef *xref; - GBool modified; //index of this field in the parent's child list unsigned childNum; @@ -270,6 +269,8 @@ public: void setReadOnly (bool b) { readOnly = b; } bool isReadOnly () const { return readOnly; } + GBool isModified () const { return modified; } + GooString* getDefaultAppearance() const { return defaultAppearance; } GBool hasTextQuadding() const { return hasQuadding; } VariableTextQuadding getTextQuadding() const { return quadding; } @@ -298,6 +299,7 @@ public: int numChildren; FormWidget **widgets; bool readOnly; + GBool modified; GooString *partialName; // T field GooString *alternateUiName; // TU field commit b04f03be7e43e309af5f164ef71788e7b8915841 Author: Carlos Garcia Campos <[email protected]> Date: Wed Mar 9 10:17:57 2011 +0100 forms: Move field names handling from FormWidget to FormField diff --git a/poppler/Form.cc b/poppler/Form.cc index 4698124..4acf010 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -75,28 +75,6 @@ FormWidget::FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormFi type = formUndef; field = fieldA; Dict *dict = obj.getDict(); - fullyQualifiedName = NULL; - - if (dict->lookup("T", &obj1)->isString()) { - partialName = obj1.getString()->copy(); - } else { - partialName = NULL; - } - obj1.free(); - - if (dict->lookup("TU", &obj1)->isString()) { - alternateUiName = obj1.getString()->copy(); - } else { - alternateUiName = NULL; - } - obj1.free(); - - if(dict->lookup("TM", &obj1)->isString()) { - mappingName = obj1.getString()->copy(); - } else { - mappingName = NULL; - } - obj1.free(); if (!dict->lookup("Rect", &obj1)->isArray()) { error(-1, "Annotation rectangle is wrong type"); @@ -147,10 +125,6 @@ FormWidget::FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormFi FormWidget::~FormWidget() { - delete partialName; - delete alternateUiName; - delete mappingName; - delete fullyQualifiedName; obj.free (); } @@ -192,50 +166,20 @@ void FormWidget::updateField (const char *key, Object *value) xref->setModifiedObject(obj1, ref1); } -GooString* FormWidget::getFullyQualifiedName() { - Object obj1, obj2; - Object parent; - GooString *parent_name; - GooString *full_name; - - if (fullyQualifiedName) - return fullyQualifiedName; - - full_name = new GooString(); - - obj.copy(&obj1); - while (obj1.dictLookup("Parent", &parent)->isDict()) { - if (parent.dictLookup("T", &obj2)->isString()) { - parent_name = obj2.getString(); - - if (parent_name->hasUnicodeMarker()) { - parent_name->del(0, 2); // Remove the unicode BOM - full_name->insert(0, "\0.", 2); // 2-byte unicode period - } else { - full_name->insert(0, '.'); // 1-byte ascii period - } +GooString *FormWidget::getPartialName() const { + return field->getPartialName(); +} - full_name->insert(0, parent_name); - obj2.free(); - } - obj1.free(); - parent.copy(&obj1); - parent.free(); - } - obj1.free(); - parent.free(); +GooString *FormWidget::getAlternateUiName() const { + return field->getAlternateUiName(); +} - if (partialName) { - full_name->append(partialName); - } else { - int len = full_name->getLength(); - // Remove the last period - if (len > 0) - full_name->del(len - 1, 1); - } +GooString *FormWidget::getMappingName() const { + return field->getMappingName(); +} - fullyQualifiedName = full_name; - return fullyQualifiedName; +GooString *FormWidget::getFullyQualifiedName() { + return field->getFullyQualifiedName(); } LinkAction *FormWidget::createActivationAction(Catalog *catalog) @@ -549,6 +493,7 @@ FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, std::set<int> * widgets = NULL; readOnly = false; defaultAppearance = NULL; + fullyQualifiedName = NULL; quadding = quaddingLeftJustified; hasQuadding = gFalse; @@ -642,6 +587,27 @@ FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, std::set<int> * hasQuadding = gTrue; } obj1.free(); + + if (dict->lookup("T", &obj1)->isString()) { + partialName = obj1.getString()->copy(); + } else { + partialName = NULL; + } + obj1.free(); + + if (dict->lookup("TU", &obj1)->isString()) { + alternateUiName = obj1.getString()->copy(); + } else { + alternateUiName = NULL; + } + obj1.free(); + + if(dict->lookup("TM", &obj1)->isString()) { + mappingName = obj1.getString()->copy(); + } else { + mappingName = NULL; + } + obj1.free(); } FormField::~FormField() @@ -660,6 +626,10 @@ FormField::~FormField() obj.free(); delete defaultAppearance; + delete partialName; + delete alternateUiName; + delete mappingName; + delete fullyQualifiedName; } void FormField::fillChildrenSiblingsID() @@ -714,6 +684,51 @@ FormWidget* FormField::findWidgetByRef (Ref aref) return NULL; } +GooString* FormField::getFullyQualifiedName() { + Object obj1, obj2; + Object parent; + GooString *parent_name; + GooString *full_name; + + if (fullyQualifiedName) + return fullyQualifiedName; + + full_name = new GooString(); + + obj.copy(&obj1); + while (obj1.dictLookup("Parent", &parent)->isDict()) { + if (parent.dictLookup("T", &obj2)->isString()) { + parent_name = obj2.getString(); + + if (parent_name->hasUnicodeMarker()) { + parent_name->del(0, 2); // Remove the unicode BOM + full_name->insert(0, "\0.", 2); // 2-byte unicode period + } else { + full_name->insert(0, '.'); // 1-byte ascii period + } + + full_name->insert(0, parent_name); + obj2.free(); + } + obj1.free(); + parent.copy(&obj1); + parent.free(); + } + obj1.free(); + parent.free(); + + if (partialName) { + full_name->append(partialName); + } else { + int len = full_name->getLength(); + // Remove the last period + if (len > 0) + full_name->del(len - 1, 1); + } + + fullyQualifiedName = full_name; + return fullyQualifiedName; +} //------------------------------------------------------------------------ // FormFieldButton diff --git a/poppler/Form.h b/poppler/Form.h index 74539ca..4913fa2 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -92,9 +92,9 @@ public: void setFontSize(double f) { fontSize = f; } double getFontSize () { return fontSize; } - GooString *getPartialName() const { return partialName; } - GooString *getAlternateUiName() const { return alternateUiName; } - GooString *getMappingName() const { return mappingName; } + GooString *getPartialName() const; + GooString *getAlternateUiName() const; + GooString *getMappingName() const; GooString *getFullyQualifiedName(); GBool isModified () { return modified; } @@ -119,10 +119,6 @@ protected: Ref ref; XRef *xref; GBool modified; - GooString *partialName; // T field - GooString *alternateUiName; // TU field - GooString *mappingName; // TM field - GooString *fullyQualifiedName; //index of this field in the parent's child list unsigned childNum; @@ -278,6 +274,11 @@ public: GBool hasTextQuadding() const { return hasQuadding; } VariableTextQuadding getTextQuadding() const { return quadding; } + GooString *getPartialName() const { return partialName; } + GooString *getAlternateUiName() const { return alternateUiName; } + GooString *getMappingName() const { return mappingName; } + GooString *getFullyQualifiedName(); + FormWidget* findWidgetByRef (Ref aref); // only implemented in FormFieldButton @@ -298,6 +299,11 @@ public: FormWidget **widgets; bool readOnly; + GooString *partialName; // T field + GooString *alternateUiName; // TU field + GooString *mappingName; // TM field + GooString *fullyQualifiedName; + // Variable Text GooString *defaultAppearance; GBool hasQuadding; _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
