diff options
author | m-holger <m-holger@kubitscheck.org> | 2022-02-06 07:37:20 +0100 |
---|---|---|
committer | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2022-02-06 17:21:15 +0100 |
commit | 5901fcad4c33b6058569e93ec9eeaa12cc880469 (patch) | |
tree | 942cb0b5d6c63a35b9b97af95b10934bcaf803ec | |
parent | 83710603402229090dd5b1eefdebed044efe8d87 (diff) | |
download | qpdf-5901fcad4c33b6058569e93ec9eeaa12cc880469.tar.zst |
C-API expose QPDFObjectHandle::getKeyIfDict
-rw-r--r-- | include/qpdf/qpdf-c.h | 2 | ||||
-rw-r--r-- | libqpdf/qpdf-c.cc | 9 | ||||
-rw-r--r-- | qpdf/qpdf-ctest.c | 11 | ||||
-rw-r--r-- | qpdf/qpdf.testcov | 1 |
4 files changed, 23 insertions, 0 deletions
diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index c4e88de8..a7e2d042 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -812,6 +812,8 @@ extern "C" { QPDF_BOOL qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key); QPDF_DLL qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key); + QPDF_DLL + qpdf_oh qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key); QPDF_DLL QPDF_BOOL qpdf_oh_is_or_has_name( diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index ac728e8b..e0b852a5 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -1550,6 +1550,15 @@ qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key) }); } +qpdf_oh qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key) +{ + return do_with_oh<qpdf_oh>( + qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) { + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key_if_dict"); + return new_object(qpdf, o.getKeyIfDict(key)); + }); +} + QPDF_BOOL qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key) { return do_with_oh<QPDF_BOOL>( diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c index 7738bdf6..0867468a 100644 --- a/qpdf/qpdf-ctest.c +++ b/qpdf/qpdf-ctest.c @@ -592,6 +592,17 @@ static void test24(char const* infile, "/Encoding"); assert(strcmp(qpdf_oh_get_name(qpdf, encoding), "/WinAnsiEncoding") == 0); + qpdf_oh res = qpdf_oh_get_key_if_dict(qpdf, page1, "/Resources"); + assert(qpdf_oh_has_key(qpdf, res, "/Font")); + /* check no warning when called with null */ + while (qpdf_more_warnings(qpdf)) + { + qpdf_next_warning(qpdf); + } + res = qpdf_oh_get_key_if_dict( + qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font"); + assert(! qpdf_more_warnings(qpdf)); + /* Look at page contents to exercise stream functions */ qpdf_oh contents = qpdf_oh_get_key(qpdf, page1, "/Contents"); assert(qpdf_oh_is_stream(qpdf, contents)); diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 5e87b831..f0594da8 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -504,6 +504,7 @@ qpdf-c called qpdf_oh_dict_more_keys 0 qpdf-c called qpdf_oh_dict_next_key 0 qpdf-c called qpdf_oh_has_key 0 qpdf-c called qpdf_oh_get_key 0 +qpdf-c called qpdf_oh_get_key_if_dict 0 qpdf-c called qpdf_oh_is_or_has_name 0 qpdf-c called qpdf_oh_new_null 0 qpdf-c called qpdf_oh_new_bool 0 |