From f1376252b2dd12c8307b7a25a809168750099cca Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Sat, 3 Sep 2016 01:51:37 +0900 Subject: [PATCH v2 5/7] Add poppler_document_build_dests_namelist() to glib frontend Builds named destinations name list in document --- glib/poppler-document.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ glib/poppler-document.h | 2 ++ 2 files changed, 71 insertions(+) diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index 20292f2..15d8d44 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -749,6 +749,75 @@ poppler_document_find_dest_bytes (PopplerDocument *document, return dest; } +/** + * poppler_document_build_dests_namelist: + * @document: A #PopplerDocument + * + * Builds named destinations name list in @document + * + * Return value: a #GList or %NULL if @document is not valid. + * The list contains #GBytes which contains a destination name. + * Note that the names can contain \0, so it is GBytes instead of gchar*. + * Returned value must be freed with poppler_document_free_dests_namelist(). + * + * Since: 0.48 + **/ +GList * +poppler_document_build_dests_namelist (PopplerDocument *document) +{ + GList *list = NULL; + Catalog *catalog; + int i, len; + GBytes *key; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + catalog = document->doc->getCatalog (); + if (catalog == NULL) + return NULL; + + // Iterate from name-dict + len = catalog->numDests (); + for (i = 0; i < len; ++i) { + key = g_bytes_new (catalog->getDestsName (i), + strlen (catalog->getDestsName (i))); + list = g_list_append (list, key); + } + + // Iterate form name-tree + len = catalog->numDestNameTree (); + for (i = 0; i < len; ++i) { + // The names of name-tree can contain \0, + // so we use GBytes instead of gchar*. + key = g_bytes_new + (catalog->getDestNameTreeName (i)->getCString (), + catalog->getDestNameTreeName (i)->getLength ()); + list = g_list_append (list, key); + } + + return list; +} + +static void +_poppler_dest_destroy_bytes (gpointer bytes) +{ + g_bytes_unref (static_cast(bytes)); +} + +/** + * poppler_document_free_dests_namelist: + * @list: Return value of poppler_document_build_dests_namelist() + * + * Free named destinations name list + * + * Since: 0.48 + **/ +void +poppler_document_free_dests_namelist (GList *list) +{ + g_list_free_full (list, _poppler_dest_destroy_bytes); +} + char *_poppler_goo_string_to_utf8(GooString *s) { if (s == NULL) { diff --git a/glib/poppler-document.h b/glib/poppler-document.h index fc580c5..1e8adb7 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -243,6 +243,8 @@ PopplerDest *poppler_document_find_dest (PopplerDocument *do const gchar *link_name); PopplerDest *poppler_document_find_dest_bytes (PopplerDocument *document, GBytes *link_name); +GList *poppler_document_build_dests_namelist (PopplerDocument *document); +void poppler_document_free_dests_namelist (GList *list); /* Form */ PopplerFormField *poppler_document_get_form_field (PopplerDocument *document, -- 2.8.3