Commit 5901fcad4c33b6058569e93ec9eeaa12cc880469

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 83710603

C-API expose QPDFObjectHandle::getKeyIfDict

include/qpdf/qpdf-c.h
... ... @@ -812,6 +812,8 @@ extern "C" {
812 812 QPDF_BOOL qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key);
813 813 QPDF_DLL
814 814 qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key);
  815 + QPDF_DLL
  816 + qpdf_oh qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key);
815 817  
816 818 QPDF_DLL
817 819 QPDF_BOOL qpdf_oh_is_or_has_name(
... ...
libqpdf/qpdf-c.cc
... ... @@ -1550,6 +1550,15 @@ qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
1550 1550 });
1551 1551 }
1552 1552  
  1553 +qpdf_oh qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key)
  1554 +{
  1555 + return do_with_oh<qpdf_oh>(
  1556 + qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) {
  1557 + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key_if_dict");
  1558 + return new_object(qpdf, o.getKeyIfDict(key));
  1559 + });
  1560 +}
  1561 +
1553 1562 QPDF_BOOL qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key)
1554 1563 {
1555 1564 return do_with_oh<QPDF_BOOL>(
... ...
qpdf/qpdf-ctest.c
... ... @@ -592,6 +592,17 @@ static void test24(char const* infile,
592 592 "/Encoding");
593 593 assert(strcmp(qpdf_oh_get_name(qpdf, encoding), "/WinAnsiEncoding") == 0);
594 594  
  595 + qpdf_oh res = qpdf_oh_get_key_if_dict(qpdf, page1, "/Resources");
  596 + assert(qpdf_oh_has_key(qpdf, res, "/Font"));
  597 + /* check no warning when called with null */
  598 + while (qpdf_more_warnings(qpdf))
  599 + {
  600 + qpdf_next_warning(qpdf);
  601 + }
  602 + res = qpdf_oh_get_key_if_dict(
  603 + qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font");
  604 + assert(! qpdf_more_warnings(qpdf));
  605 +
595 606 /* Look at page contents to exercise stream functions */
596 607 qpdf_oh contents = qpdf_oh_get_key(qpdf, page1, "/Contents");
597 608 assert(qpdf_oh_is_stream(qpdf, contents));
... ...
qpdf/qpdf.testcov
... ... @@ -504,6 +504,7 @@ qpdf-c called qpdf_oh_dict_more_keys 0
504 504 qpdf-c called qpdf_oh_dict_next_key 0
505 505 qpdf-c called qpdf_oh_has_key 0
506 506 qpdf-c called qpdf_oh_get_key 0
  507 +qpdf-c called qpdf_oh_get_key_if_dict 0
507 508 qpdf-c called qpdf_oh_is_or_has_name 0
508 509 qpdf-c called qpdf_oh_new_null 0
509 510 qpdf-c called qpdf_oh_new_bool 0
... ...