From f96e49faa06a31223734c83d30b47658b32281e7 Mon Sep 17 00:00:00 2001 From: Masamichi Hosoda Date: Sat, 3 Sep 2016 00:38:11 +0900 Subject: [PATCH v2 4/7] Add poppler_document_find_dest_bytes() to glib frontend If the named destination contains a null byte, poppler_document_find_dest() cannot find it. poppler_document_find_dest_bytes() can find it. --- glib/poppler-document.cc | 41 +++++++++++++++++++++++++++++++++++++++-- glib/poppler-document.h | 3 +++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index a03f1d9..20292f2 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -2,6 +2,7 @@ * Copyright (C) 2005, Red Hat, Inc. * * Copyright (C) 2016 Jakub Kucharski + * Copyright (C) 2016 Masamichi Hosoda * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -680,7 +681,9 @@ poppler_document_get_attachments (PopplerDocument *document) * @document: A #PopplerDocument * @link_name: a named destination * - * Finds named destination @link_name in @document + * Finds named destination @link_name in @document. + * If the named destination contains a null byte, it cannot be found. + * See also poppler_document_find_dest_bytes(). * * Return value: The #PopplerDest destination or %NULL if * @link_name is not a destination. Returned value must @@ -690,6 +693,38 @@ PopplerDest * poppler_document_find_dest (PopplerDocument *document, const gchar *link_name) { + PopplerDest *dest; + GBytes *bytes; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + g_return_val_if_fail (link_name != NULL, NULL); + + bytes = g_bytes_new (link_name, strlen (link_name)); + dest = poppler_document_find_dest_bytes (document, bytes); + g_bytes_unref (bytes); + + return dest; +} + +/** + * poppler_document_find_dest_bytes: + * @document: A #PopplerDocument + * @link_name: a named destination + * + * Finds named destination @link_name in @document. + * Even if the named destination contains a null byte, it can be found. + * See also poppler_document_find_dest(). + * + * Return value: The #PopplerDest destination or %NULL if + * @link_name is not a destination. Returned value must + * be freed with #poppler_dest_free + * + * Since: 0.48 + **/ +PopplerDest * +poppler_document_find_dest_bytes (PopplerDocument *document, + GBytes *link_name) +{ PopplerDest *dest = NULL; LinkDest *link_dest = NULL; GooString *g_link_name; @@ -697,7 +732,9 @@ poppler_document_find_dest (PopplerDocument *document, g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); g_return_val_if_fail (link_name != NULL, NULL); - g_link_name = new GooString (link_name); + g_link_name = new GooString + (static_cast (g_bytes_get_data (link_name, NULL)), + static_cast (g_bytes_get_size (link_name))); if (g_link_name) { link_dest = document->doc->findDest (g_link_name); diff --git a/glib/poppler-document.h b/glib/poppler-document.h index fb0ac72..fc580c5 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -2,6 +2,7 @@ * Copyright (C) 2004, Red Hat, Inc. * * Copyright (C) 2016 Jakub Kucharski + * Copyright (C) 2016 Masamichi Hosoda * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -240,6 +241,8 @@ GList *poppler_document_get_attachments (PopplerDocument *do /* Links */ PopplerDest *poppler_document_find_dest (PopplerDocument *document, const gchar *link_name); +PopplerDest *poppler_document_find_dest_bytes (PopplerDocument *document, + GBytes *link_name); /* Form */ PopplerFormField *poppler_document_get_form_field (PopplerDocument *document, -- 2.8.3