Commit 63ea46193d4ce4cbd1dc37becad4645b0e75769b
1 parent
e7a85545
QPDFPageObjectHelper: getPageImages -> getImages
Showing
9 changed files
with
24 additions
and
13 deletions
ChangeLog
| 1 | 2020-12-31 Jay Berkenbilt <ejb@ql.org> | 1 | 2020-12-31 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * Rename QPDFPageObjectHelper::getPageImages to | ||
| 4 | + QPDFPageObjectHelper::getImages and make it support form XObjects | ||
| 5 | + as well as pages. The old name will be preserved for | ||
| 6 | + compatibility. | ||
| 7 | + | ||
| 3 | * Add QPDFObjectHandle::isFormXObject to test whether an object is | 8 | * Add QPDFObjectHandle::isFormXObject to test whether an object is |
| 4 | a form XObject. | 9 | a form XObject. |
| 5 | 10 |
examples/pdf-create.cc
| @@ -268,7 +268,7 @@ static void check(char const* filename, | @@ -268,7 +268,7 @@ static void check(char const* filename, | ||
| 268 | page_iter != pages.end(); ++page_iter) | 268 | page_iter != pages.end(); ++page_iter) |
| 269 | { | 269 | { |
| 270 | QPDFPageObjectHelper& page(*page_iter); | 270 | QPDFPageObjectHelper& page(*page_iter); |
| 271 | - std::map<std::string, QPDFObjectHandle> images = page.getPageImages(); | 271 | + std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 272 | if (images.size() != 1) | 272 | if (images.size() != 1) |
| 273 | { | 273 | { |
| 274 | throw std::logic_error("incorrect number of images on page"); | 274 | throw std::logic_error("incorrect number of images on page"); |
examples/pdf-invert-images.cc
| @@ -159,7 +159,7 @@ int main(int argc, char* argv[]) | @@ -159,7 +159,7 @@ int main(int argc, char* argv[]) | ||
| 159 | QPDFPageObjectHelper& page(*iter); | 159 | QPDFPageObjectHelper& page(*iter); |
| 160 | // Get all images on the page. | 160 | // Get all images on the page. |
| 161 | std::map<std::string, QPDFObjectHandle> images = | 161 | std::map<std::string, QPDFObjectHandle> images = |
| 162 | - page.getPageImages(); | 162 | + page.getImages(); |
| 163 | for (auto& iter2: images) | 163 | for (auto& iter2: images) |
| 164 | { | 164 | { |
| 165 | QPDFObjectHandle& image = iter2.second; | 165 | QPDFObjectHandle& image = iter2.second; |
fuzz/qpdf_fuzzer.cc
| @@ -143,7 +143,7 @@ FuzzHelper::testPages() | @@ -143,7 +143,7 @@ FuzzHelper::testPages() | ||
| 143 | { | 143 | { |
| 144 | page.coalesceContentStreams(); | 144 | page.coalesceContentStreams(); |
| 145 | page.parsePageContents(&discard_contents); | 145 | page.parsePageContents(&discard_contents); |
| 146 | - page.getPageImages(); | 146 | + page.getImages(); |
| 147 | pldh.getLabelForPage(pageno); | 147 | pldh.getLabelForPage(pageno); |
| 148 | QPDFObjectHandle page_obj(page.getObjectHandle()); | 148 | QPDFObjectHandle page_obj(page.getObjectHandle()); |
| 149 | page_obj.getJSON(true).unparse(); | 149 | page_obj.getJSON(true).unparse(); |
include/qpdf/QPDFPageObjectHelper.hh
| @@ -78,6 +78,10 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -78,6 +78,10 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 78 | // name to the image object, which is always a stream. Works with | 78 | // name to the image object, which is always a stream. Works with |
| 79 | // form XObjects as well as pages. | 79 | // form XObjects as well as pages. |
| 80 | QPDF_DLL | 80 | QPDF_DLL |
| 81 | + std::map<std::string, QPDFObjectHandle> getImages(); | ||
| 82 | + | ||
| 83 | + // Old name -- calls getImages() | ||
| 84 | + QPDF_DLL | ||
| 81 | std::map<std::string, QPDFObjectHandle> getPageImages(); | 85 | std::map<std::string, QPDFObjectHandle> getPageImages(); |
| 82 | 86 | ||
| 83 | // Convert each inline image to an external (normal) image if the | 87 | // Convert each inline image to an external (normal) image if the |
libqpdf/QPDFObjectHandle.cc
| @@ -1320,7 +1320,7 @@ QPDFObjectHandle::getGeneration() const | @@ -1320,7 +1320,7 @@ QPDFObjectHandle::getGeneration() const | ||
| 1320 | std::map<std::string, QPDFObjectHandle> | 1320 | std::map<std::string, QPDFObjectHandle> |
| 1321 | QPDFObjectHandle::getPageImages() | 1321 | QPDFObjectHandle::getPageImages() |
| 1322 | { | 1322 | { |
| 1323 | - return QPDFPageObjectHelper(*this).getPageImages(); | 1323 | + return QPDFPageObjectHelper(*this).getImages(); |
| 1324 | } | 1324 | } |
| 1325 | 1325 | ||
| 1326 | std::vector<QPDFObjectHandle> | 1326 | std::vector<QPDFObjectHandle> |
libqpdf/QPDFPageObjectHelper.cc
| @@ -389,6 +389,12 @@ QPDFPageObjectHelper::getMediaBox(bool copy_if_shared) | @@ -389,6 +389,12 @@ QPDFPageObjectHelper::getMediaBox(bool copy_if_shared) | ||
| 389 | std::map<std::string, QPDFObjectHandle> | 389 | std::map<std::string, QPDFObjectHandle> |
| 390 | QPDFPageObjectHelper::getPageImages() | 390 | QPDFPageObjectHelper::getPageImages() |
| 391 | { | 391 | { |
| 392 | + return getImages(); | ||
| 393 | +} | ||
| 394 | + | ||
| 395 | +std::map<std::string, QPDFObjectHandle> | ||
| 396 | +QPDFPageObjectHelper::getImages() | ||
| 397 | +{ | ||
| 392 | std::map<std::string, QPDFObjectHandle> result; | 398 | std::map<std::string, QPDFObjectHandle> result; |
| 393 | QPDFObjectHandle resources = getAttribute("/Resources", false); | 399 | QPDFObjectHandle resources = getAttribute("/Resources", false); |
| 394 | if (resources.isDictionary()) | 400 | if (resources.isDictionary()) |
qpdf/qpdf.cc
| @@ -3639,8 +3639,7 @@ static void do_show_pages(QPDF& pdf, Options& o) | @@ -3639,8 +3639,7 @@ static void do_show_pages(QPDF& pdf, Options& o) | ||
| 3639 | << page.getGeneration() << " R" << std::endl; | 3639 | << page.getGeneration() << " R" << std::endl; |
| 3640 | if (o.show_page_images) | 3640 | if (o.show_page_images) |
| 3641 | { | 3641 | { |
| 3642 | - std::map<std::string, QPDFObjectHandle> images = | ||
| 3643 | - ph.getPageImages(); | 3642 | + std::map<std::string, QPDFObjectHandle> images = ph.getImages(); |
| 3644 | if (! images.empty()) | 3643 | if (! images.empty()) |
| 3645 | { | 3644 | { |
| 3646 | std::cout << " images:" << std::endl; | 3645 | std::cout << " images:" << std::endl; |
| @@ -3765,8 +3764,7 @@ static void do_json_pages(QPDF& pdf, Options& o, JSON& j) | @@ -3765,8 +3764,7 @@ static void do_json_pages(QPDF& pdf, Options& o, JSON& j) | ||
| 3765 | j_page.addDictionaryMember("object", page.getJSON()); | 3764 | j_page.addDictionaryMember("object", page.getJSON()); |
| 3766 | JSON j_images = j_page.addDictionaryMember( | 3765 | JSON j_images = j_page.addDictionaryMember( |
| 3767 | "images", JSON::makeArray()); | 3766 | "images", JSON::makeArray()); |
| 3768 | - std::map<std::string, QPDFObjectHandle> images = | ||
| 3769 | - ph.getPageImages(); | 3767 | + std::map<std::string, QPDFObjectHandle> images = ph.getImages(); |
| 3770 | for (auto const& iter2: images) | 3768 | for (auto const& iter2: images) |
| 3771 | { | 3769 | { |
| 3772 | JSON j_image = j_images.addArrayElement(JSON::makeDictionary()); | 3770 | JSON j_image = j_images.addArrayElement(JSON::makeDictionary()); |
| @@ -4785,8 +4783,7 @@ static void handle_transformations(QPDF& pdf, Options& o) | @@ -4785,8 +4783,7 @@ static void handle_transformations(QPDF& pdf, Options& o) | ||
| 4785 | ++pageno; | 4783 | ++pageno; |
| 4786 | QPDFPageObjectHelper& ph(*iter); | 4784 | QPDFPageObjectHelper& ph(*iter); |
| 4787 | QPDFObjectHandle page = ph.getObjectHandle(); | 4785 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 4788 | - std::map<std::string, QPDFObjectHandle> images = | ||
| 4789 | - ph.getPageImages(); | 4786 | + std::map<std::string, QPDFObjectHandle> images = ph.getImages(); |
| 4790 | for (auto& iter2: images) | 4787 | for (auto& iter2: images) |
| 4791 | { | 4788 | { |
| 4792 | std::string name = iter2.first; | 4789 | std::string name = iter2.first; |
qpdf/test_driver.cc
| @@ -516,8 +516,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -516,8 +516,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 516 | std::cout << "page " << pageno << ":" << std::endl; | 516 | std::cout << "page " << pageno << ":" << std::endl; |
| 517 | 517 | ||
| 518 | std::cout << " images:" << std::endl; | 518 | std::cout << " images:" << std::endl; |
| 519 | - std::map<std::string, QPDFObjectHandle> images = | ||
| 520 | - page.getPageImages(); | 519 | + std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 521 | for (auto const& iter2: images) | 520 | for (auto const& iter2: images) |
| 522 | { | 521 | { |
| 523 | std::string const& name = iter2.first; | 522 | std::string const& name = iter2.first; |
| @@ -1488,7 +1487,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1488,7 +1487,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1488 | { | 1487 | { |
| 1489 | std::cout << "page " << ++pageno << std::endl; | 1488 | std::cout << "page " << ++pageno << std::endl; |
| 1490 | std::map<std::string, QPDFObjectHandle> images = | 1489 | std::map<std::string, QPDFObjectHandle> images = |
| 1491 | - (*p_iter).getPageImages(); | 1490 | + (*p_iter).getImages(); |
| 1492 | for (std::map<std::string, QPDFObjectHandle>::iterator i_iter = | 1491 | for (std::map<std::string, QPDFObjectHandle>::iterator i_iter = |
| 1493 | images.begin(); i_iter != images.end(); ++i_iter) | 1492 | images.begin(); i_iter != images.end(); ++i_iter) |
| 1494 | { | 1493 | { |