diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index 61d92e8..676f628 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -737,6 +737,32 @@ char *_poppler_goo_string_to_utf8(GooString *s) return result; } +static GooString * +_poppler_utf8_to_goo_string(const gchar *str) +{ + gsize written_bytes; + gchar *utf16; + + utf16 = g_convert(str, strlen(str), "UTF-16BE", "UTF-8", NULL, &written_bytes, NULL); + + if (!utf16) { + return NULL; + } + + GooString *goo_str = NULL; + + goo_str = new GooString(utf16, written_bytes); + + if (!goo_str->hasUnicodeMarker()) { + goo_str->insert(0, 0xff); + goo_str->insert(0, 0xfe); + } + + g_free(utf16); + + return goo_str; +} + static gchar * info_dict_get_string (Dict *info_dict, const gchar *key) { @@ -756,6 +782,53 @@ info_dict_get_string (Dict *info_dict, const gchar *key) return result; } +gchar * +poppler_document_info_get_string (PopplerDocument *document, + const gchar *key) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), key); + obj.free (); + + return retval; +} + +gboolean +poppler_document_info_set_string (PopplerDocument *document, + const gchar *key, + gchar *value) +{ + GooString *goo_str = _poppler_utf8_to_goo_string(value); + XRef *doc_xref = document->doc->getXRef(); + + g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), FALSE); + g_return_val_if_fail(goo_str && doc_xref, FALSE); + + Object goo_str_obj; + Object info_obj; + Object info_obj_ref; + + goo_str_obj.initString(goo_str); + + document->doc->getDocInfo(&info_obj); + info_obj.dictSet(key, &goo_str_obj); + + doc_xref->getDocInfoNF(&info_obj_ref); + assert(info_obj_ref.isRef()); + doc_xref->setModifiedObject(&info_obj, info_obj_ref.getRef()); + + info_obj.free(); + info_obj_ref.free(); + + return TRUE; +} + static time_t info_dict_get_date (Dict *info_dict, const gchar *key) { diff --git a/glib/poppler-document.h b/glib/poppler-document.h index a34e88c..cc9d017 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -214,6 +214,12 @@ PopplerPageMode poppler_document_get_page_mode (PopplerDocument *doc PopplerPermissions poppler_document_get_permissions (PopplerDocument *document); gchar *poppler_document_get_metadata (PopplerDocument *document); +/* Info setters/getters */ +gboolean poppler_document_info_set_string (PopplerDocument *document, + const gchar *key, + gchar *value); +gchar *poppler_document_info_get_string (PopplerDocument *document, + const gchar *key); /* Attachments */ guint poppler_document_get_n_attachments (PopplerDocument *document); gboolean poppler_document_has_attachments (PopplerDocument *document);