mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
Code clean up: use range-style for loops wherever possible
Remove variables obsoleted by commit 4f24617
.
This commit is contained in:
parent
70ccd807c4
commit
6c69a747b9
@ -191,9 +191,7 @@ main(int argc, char* argv[])
|
|||||||
try {
|
try {
|
||||||
QPDF pdf;
|
QPDF pdf;
|
||||||
pdf.processFile(infilename);
|
pdf.processFile(infilename);
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
|
||||||
for (auto& page: pages) {
|
|
||||||
// Attach two token filters to each page of this file.
|
// Attach two token filters to each page of this file.
|
||||||
// When the file is written, or when the pages' contents
|
// When the file is written, or when the pages' contents
|
||||||
// are retrieved in any other way, the filters will be
|
// are retrieved in any other way, the filters will be
|
||||||
|
@ -129,12 +129,9 @@ main(int argc, char* argv[])
|
|||||||
auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv);
|
auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv);
|
||||||
|
|
||||||
// For each page...
|
// For each page...
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
|
||||||
QPDFPageDocumentHelper(qpdf).getAllPages();
|
|
||||||
for (auto& page: pages) {
|
|
||||||
// Get all images on the page.
|
// Get all images on the page.
|
||||||
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
for (auto& iter: page.getImages()) {
|
||||||
for (auto& iter: images) {
|
|
||||||
QPDFObjectHandle& image = iter.second;
|
QPDFObjectHandle& image = iter.second;
|
||||||
QPDFObjectHandle image_dict = image.getDict();
|
QPDFObjectHandle image_dict = image.getDict();
|
||||||
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
|
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
|
||||||
|
@ -40,9 +40,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
|
|||||||
QPDFObjectHandle stamp_fo = inpdf.copyForeignObject(foreign_fo);
|
QPDFObjectHandle stamp_fo = inpdf.copyForeignObject(foreign_fo);
|
||||||
|
|
||||||
// For each page...
|
// For each page...
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
for (auto& ph: QPDFPageDocumentHelper(inpdf).getAllPages()) {
|
||||||
QPDFPageDocumentHelper(inpdf).getAllPages();
|
|
||||||
for (auto& ph: pages) {
|
|
||||||
// Find a unique resource name for the new form XObject
|
// Find a unique resource name for the new form XObject
|
||||||
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
||||||
int min_suffix = 1;
|
int min_suffix = 1;
|
||||||
|
@ -50,15 +50,11 @@ main(int argc, char* argv[])
|
|||||||
// illustrates how we can map from annotations to fields.
|
// illustrates how we can map from annotations to fields.
|
||||||
|
|
||||||
QPDFAcroFormDocumentHelper afdh(qpdf);
|
QPDFAcroFormDocumentHelper afdh(qpdf);
|
||||||
QPDFPageDocumentHelper pdh(qpdf);
|
for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
|
||||||
for (auto const& page: pages) {
|
|
||||||
// Get all widget annotations for each page. Widget
|
// Get all widget annotations for each page. Widget
|
||||||
// annotations are the ones that contain the details of
|
// annotations are the ones that contain the details of
|
||||||
// what's in a form field.
|
// what's in a form field.
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) {
|
||||||
afdh.getWidgetAnnotationsForPage(page);
|
|
||||||
for (auto& annot: annotations) {
|
|
||||||
// For each annotation, find its associated field. If
|
// For each annotation, find its associated field. If
|
||||||
// it's a text field, set its value.
|
// it's a text field, set its value.
|
||||||
QPDFFormFieldObjectHelper ffh =
|
QPDFFormFieldObjectHelper ffh =
|
||||||
|
@ -131,10 +131,9 @@ FuzzHelper::testPages()
|
|||||||
QPDFAcroFormDocumentHelper afdh(*q);
|
QPDFAcroFormDocumentHelper afdh(*q);
|
||||||
afdh.generateAppearancesIfNeeded();
|
afdh.generateAppearancesIfNeeded();
|
||||||
pdh.flattenAnnotations();
|
pdh.flattenAnnotations();
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
|
||||||
DiscardContents discard_contents;
|
DiscardContents discard_contents;
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (auto& page: pages) {
|
for (auto& page: pdh.getAllPages()) {
|
||||||
++pageno;
|
++pageno;
|
||||||
try {
|
try {
|
||||||
page.coalesceContentStreams();
|
page.coalesceContentStreams();
|
||||||
@ -145,9 +144,7 @@ FuzzHelper::testPages()
|
|||||||
page_obj.getJSON(JSON::LATEST, true).unparse();
|
page_obj.getJSON(JSON::LATEST, true).unparse();
|
||||||
odh.getOutlinesForPage(page_obj.getObjGen());
|
odh.getOutlinesForPage(page_obj.getObjGen());
|
||||||
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
|
||||||
afdh.getWidgetAnnotationsForPage(page);
|
|
||||||
for (auto& aoh: annotations) {
|
|
||||||
afdh.getFieldForAnnotation(aoh);
|
afdh.getFieldForAnnotation(aoh);
|
||||||
}
|
}
|
||||||
} catch (QPDFExc& e) {
|
} catch (QPDFExc& e) {
|
||||||
@ -164,8 +161,7 @@ FuzzHelper::testOutlines()
|
|||||||
QPDFOutlineDocumentHelper odh(*q);
|
QPDFOutlineDocumentHelper odh(*q);
|
||||||
queue.push_back(odh.getTopLevelOutlines());
|
queue.push_back(odh.getTopLevelOutlines());
|
||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin());
|
for (auto& ol: *(queue.begin())) {
|
||||||
for (auto& ol: outlines) {
|
|
||||||
ol.getDestPage();
|
ol.getDestPage();
|
||||||
queue.push_back(ol.getKids());
|
queue.push_back(ol.getKids());
|
||||||
}
|
}
|
||||||
|
@ -2369,8 +2369,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
|
|||||||
}
|
}
|
||||||
} else if (foreign.isDictionary()) {
|
} else if (foreign.isDictionary()) {
|
||||||
QTC::TC("qpdf", "QPDF reserve dictionary");
|
QTC::TC("qpdf", "QPDF reserve dictionary");
|
||||||
std::set<std::string> keys = foreign.getKeys();
|
for (auto const& key: foreign.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
reserveObjects(foreign.getKey(key), obj_copier, false);
|
reserveObjects(foreign.getKey(key), obj_copier, false);
|
||||||
}
|
}
|
||||||
} else if (foreign.isStream()) {
|
} else if (foreign.isStream()) {
|
||||||
|
@ -294,12 +294,8 @@ QPDFAcroFormDocumentHelper::analyze()
|
|||||||
// a file that contains this kind of error will probably not
|
// a file that contains this kind of error will probably not
|
||||||
// actually work with most viewers.
|
// actually work with most viewers.
|
||||||
|
|
||||||
QPDFPageDocumentHelper dh(this->qpdf);
|
for (auto const& ph: QPDFPageDocumentHelper(this->qpdf).getAllPages()) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
for (auto const& iter: getWidgetAnnotationsForPage(ph)) {
|
||||||
for (auto const& ph: pages) {
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annots =
|
|
||||||
getWidgetAnnotationsForPage(ph);
|
|
||||||
for (auto const& iter: annots) {
|
|
||||||
QPDFObjectHandle annot(iter.getObjectHandle());
|
QPDFObjectHandle annot(iter.getObjectHandle());
|
||||||
QPDFObjGen og(annot.getObjGen());
|
QPDFObjGen og(annot.getObjGen());
|
||||||
if (this->m->annotation_to_field.count(og) == 0) {
|
if (this->m->annotation_to_field.count(og) == 0) {
|
||||||
@ -451,12 +447,8 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFPageDocumentHelper pdh(this->qpdf);
|
for (auto const& page: QPDFPageDocumentHelper(this->qpdf).getAllPages()) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
for (auto& aoh: getWidgetAnnotationsForPage(page)) {
|
||||||
for (auto const& page: pages) {
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
|
||||||
getWidgetAnnotationsForPage(page);
|
|
||||||
for (auto& aoh: annotations) {
|
|
||||||
QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh);
|
QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh);
|
||||||
if (ffh.getFieldType() == "/Btn") {
|
if (ffh.getFieldType() == "/Btn") {
|
||||||
// Rather than generating appearances for button
|
// Rather than generating appearances for button
|
||||||
|
@ -867,11 +867,9 @@ QPDFJob::doCheck(QPDF& pdf)
|
|||||||
w.write();
|
w.write();
|
||||||
|
|
||||||
// Parse all content streams
|
// Parse all content streams
|
||||||
QPDFPageDocumentHelper dh(pdf);
|
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
|
||||||
DiscardContents discard_contents;
|
DiscardContents discard_contents;
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (auto& page: pages) {
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
++pageno;
|
++pageno;
|
||||||
try {
|
try {
|
||||||
page.parseContents(&discard_contents);
|
page.parseContents(&discard_contents);
|
||||||
@ -939,11 +937,9 @@ QPDFJob::doShowObj(QPDF& pdf)
|
|||||||
void
|
void
|
||||||
QPDFJob::doShowPages(QPDF& pdf)
|
QPDFJob::doShowPages(QPDF& pdf)
|
||||||
{
|
{
|
||||||
QPDFPageDocumentHelper dh(pdf);
|
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
auto& cout = *this->m->cout;
|
auto& cout = *this->m->cout;
|
||||||
for (auto& ph: pages) {
|
for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
QPDFObjectHandle page = ph.getObjectHandle();
|
||||||
++pageno;
|
++pageno;
|
||||||
|
|
||||||
@ -966,8 +962,7 @@ QPDFJob::doShowPages(QPDF& pdf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cout << " content:" << std::endl;
|
cout << " content:" << std::endl;
|
||||||
std::vector<QPDFObjectHandle> content = ph.getPageContents();
|
for (auto& iter2: ph.getPageContents()) {
|
||||||
for (auto& iter2: content) {
|
|
||||||
cout << " " << iter2.unparse() << std::endl;
|
cout << " " << iter2.unparse() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1085,8 +1080,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
|
|||||||
JSON::writeDictionaryOpen(p, first_object, 1);
|
JSON::writeDictionaryOpen(p, first_object, 1);
|
||||||
bool all_objects = m->json_objects.empty();
|
bool all_objects = m->json_objects.empty();
|
||||||
std::set<QPDFObjGen> wanted_og = getWantedJSONObjects();
|
std::set<QPDFObjGen> wanted_og = getWantedJSONObjects();
|
||||||
std::vector<QPDFObjectHandle> objects = pdf.getAllObjects();
|
for (auto& obj: pdf.getAllObjects()) {
|
||||||
for (auto& obj: objects) {
|
|
||||||
std::string key = obj.unparse();
|
std::string key = obj.unparse();
|
||||||
if (this->m->json_version > 1) {
|
if (this->m->json_version > 1) {
|
||||||
key = "obj:" + key;
|
key = "obj:" + key;
|
||||||
@ -1140,20 +1134,17 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
|||||||
JSON::writeDictionaryKey(p, first, "pages", 0);
|
JSON::writeDictionaryKey(p, first, "pages", 0);
|
||||||
bool first_page = true;
|
bool first_page = true;
|
||||||
JSON::writeArrayOpen(p, first_page, 1);
|
JSON::writeArrayOpen(p, first_page, 1);
|
||||||
QPDFPageDocumentHelper pdh(pdf);
|
|
||||||
QPDFPageLabelDocumentHelper pldh(pdf);
|
QPDFPageLabelDocumentHelper pldh(pdf);
|
||||||
QPDFOutlineDocumentHelper odh(pdf);
|
QPDFOutlineDocumentHelper odh(pdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
|
||||||
int pageno = -1;
|
int pageno = -1;
|
||||||
for (auto& ph: pages) {
|
for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
++pageno;
|
++pageno;
|
||||||
JSON j_page = JSON::makeDictionary();
|
JSON j_page = JSON::makeDictionary();
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
QPDFObjectHandle page = ph.getObjectHandle();
|
||||||
j_page.addDictionaryMember(
|
j_page.addDictionaryMember(
|
||||||
"object", page.getJSON(this->m->json_version));
|
"object", page.getJSON(this->m->json_version));
|
||||||
JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
|
JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
|
||||||
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
|
for (auto const& iter2: ph.getImages()) {
|
||||||
for (auto const& iter2: images) {
|
|
||||||
JSON j_image = j_images.addArrayElement(JSON::makeDictionary());
|
JSON j_image = j_images.addArrayElement(JSON::makeDictionary());
|
||||||
j_image.addDictionaryMember("name", JSON::makeString(iter2.first));
|
j_image.addDictionaryMember("name", JSON::makeString(iter2.first));
|
||||||
QPDFObjectHandle image = iter2.second;
|
QPDFObjectHandle image = iter2.second;
|
||||||
@ -1195,8 +1186,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
|||||||
j_page.addDictionaryMember("images", j_images);
|
j_page.addDictionaryMember("images", j_images);
|
||||||
JSON j_contents =
|
JSON j_contents =
|
||||||
j_page.addDictionaryMember("contents", JSON::makeArray());
|
j_page.addDictionaryMember("contents", JSON::makeArray());
|
||||||
std::vector<QPDFObjectHandle> content = ph.getPageContents();
|
for (auto& iter2: ph.getPageContents()) {
|
||||||
for (auto& iter2: content) {
|
|
||||||
j_contents.addArrayElement(iter2.getJSON(this->m->json_version));
|
j_contents.addArrayElement(iter2.getJSON(this->m->json_version));
|
||||||
}
|
}
|
||||||
j_page.addDictionaryMember(
|
j_page.addDictionaryMember(
|
||||||
@ -1285,10 +1275,8 @@ void
|
|||||||
QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf)
|
QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf)
|
||||||
{
|
{
|
||||||
std::map<QPDFObjGen, int> page_numbers;
|
std::map<QPDFObjGen, int> page_numbers;
|
||||||
QPDFPageDocumentHelper dh(pdf);
|
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (auto const& ph: pages) {
|
for (auto const& ph: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
QPDFObjectHandle oh = ph.getObjectHandle();
|
QPDFObjectHandle oh = ph.getObjectHandle();
|
||||||
page_numbers[oh.getObjGen()] = ++n;
|
page_numbers[oh.getObjGen()] = ++n;
|
||||||
}
|
}
|
||||||
@ -1309,14 +1297,10 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
|
|||||||
j_acroform.addDictionaryMember(
|
j_acroform.addDictionaryMember(
|
||||||
"needappearances", JSON::makeBool(afdh.getNeedAppearances()));
|
"needappearances", JSON::makeBool(afdh.getNeedAppearances()));
|
||||||
JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray());
|
JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray());
|
||||||
QPDFPageDocumentHelper pdh(pdf);
|
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
|
||||||
int pagepos1 = 0;
|
int pagepos1 = 0;
|
||||||
for (auto const& page: pages) {
|
for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
++pagepos1;
|
++pagepos1;
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
|
||||||
afdh.getWidgetAnnotationsForPage(page);
|
|
||||||
for (auto& aoh: annotations) {
|
|
||||||
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
|
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
|
||||||
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
|
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
|
||||||
j_field.addDictionaryMember(
|
j_field.addDictionaryMember(
|
||||||
@ -1355,8 +1339,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
|
|||||||
j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText()));
|
j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText()));
|
||||||
JSON j_choices =
|
JSON j_choices =
|
||||||
j_field.addDictionaryMember("choices", JSON::makeArray());
|
j_field.addDictionaryMember("choices", JSON::makeArray());
|
||||||
std::vector<std::string> choices = ffh.getChoices();
|
for (auto const& choice: ffh.getChoices()) {
|
||||||
for (auto const& choice: choices) {
|
|
||||||
j_choices.addArrayElement(JSON::makeString(choice));
|
j_choices.addArrayElement(JSON::makeString(choice));
|
||||||
}
|
}
|
||||||
JSON j_annot = j_field.addDictionaryMember(
|
JSON j_annot = j_field.addDictionaryMember(
|
||||||
@ -2282,19 +2265,16 @@ QPDFJob::handleTransformations(QPDF& pdf)
|
|||||||
};
|
};
|
||||||
if (m->externalize_inline_images ||
|
if (m->externalize_inline_images ||
|
||||||
(m->optimize_images && (!m->keep_inline_images))) {
|
(m->optimize_images && (!m->keep_inline_images))) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
for (auto& ph: dh.getAllPages()) {
|
||||||
for (auto& ph: pages) {
|
|
||||||
ph.externalizeInlineImages(m->ii_min_bytes);
|
ph.externalizeInlineImages(m->ii_min_bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m->optimize_images) {
|
if (m->optimize_images) {
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
for (auto& ph: dh.getAllPages()) {
|
||||||
for (auto& ph: pages) {
|
|
||||||
++pageno;
|
++pageno;
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
QPDFObjectHandle page = ph.getObjectHandle();
|
||||||
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
|
for (auto& iter2: ph.getImages()) {
|
||||||
for (auto& iter2: images) {
|
|
||||||
std::string name = iter2.first;
|
std::string name = iter2.first;
|
||||||
QPDFObjectHandle& image = iter2.second;
|
QPDFObjectHandle& image = iter2.second;
|
||||||
ImageOptimizer* io = new ImageOptimizer(
|
ImageOptimizer* io = new ImageOptimizer(
|
||||||
@ -2330,8 +2310,7 @@ QPDFJob::handleTransformations(QPDF& pdf)
|
|||||||
m->flatten_annotations_required, m->flatten_annotations_forbidden);
|
m->flatten_annotations_required, m->flatten_annotations_forbidden);
|
||||||
}
|
}
|
||||||
if (m->coalesce_contents) {
|
if (m->coalesce_contents) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
for (auto& page: dh.getAllPages()) {
|
||||||
for (auto& page: pages) {
|
|
||||||
page.coalesceContentStreams();
|
page.coalesceContentStreams();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2805,9 +2784,7 @@ QPDFJob::handleRotations(QPDF& pdf)
|
|||||||
std::string const& range = iter.first;
|
std::string const& range = iter.first;
|
||||||
QPDFJob::RotationSpec const& rspec = iter.second;
|
QPDFJob::RotationSpec const& rspec = iter.second;
|
||||||
// range has been previously validated
|
// range has been previously validated
|
||||||
std::vector<int> to_rotate =
|
for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) {
|
||||||
QUtil::parse_numrange(range.c_str(), npages);
|
|
||||||
for (int pageno_iter: to_rotate) {
|
|
||||||
int pageno = pageno_iter - 1;
|
int pageno = pageno_iter - 1;
|
||||||
if ((pageno >= 0) && (pageno < npages)) {
|
if ((pageno >= 0) && (pageno < npages)) {
|
||||||
pages.at(QIntC::to_size(pageno))
|
pages.at(QIntC::to_size(pageno))
|
||||||
|
@ -1240,12 +1240,10 @@ QPDFObjectHandle::getResourceNames()
|
|||||||
if (!isDictionary()) {
|
if (!isDictionary()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
std::set<std::string> keys = getKeys();
|
for (auto const& key: getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
QPDFObjectHandle val = getKey(key);
|
QPDFObjectHandle val = getKey(key);
|
||||||
if (val.isDictionary()) {
|
if (val.isDictionary()) {
|
||||||
std::set<std::string> val_keys = val.getKeys();
|
for (auto const& val_key: val.getKeys()) {
|
||||||
for (auto const& val_key: val_keys) {
|
|
||||||
result.insert(val_key);
|
result.insert(val_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1642,14 +1640,12 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
|
|||||||
{
|
{
|
||||||
new_contents.assertStream();
|
new_contents.assertStream();
|
||||||
|
|
||||||
std::vector<QPDFObjectHandle> orig_contents = getPageContents();
|
|
||||||
|
|
||||||
std::vector<QPDFObjectHandle> content_streams;
|
std::vector<QPDFObjectHandle> content_streams;
|
||||||
if (first) {
|
if (first) {
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
|
QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
|
||||||
content_streams.push_back(new_contents);
|
content_streams.push_back(new_contents);
|
||||||
}
|
}
|
||||||
for (auto const& iter: orig_contents) {
|
for (auto const& iter: getPageContents()) {
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle append page contents");
|
QTC::TC("qpdf", "QPDFObjectHandle append page contents");
|
||||||
content_streams.push_back(iter);
|
content_streams.push_back(iter);
|
||||||
}
|
}
|
||||||
@ -1657,8 +1653,7 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
|
|||||||
content_streams.push_back(new_contents);
|
content_streams.push_back(new_contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFObjectHandle contents = QPDFObjectHandle::newArray(content_streams);
|
this->replaceKey("/Contents", newArray(content_streams));
|
||||||
this->replaceKey("/Contents", contents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -2927,9 +2922,8 @@ QPDFObjectHandle::copyObject(
|
|||||||
new_obj = std::shared_ptr<QPDFObject>(new QPDF_Array(items));
|
new_obj = std::shared_ptr<QPDFObject>(new QPDF_Array(items));
|
||||||
} else if (isDictionary()) {
|
} else if (isDictionary()) {
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
|
QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
|
||||||
std::set<std::string> keys = getKeys();
|
|
||||||
std::map<std::string, QPDFObjectHandle> items;
|
std::map<std::string, QPDFObjectHandle> items;
|
||||||
for (auto const& key: keys) {
|
for (auto const& key: getKeys()) {
|
||||||
items[key] = getKey(key);
|
items[key] = getKey(key);
|
||||||
if ((!first_level_only) &&
|
if ((!first_level_only) &&
|
||||||
(cross_indirect || (!items[key].isIndirect()))) {
|
(cross_indirect || (!items[key].isIndirect()))) {
|
||||||
|
@ -12,9 +12,8 @@ QPDFPageDocumentHelper::QPDFPageDocumentHelper(QPDF& qpdf) :
|
|||||||
std::vector<QPDFPageObjectHelper>
|
std::vector<QPDFPageObjectHelper>
|
||||||
QPDFPageDocumentHelper::getAllPages()
|
QPDFPageDocumentHelper::getAllPages()
|
||||||
{
|
{
|
||||||
std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages();
|
|
||||||
std::vector<QPDFPageObjectHelper> pages;
|
std::vector<QPDFPageObjectHelper> pages;
|
||||||
for (auto const& iter: pages_v) {
|
for (auto const& iter: this->qpdf.getAllPages()) {
|
||||||
pages.push_back(QPDFPageObjectHelper(iter));
|
pages.push_back(QPDFPageObjectHelper(iter));
|
||||||
}
|
}
|
||||||
return pages;
|
return pages;
|
||||||
@ -29,8 +28,7 @@ QPDFPageDocumentHelper::pushInheritedAttributesToPage()
|
|||||||
void
|
void
|
||||||
QPDFPageDocumentHelper::removeUnreferencedResources()
|
QPDFPageDocumentHelper::removeUnreferencedResources()
|
||||||
{
|
{
|
||||||
std::vector<QPDFPageObjectHelper> pages = getAllPages();
|
for (auto& ph: getAllPages()) {
|
||||||
for (auto& ph: pages) {
|
|
||||||
ph.removeUnreferencedResources();
|
ph.removeUnreferencedResources();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,8 +64,7 @@ QPDFPageDocumentHelper::flattenAnnotations(
|
|||||||
.warnIfPossible("document does not have updated appearance streams,"
|
.warnIfPossible("document does not have updated appearance streams,"
|
||||||
" so form fields will not be flattened");
|
" so form fields will not be flattened");
|
||||||
}
|
}
|
||||||
std::vector<QPDFPageObjectHelper> pages = getAllPages();
|
for (auto& ph: getAllPages()) {
|
||||||
for (auto& ph: pages) {
|
|
||||||
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
||||||
if (!resources.isDictionary()) {
|
if (!resources.isDictionary()) {
|
||||||
// This should never happen and is not exercised in the
|
// This should never happen and is not exercised in the
|
||||||
|
@ -567,8 +567,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input)
|
|||||||
bool found_alpha = false;
|
bool found_alpha = false;
|
||||||
bool found_non_printable = false;
|
bool found_non_printable = false;
|
||||||
bool found_other = false;
|
bool found_other = false;
|
||||||
std::string value = t.getValue();
|
for (char ch: t.getValue()) {
|
||||||
for (char ch: value) {
|
|
||||||
if (((ch >= 'a') && (ch <= 'z')) ||
|
if (((ch >= 'a') && (ch <= 'z')) ||
|
||||||
((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
|
((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
|
||||||
// Treat '*' as alpha since there are valid
|
// Treat '*' as alpha since there are valid
|
||||||
|
@ -1237,8 +1237,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (object.isDictionary()) {
|
} else if (object.isDictionary()) {
|
||||||
std::set<std::string> keys = object.getKeys();
|
for (auto const& key: object.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
if (!this->m->linearized) {
|
if (!this->m->linearized) {
|
||||||
enqueueObject(object.getKey(key));
|
enqueueObject(object.getKey(key));
|
||||||
}
|
}
|
||||||
@ -1283,8 +1282,7 @@ QPDFWriter::writeTrailer(
|
|||||||
writeString(" /Size ");
|
writeString(" /Size ");
|
||||||
writeString(QUtil::int_to_string(size));
|
writeString(QUtil::int_to_string(size));
|
||||||
} else {
|
} else {
|
||||||
std::set<std::string> keys = trailer.getKeys();
|
for (auto const& key: trailer.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeStringNoQDF(" ");
|
writeStringNoQDF(" ");
|
||||||
writeString(QPDF_Name::normalizeName(key));
|
writeString(QPDF_Name::normalizeName(key));
|
||||||
@ -1644,8 +1642,7 @@ QPDFWriter::unparseObject(
|
|||||||
writeString("<<");
|
writeString("<<");
|
||||||
writeStringQDF("\n");
|
writeStringQDF("\n");
|
||||||
|
|
||||||
std::set<std::string> keys = object.getKeys();
|
for (auto const& key: object.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
writeStringQDF(indent);
|
writeStringQDF(indent);
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeStringNoQDF(" ");
|
writeStringNoQDF(" ");
|
||||||
@ -2074,8 +2071,7 @@ QPDFWriter::generateID()
|
|||||||
seed += " QPDF ";
|
seed += " QPDF ";
|
||||||
if (trailer.hasKey("/Info")) {
|
if (trailer.hasKey("/Info")) {
|
||||||
QPDFObjectHandle info = trailer.getKey("/Info");
|
QPDFObjectHandle info = trailer.getKey("/Info");
|
||||||
std::set<std::string> keys = info.getKeys();
|
for (auto const& key: info.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
QPDFObjectHandle obj = info.getKey(key);
|
QPDFObjectHandle obj = info.getKey(key);
|
||||||
if (obj.isString()) {
|
if (obj.isString()) {
|
||||||
seed += " ";
|
seed += " ";
|
||||||
@ -2365,8 +2361,7 @@ QPDFWriter::doWriteSetup()
|
|||||||
|
|
||||||
if (this->m->linearized) {
|
if (this->m->linearized) {
|
||||||
// Page dictionaries are not allowed to be compressed objects.
|
// Page dictionaries are not allowed to be compressed objects.
|
||||||
std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
|
for (auto& page: this->m->pdf.getAllPages()) {
|
||||||
for (auto& page: pages) {
|
|
||||||
QPDFObjGen og = page.getObjGen();
|
QPDFObjGen og = page.getObjGen();
|
||||||
if (this->m->object_to_object_stream.count(og)) {
|
if (this->m->object_to_object_stream.count(og)) {
|
||||||
QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
|
QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
|
||||||
@ -3251,8 +3246,7 @@ QPDFWriter::enqueueObjectsStandard()
|
|||||||
// dictionary into the queue, handling direct objects recursively.
|
// dictionary into the queue, handling direct objects recursively.
|
||||||
// Root is already there, so enqueuing it a second time is a
|
// Root is already there, so enqueuing it a second time is a
|
||||||
// no-op.
|
// no-op.
|
||||||
std::set<std::string> keys = trailer.getKeys();
|
for (auto const& key: trailer.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
enqueueObject(trailer.getKey(key));
|
enqueueObject(trailer.getKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3276,8 +3270,7 @@ QPDFWriter::enqueueObjectsPCLm()
|
|||||||
|
|
||||||
// enqueue all the strips for each page
|
// enqueue all the strips for each page
|
||||||
QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject");
|
QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject");
|
||||||
std::set<std::string> keys = strips.getKeys();
|
for (auto const& image: strips.getKeys()) {
|
||||||
for (auto const& image: keys) {
|
|
||||||
enqueueObject(strips.getKey(image));
|
enqueueObject(strips.getKey(image));
|
||||||
enqueueObject(QPDFObjectHandle::newStream(
|
enqueueObject(QPDFObjectHandle::newStream(
|
||||||
&this->m->pdf, image_transform_content));
|
&this->m->pdf, image_transform_content));
|
||||||
|
@ -663,9 +663,8 @@ QPDF::maxEnd(ObjUser const& ou)
|
|||||||
if (this->m->obj_user_to_objects.count(ou) == 0) {
|
if (this->m->obj_user_to_objects.count(ou) == 0) {
|
||||||
stopOnError("no entry in object user table for requested object user");
|
stopOnError("no entry in object user table for requested object user");
|
||||||
}
|
}
|
||||||
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
|
|
||||||
qpdf_offset_t end = 0;
|
qpdf_offset_t end = 0;
|
||||||
for (auto const& og: ogs) {
|
for (auto const& og: this->m->obj_user_to_objects[ou]) {
|
||||||
if (this->m->obj_cache.count(og) == 0) {
|
if (this->m->obj_cache.count(og) == 0) {
|
||||||
stopOnError("unknown object referenced in object user table");
|
stopOnError("unknown object referenced in object user table");
|
||||||
}
|
}
|
||||||
@ -1474,8 +1473,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
stopOnError("found unreferenced page while"
|
stopOnError("found unreferenced page while"
|
||||||
" calculating linearization data");
|
" calculating linearization data");
|
||||||
}
|
}
|
||||||
std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];
|
for (auto const& og: this->m->obj_user_to_objects[ou]) {
|
||||||
for (auto const& og: ogs) {
|
|
||||||
if (lc_other_page_private.count(og)) {
|
if (lc_other_page_private.count(og)) {
|
||||||
lc_other_page_private.erase(og);
|
lc_other_page_private.erase(og);
|
||||||
this->m->part7.push_back(objGenToIndirect(og));
|
this->m->part7.push_back(objGenToIndirect(og));
|
||||||
@ -1637,8 +1635,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
stopOnError("found unreferenced page while"
|
stopOnError("found unreferenced page while"
|
||||||
" calculating linearization data");
|
" calculating linearization data");
|
||||||
}
|
}
|
||||||
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
|
for (auto const& og: this->m->obj_user_to_objects[ou]) {
|
||||||
for (auto const& og: ogs) {
|
|
||||||
if ((this->m->object_to_obj_users[og].size() > 1) &&
|
if ((this->m->object_to_obj_users[og].size() > 1) &&
|
||||||
(obj_to_index.count(og.getObj()) > 0)) {
|
(obj_to_index.count(og.getObj()) > 0)) {
|
||||||
int idx = obj_to_index[og.getObj()];
|
int idx = obj_to_index[og.getObj()];
|
||||||
|
@ -90,8 +90,7 @@ QPDF::optimize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Traverse document-level items
|
// Traverse document-level items
|
||||||
std::set<std::string> keys = this->m->trailer.getKeys();
|
for (auto const& key: this->m->trailer.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
if (key == "/Root") {
|
if (key == "/Root") {
|
||||||
// handled separately
|
// handled separately
|
||||||
} else {
|
} else {
|
||||||
@ -102,8 +101,7 @@ QPDF::optimize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = root.getKeys();
|
for (auto const& key: root.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
// Technically, /I keys from /Thread dictionaries are supposed
|
// Technically, /I keys from /Thread dictionaries are supposed
|
||||||
// to be handled separately, but we are going to disregard
|
// to be handled separately, but we are going to disregard
|
||||||
// that specification for now. There is loads of evidence
|
// that specification for now. There is loads of evidence
|
||||||
@ -205,8 +203,7 @@ QPDF::pushInheritedAttributesToPageInternal(
|
|||||||
// that have values for this attribute.
|
// that have values for this attribute.
|
||||||
|
|
||||||
std::set<std::string> inheritable_keys;
|
std::set<std::string> inheritable_keys;
|
||||||
std::set<std::string> keys = cur_pages.getKeys();
|
for (auto const& key: cur_pages.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
if ((key == "/MediaBox") || (key == "/CropBox") ||
|
if ((key == "/MediaBox") || (key == "/CropBox") ||
|
||||||
(key == "/Resources") || (key == "/Rotate")) {
|
(key == "/Resources") || (key == "/Rotate")) {
|
||||||
if (!allow_changes) {
|
if (!allow_changes) {
|
||||||
@ -387,8 +384,7 @@ QPDF::updateObjectMapsInternal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> keys = dict.getKeys();
|
for (auto const& key: dict.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
if (is_page_node && (key == "/Thumb")) {
|
if (is_page_node && (key == "/Thumb")) {
|
||||||
// Traverse page thumbnail dictionaries as a special
|
// Traverse page thumbnail dictionaries as a special
|
||||||
// case.
|
// case.
|
||||||
@ -437,8 +433,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data)
|
|||||||
|
|
||||||
for (auto const& i1: this->m->obj_user_to_objects) {
|
for (auto const& i1: this->m->obj_user_to_objects) {
|
||||||
ObjUser const& ou = i1.first;
|
ObjUser const& ou = i1.first;
|
||||||
std::set<QPDFObjGen> const& objects = i1.second;
|
// Loop over objects.
|
||||||
for (auto const& og: objects) {
|
for (auto const& og: i1.second) {
|
||||||
auto i2 = object_stream_data.find(og.getObj());
|
auto i2 = object_stream_data.find(og.getObj());
|
||||||
if (i2 == object_stream_data.end()) {
|
if (i2 == object_stream_data.end()) {
|
||||||
t_obj_user_to_objects[ou].insert(og);
|
t_obj_user_to_objects[ou].insert(og);
|
||||||
@ -450,8 +446,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data)
|
|||||||
|
|
||||||
for (auto const& i1: this->m->object_to_obj_users) {
|
for (auto const& i1: this->m->object_to_obj_users) {
|
||||||
QPDFObjGen const& og = i1.first;
|
QPDFObjGen const& og = i1.first;
|
||||||
std::set<ObjUser> const& objusers = i1.second;
|
// Loop over obj_users.
|
||||||
for (auto const& ou: objusers) {
|
for (auto const& ou: i1.second) {
|
||||||
auto i2 = object_stream_data.find(og.getObj());
|
auto i2 = object_stream_data.find(og.getObj());
|
||||||
if (i2 == object_stream_data.end()) {
|
if (i2 == object_stream_data.end()) {
|
||||||
t_object_to_obj_users[og].insert(ou);
|
t_object_to_obj_users[og].insert(ou);
|
||||||
|
@ -377,15 +377,12 @@ test_4(QPDF& pdf, char const* arg2)
|
|||||||
static void
|
static void
|
||||||
test_5(QPDF& pdf, char const* arg2)
|
test_5(QPDF& pdf, char const* arg2)
|
||||||
{
|
{
|
||||||
QPDFPageDocumentHelper dh(pdf);
|
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (auto& page: pages) {
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
++pageno;
|
++pageno;
|
||||||
std::cout << "page " << pageno << ":" << std::endl;
|
std::cout << "page " << pageno << ":" << std::endl;
|
||||||
std::cout << " images:" << std::endl;
|
std::cout << " images:" << std::endl;
|
||||||
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
for (auto const& iter2: page.getImages()) {
|
||||||
for (auto const& iter2: images) {
|
|
||||||
std::string const& name = iter2.first;
|
std::string const& name = iter2.first;
|
||||||
QPDFObjectHandle image = iter2.second;
|
QPDFObjectHandle image = iter2.second;
|
||||||
QPDFObjectHandle dict = image.getDict();
|
QPDFObjectHandle dict = image.getDict();
|
||||||
@ -1319,9 +1316,7 @@ static void
|
|||||||
test_37(QPDF& pdf, char const* arg2)
|
test_37(QPDF& pdf, char const* arg2)
|
||||||
{
|
{
|
||||||
// Parse content streams of all pages
|
// Parse content streams of all pages
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
|
||||||
for (auto& page: pages) {
|
|
||||||
ParserCallbacks cb;
|
ParserCallbacks cb;
|
||||||
page.parseContents(&cb);
|
page.parseContents(&cb);
|
||||||
}
|
}
|
||||||
@ -1341,10 +1336,8 @@ static void
|
|||||||
test_39(QPDF& pdf, char const* arg2)
|
test_39(QPDF& pdf, char const* arg2)
|
||||||
{
|
{
|
||||||
// Display image filter and color set for each image on each page
|
// Display image filter and color set for each image on each page
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (auto& page: pages) {
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
std::cout << "page " << ++pageno << std::endl;
|
std::cout << "page " << ++pageno << std::endl;
|
||||||
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
||||||
for (auto& i_iter: images) {
|
for (auto& i_iter: images) {
|
||||||
@ -1377,9 +1370,7 @@ test_41(QPDF& pdf, char const* arg2)
|
|||||||
{
|
{
|
||||||
// Apply a token filter. This test case is crafted to work
|
// Apply a token filter. This test case is crafted to work
|
||||||
// with coalesce.pdf.
|
// with coalesce.pdf.
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
|
||||||
for (auto& page: pages) {
|
|
||||||
page.addContentTokenFilter(
|
page.addContentTokenFilter(
|
||||||
std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
|
std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
|
||||||
}
|
}
|
||||||
@ -1509,8 +1500,7 @@ test_43(QPDF& pdf, char const* arg2)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "iterating over form fields\n";
|
std::cout << "iterating over form fields\n";
|
||||||
std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields();
|
for (auto& ffh: afdh.getFormFields()) {
|
||||||
for (auto& ffh: form_fields) {
|
|
||||||
std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
|
std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
|
||||||
QPDFFormFieldObjectHelper node = ffh;
|
QPDFFormFieldObjectHelper node = ffh;
|
||||||
while (!node.isNull()) {
|
while (!node.isNull()) {
|
||||||
@ -1548,9 +1538,7 @@ test_43(QPDF& pdf, char const* arg2)
|
|||||||
std::cout << "iterating over annotations per page\n";
|
std::cout << "iterating over annotations per page\n";
|
||||||
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
|
std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) {
|
||||||
afdh.getWidgetAnnotationsForPage(page);
|
|
||||||
for (auto& ah: annotations) {
|
|
||||||
std::cout << " Annotation: " << ah.getObjectHandle().unparse()
|
std::cout << " Annotation: " << ah.getObjectHandle().unparse()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout
|
std::cout
|
||||||
@ -1578,9 +1566,7 @@ static void
|
|||||||
test_44(QPDF& pdf, char const* arg2)
|
test_44(QPDF& pdf, char const* arg2)
|
||||||
{
|
{
|
||||||
// Set form fields.
|
// Set form fields.
|
||||||
QPDFAcroFormDocumentHelper afdh(pdf);
|
for (auto& field: QPDFAcroFormDocumentHelper(pdf).getFormFields()) {
|
||||||
std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields();
|
|
||||||
for (auto& field: fields) {
|
|
||||||
QPDFObjectHandle ft = field.getInheritableFieldValue("/FT");
|
QPDFObjectHandle ft = field.getInheritableFieldValue("/FT");
|
||||||
if (ft.isName() && (ft.getName() == "/Tx")) {
|
if (ft.isName() && (ft.getName() == "/Tx")) {
|
||||||
// \xc3\xb7 is utf-8 for U+00F7 (divided by)
|
// \xc3\xb7 is utf-8 for U+00F7 (divided by)
|
||||||
|
@ -51,8 +51,7 @@ walk(
|
|||||||
result[stream_number].push_back(p);
|
result[stream_number].push_back(p);
|
||||||
|
|
||||||
if (obj.isArray()) {
|
if (obj.isArray()) {
|
||||||
std::vector<QPDFObjectHandle> array = obj.getArrayAsVector();
|
for (auto& oh: obj.getArrayAsVector()) {
|
||||||
for (auto& oh: array) {
|
|
||||||
if (!oh.isIndirect()) {
|
if (!oh.isIndirect()) {
|
||||||
// QPDF::GetAllObjects() enumerates all indirect objects.
|
// QPDF::GetAllObjects() enumerates all indirect objects.
|
||||||
// So only the direct objects are recursed here.
|
// So only the direct objects are recursed here.
|
||||||
@ -60,8 +59,7 @@ walk(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (obj.isDictionary()) {
|
} else if (obj.isDictionary()) {
|
||||||
std::set<std::string> keys = obj.getKeys();
|
for (auto const& key: obj.getKeys()) {
|
||||||
for (auto const& key: keys) {
|
|
||||||
QPDFObjectHandle item = obj.getKey(key);
|
QPDFObjectHandle item = obj.getKey(key);
|
||||||
if (!item.isIndirect()) {
|
if (!item.isIndirect()) {
|
||||||
// QPDF::GetAllObjects() enumerates all indirect objects.
|
// QPDF::GetAllObjects() enumerates all indirect objects.
|
||||||
@ -81,10 +79,9 @@ process(
|
|||||||
{
|
{
|
||||||
QPDF qpdf;
|
QPDF qpdf;
|
||||||
qpdf.processFile(fn.c_str());
|
qpdf.processFile(fn.c_str());
|
||||||
std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects();
|
|
||||||
std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
|
std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
|
||||||
|
|
||||||
for (auto const& oh: objs) {
|
for (auto const& oh: qpdf.getAllObjects()) {
|
||||||
if (xrefs.count(oh.getObjGen()) == 0) {
|
if (xrefs.count(oh.getObjGen()) == 0) {
|
||||||
std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
|
std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
|
||||||
<< " is not found in xref table" << std::endl;
|
<< " is not found in xref table" << std::endl;
|
||||||
|
@ -26,8 +26,7 @@ main(int argc, char* argv[])
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
char const* infilename = argv[1];
|
char const* infilename = argv[1];
|
||||||
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
|
for (auto const& line: QUtil::read_lines_from_file(infilename)) {
|
||||||
for (auto const& line: lines) {
|
|
||||||
QPDFObjectHandle str = QPDFObjectHandle::newString(line);
|
QPDFObjectHandle str = QPDFObjectHandle::newString(line);
|
||||||
std::cout << str.getUTF8Value() << std::endl;
|
std::cout << str.getUTF8Value() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ main(int argc, char* argv[])
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
char const* infilename = argv[1];
|
char const* infilename = argv[1];
|
||||||
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
|
for (auto const& line: QUtil::read_lines_from_file(infilename)) {
|
||||||
for (auto const& line: lines) {
|
|
||||||
QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
|
QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
|
||||||
std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
|
std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -198,10 +198,8 @@ process(char const* filename, bool include_ignorable, size_t max_len)
|
|||||||
// Tokenize content streams, skipping inline images
|
// Tokenize content streams, skipping inline images
|
||||||
QPDF qpdf;
|
QPDF qpdf;
|
||||||
qpdf.processFile(filename);
|
qpdf.processFile(filename);
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
|
||||||
QPDFPageDocumentHelper(qpdf).getAllPages();
|
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (auto& page: pages) {
|
for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) {
|
||||||
++pageno;
|
++pageno;
|
||||||
Pl_Buffer plb("buffer");
|
Pl_Buffer plb("buffer");
|
||||||
page.pipeContents(&plb);
|
page.pipeContents(&plb);
|
||||||
|
@ -19,9 +19,7 @@ main(int argc, char* argv[])
|
|||||||
QPDF qpdf;
|
QPDF qpdf;
|
||||||
qpdf.processFile(argv[1]);
|
qpdf.processFile(argv[1]);
|
||||||
|
|
||||||
std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable();
|
for (auto const& iter: qpdf.getXRefTable()) {
|
||||||
|
|
||||||
for (auto const& iter: xref) {
|
|
||||||
std::cout << iter.first.getObj() << "/" << iter.first.getGen()
|
std::cout << iter.first.getObj() << "/" << iter.first.getGen()
|
||||||
<< ", ";
|
<< ", ";
|
||||||
switch (iter.second.getType()) {
|
switch (iter.second.getType()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user