diff --git a/glib/poppler-form-field.cc b/glib/poppler-form-field.cc index 33c4b15..e774880 100644 --- a/glib/poppler-form-field.cc +++ b/glib/poppler-form-field.cc @@ -220,6 +220,67 @@ poppler_form_field_button_set_state (PopplerFormField *field, static_cast(field->widget)->setState ((GBool)state); } +/** + * poppler_form_field_get_partial_name: + * @field: a #PopplerFormField + * + * Gets the partial name (PDF /T property) for @field. + * + * Return value: a new allocated string. It must be freed with g_free() when done. + **/ +gchar* +poppler_form_field_get_partial_name (PopplerFormField *field) +{ + GooString *tmp; + + g_return_val_if_fail (POPPLER_IS_FORM_FIELD (field), NULL); + + tmp = field->widget->getPartialName(); + + return tmp ? _poppler_goo_string_to_utf8 (tmp) : NULL; +} + +/** + * poppler_form_field_get_mapping_name: + * @field: a #PopplerFormField + * + * Gets the mapping name (PDF /TM property) for @field. + * + * Return value: a new allocated string. It must be freed with g_free() when done. + **/ +gchar* +poppler_form_field_get_mapping_name (PopplerFormField *field) +{ + GooString *tmp; + + g_return_val_if_fail (POPPLER_IS_FORM_FIELD (field), NULL); + + tmp = field->widget->getMappingName(); + + return tmp ? _poppler_goo_string_to_utf8 (tmp) : NULL; +} + +/** + * poppler_form_field_get_fully_qualified_name: + * @field: a #PopplerFormField + * + * Gets the fully qualified name (concatenated PDF /T properties) for @field. + * + * Return value: a new allocated string. It must be freed with g_free() when done. + **/ +gchar* +poppler_form_field_get_fully_qualified_name (PopplerFormField *field) +{ + GooString *tmp; + + g_return_val_if_fail (POPPLER_IS_FORM_FIELD (field), NULL); + + tmp = field->widget->getFullyQualifiedName(); + + return tmp ? _poppler_goo_string_to_utf8 (tmp) : NULL; +} + + /* Text Field */ /** * poppler_form_field_text_get_text_type: diff --git a/glib/poppler-form-field.h b/glib/poppler-form-field.h index b8727e9..b14f805 100644 --- a/glib/poppler-form-field.h +++ b/glib/poppler-form-field.h @@ -64,6 +64,9 @@ PopplerFormFieldType poppler_form_field_get_field_type (PopplerFormFie gint poppler_form_field_get_id (PopplerFormField *field); gdouble poppler_form_field_get_font_size (PopplerFormField *field); gboolean poppler_form_field_is_read_only (PopplerFormField *field); +gchar *poppler_form_field_get_partial_name (PopplerFormField *field); +gchar *poppler_form_field_get_mapping_name (PopplerFormField *field); +gchar *poppler_form_field_get_fully_qualified_name (PopplerFormField *field); /* Button Field */ PopplerFormButtonType poppler_form_field_button_get_button_type (PopplerFormField *field); diff --git a/poppler/Form.cc b/poppler/Form.cc index 4df8a7d..78639b5 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -72,6 +72,21 @@ 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("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"); @@ -122,6 +137,15 @@ FormWidget::FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormFi FormWidget::~FormWidget() { + if (partialName) + delete partialName; + + if (mappingName) + delete mappingName; + + if (fullyQualifiedName) + delete fullyQualifiedName; + obj.free (); } @@ -163,6 +187,47 @@ 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; + + if (!partialName) + return NULL; + + full_name = new GooString(partialName); + + obj.copy(&obj1); + while (obj1.getDict()->lookup("Parent", &parent)->isDict()) { + if (parent.getDict()->lookup("T", &obj2)->isString()) { + parent_name = obj2.getString()->copy(); + obj2.free(); + + if (full_name->hasUnicodeMarker()) { + full_name->del(0, 2); // Remove the unicode BOM + parent_name->append("\0.", 2); // 2-byte unicode period + } else { + parent_name->append('.'); // 1-byte ascii period + } + + parent_name->append(full_name); + + delete full_name; + full_name = parent_name; + + } + obj1.free(); + parent.copy(&obj1); + parent.free(); + } + fullyQualifiedName = full_name; + return fullyQualifiedName; +} + FormWidgetButton::FormWidgetButton (XRef *xrefA, Object *aobj, unsigned num, Ref ref, FormField *p) : FormWidget(xrefA, aobj, num, ref, p) { diff --git a/poppler/Form.h b/poppler/Form.h index 35d66af..fea7c67 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -83,6 +83,10 @@ public: void setFontSize(double f) { fontSize = f; } double getFontSize () { return fontSize; } + GooString *getPartialName() const { return partialName; } + GooString *getMappingName() const { return mappingName; } + GooString *getFullyQualifiedName(); + GBool isModified () { return modified; } bool isReadOnly() const; @@ -104,6 +108,10 @@ protected: XRef *xref; GBool defaultsLoaded; GBool modified; + GooString *partialName; // T field + GooString *mappingName; // TM field + GooString *fullyQualifiedName; + //index of this field in the parent's child list unsigned childNum;