Commit bbe9f8b83c1e7d42f7e1f5b2ea613dc845a1de7c
Committed by
GitHub
Merge pull request #969 from m-holger/tidy
Code formating : drop 'this->' in 'this->m'
Showing
33 changed files
with
1473 additions
and
1574 deletions
include/qpdf/QPDFOutlineObjectHelper.hh
| @@ -42,7 +42,7 @@ class QPDFOutlineObjectHelper: public QPDFObjectHelper | @@ -42,7 +42,7 @@ class QPDFOutlineObjectHelper: public QPDFObjectHelper | ||
| 42 | { | 42 | { |
| 43 | // This must be cleared explicitly to avoid circular references | 43 | // This must be cleared explicitly to avoid circular references |
| 44 | // that prevent cleanup of pointer holders. | 44 | // that prevent cleanup of pointer holders. |
| 45 | - this->m->parent = nullptr; | 45 | + m->parent = nullptr; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | // All constructors are private. You can only create one of these | 48 | // All constructors are private. You can only create one of these |
libqpdf/Buffer.cc
| @@ -56,7 +56,7 @@ Buffer::Buffer(Buffer&& rhs) noexcept : | @@ -56,7 +56,7 @@ Buffer::Buffer(Buffer&& rhs) noexcept : | ||
| 56 | Buffer& | 56 | Buffer& |
| 57 | Buffer::operator=(Buffer&& rhs) noexcept | 57 | Buffer::operator=(Buffer&& rhs) noexcept |
| 58 | { | 58 | { |
| 59 | - std::swap(this->m, rhs.m); | 59 | + std::swap(m, rhs.m); |
| 60 | return *this; | 60 | return *this; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| @@ -64,10 +64,9 @@ void | @@ -64,10 +64,9 @@ void | ||
| 64 | Buffer::copy(Buffer const& rhs) | 64 | Buffer::copy(Buffer const& rhs) |
| 65 | { | 65 | { |
| 66 | if (this != &rhs) { | 66 | if (this != &rhs) { |
| 67 | - this->m = | ||
| 68 | - std::unique_ptr<Members>(new Members(rhs.m->size, nullptr, true)); | ||
| 69 | - if (this->m->size) { | ||
| 70 | - memcpy(this->m->buf, rhs.m->buf, this->m->size); | 67 | + m = std::unique_ptr<Members>(new Members(rhs.m->size, nullptr, true)); |
| 68 | + if (m->size) { | ||
| 69 | + memcpy(m->buf, rhs.m->buf, m->size); | ||
| 71 | } | 70 | } |
| 72 | } | 71 | } |
| 73 | } | 72 | } |
| @@ -75,17 +74,17 @@ Buffer::copy(Buffer const& rhs) | @@ -75,17 +74,17 @@ Buffer::copy(Buffer const& rhs) | ||
| 75 | size_t | 74 | size_t |
| 76 | Buffer::getSize() const | 75 | Buffer::getSize() const |
| 77 | { | 76 | { |
| 78 | - return this->m->size; | 77 | + return m->size; |
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | unsigned char const* | 80 | unsigned char const* |
| 82 | Buffer::getBuffer() const | 81 | Buffer::getBuffer() const |
| 83 | { | 82 | { |
| 84 | - return this->m->buf; | 83 | + return m->buf; |
| 85 | } | 84 | } |
| 86 | 85 | ||
| 87 | unsigned char* | 86 | unsigned char* |
| 88 | Buffer::getBuffer() | 87 | Buffer::getBuffer() |
| 89 | { | 88 | { |
| 90 | - return this->m->buf; | 89 | + return m->buf; |
| 91 | } | 90 | } |
libqpdf/JSON.cc
| @@ -197,10 +197,10 @@ JSON::JSON_blob::write(Pipeline* p, size_t) const | @@ -197,10 +197,10 @@ JSON::JSON_blob::write(Pipeline* p, size_t) const | ||
| 197 | void | 197 | void |
| 198 | JSON::write(Pipeline* p, size_t depth) const | 198 | JSON::write(Pipeline* p, size_t depth) const |
| 199 | { | 199 | { |
| 200 | - if (nullptr == this->m->value) { | 200 | + if (nullptr == m->value) { |
| 201 | *p << "null"; | 201 | *p << "null"; |
| 202 | } else { | 202 | } else { |
| 203 | - this->m->value->write(p, depth); | 203 | + m->value->write(p, depth); |
| 204 | } | 204 | } |
| 205 | } | 205 | } |
| 206 | 206 | ||
| @@ -282,7 +282,7 @@ JSON::makeDictionary() | @@ -282,7 +282,7 @@ JSON::makeDictionary() | ||
| 282 | JSON | 282 | JSON |
| 283 | JSON::addDictionaryMember(std::string const& key, JSON const& val) | 283 | JSON::addDictionaryMember(std::string const& key, JSON const& val) |
| 284 | { | 284 | { |
| 285 | - if (auto* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get())) { | 285 | + if (auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get())) { |
| 286 | return obj->members[encode_string(key)] = | 286 | return obj->members[encode_string(key)] = |
| 287 | val.m->value ? val : makeNull(); | 287 | val.m->value ? val : makeNull(); |
| 288 | } else { | 288 | } else { |
| @@ -294,7 +294,7 @@ JSON::addDictionaryMember(std::string const& key, JSON const& val) | @@ -294,7 +294,7 @@ JSON::addDictionaryMember(std::string const& key, JSON const& val) | ||
| 294 | bool | 294 | bool |
| 295 | JSON::checkDictionaryKeySeen(std::string const& key) | 295 | JSON::checkDictionaryKeySeen(std::string const& key) |
| 296 | { | 296 | { |
| 297 | - auto* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get()); | 297 | + auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get()); |
| 298 | if (nullptr == obj) { | 298 | if (nullptr == obj) { |
| 299 | throw std::logic_error( | 299 | throw std::logic_error( |
| 300 | "JSON::checkDictionaryKey called on non-dictionary"); | 300 | "JSON::checkDictionaryKey called on non-dictionary"); |
| @@ -315,7 +315,7 @@ JSON::makeArray() | @@ -315,7 +315,7 @@ JSON::makeArray() | ||
| 315 | JSON | 315 | JSON |
| 316 | JSON::addArrayElement(JSON const& val) | 316 | JSON::addArrayElement(JSON const& val) |
| 317 | { | 317 | { |
| 318 | - auto* arr = dynamic_cast<JSON_array*>(this->m->value.get()); | 318 | + auto* arr = dynamic_cast<JSON_array*>(m->value.get()); |
| 319 | if (nullptr == arr) { | 319 | if (nullptr == arr) { |
| 320 | throw std::runtime_error("JSON::addArrayElement called on non-array"); | 320 | throw std::runtime_error("JSON::addArrayElement called on non-array"); |
| 321 | } | 321 | } |
| @@ -385,7 +385,7 @@ bool | @@ -385,7 +385,7 @@ bool | ||
| 385 | JSON::getString(std::string& utf8) const | 385 | JSON::getString(std::string& utf8) const |
| 386 | { | 386 | { |
| 387 | if (m->value->type_code == vt_string) { | 387 | if (m->value->type_code == vt_string) { |
| 388 | - auto v = dynamic_cast<JSON_string const*>(this->m->value.get()); | 388 | + auto v = dynamic_cast<JSON_string const*>(m->value.get()); |
| 389 | utf8 = v->utf8; | 389 | utf8 = v->utf8; |
| 390 | return true; | 390 | return true; |
| 391 | } | 391 | } |
| @@ -396,7 +396,7 @@ bool | @@ -396,7 +396,7 @@ bool | ||
| 396 | JSON::getNumber(std::string& value) const | 396 | JSON::getNumber(std::string& value) const |
| 397 | { | 397 | { |
| 398 | if (m->value->type_code == vt_number) { | 398 | if (m->value->type_code == vt_number) { |
| 399 | - auto v = dynamic_cast<JSON_number const*>(this->m->value.get()); | 399 | + auto v = dynamic_cast<JSON_number const*>(m->value.get()); |
| 400 | value = v->encoded; | 400 | value = v->encoded; |
| 401 | return true; | 401 | return true; |
| 402 | } | 402 | } |
| @@ -407,7 +407,7 @@ bool | @@ -407,7 +407,7 @@ bool | ||
| 407 | JSON::getBool(bool& value) const | 407 | JSON::getBool(bool& value) const |
| 408 | { | 408 | { |
| 409 | if (m->value->type_code == vt_bool) { | 409 | if (m->value->type_code == vt_bool) { |
| 410 | - auto v = dynamic_cast<JSON_bool const*>(this->m->value.get()); | 410 | + auto v = dynamic_cast<JSON_bool const*>(m->value.get()); |
| 411 | value = v->value; | 411 | value = v->value; |
| 412 | return true; | 412 | return true; |
| 413 | } | 413 | } |
| @@ -424,7 +424,7 @@ bool | @@ -424,7 +424,7 @@ bool | ||
| 424 | JSON::forEachDictItem( | 424 | JSON::forEachDictItem( |
| 425 | std::function<void(std::string const& key, JSON value)> fn) const | 425 | std::function<void(std::string const& key, JSON value)> fn) const |
| 426 | { | 426 | { |
| 427 | - auto v = dynamic_cast<JSON_dictionary const*>(this->m->value.get()); | 427 | + auto v = dynamic_cast<JSON_dictionary const*>(m->value.get()); |
| 428 | if (v == nullptr) { | 428 | if (v == nullptr) { |
| 429 | return false; | 429 | return false; |
| 430 | } | 430 | } |
| @@ -437,7 +437,7 @@ JSON::forEachDictItem( | @@ -437,7 +437,7 @@ JSON::forEachDictItem( | ||
| 437 | bool | 437 | bool |
| 438 | JSON::forEachArrayItem(std::function<void(JSON value)> fn) const | 438 | JSON::forEachArrayItem(std::function<void(JSON value)> fn) const |
| 439 | { | 439 | { |
| 440 | - auto v = dynamic_cast<JSON_array const*>(this->m->value.get()); | 440 | + auto v = dynamic_cast<JSON_array const*>(m->value.get()); |
| 441 | if (v == nullptr) { | 441 | if (v == nullptr) { |
| 442 | return false; | 442 | return false; |
| 443 | } | 443 | } |
| @@ -451,7 +451,7 @@ bool | @@ -451,7 +451,7 @@ bool | ||
| 451 | JSON::checkSchema(JSON schema, std::list<std::string>& errors) | 451 | JSON::checkSchema(JSON schema, std::list<std::string>& errors) |
| 452 | { | 452 | { |
| 453 | return checkSchemaInternal( | 453 | return checkSchemaInternal( |
| 454 | - this->m->value.get(), schema.m->value.get(), 0, errors, ""); | 454 | + m->value.get(), schema.m->value.get(), 0, errors, ""); |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | bool | 457 | bool |
| @@ -459,7 +459,7 @@ JSON::checkSchema( | @@ -459,7 +459,7 @@ JSON::checkSchema( | ||
| 459 | JSON schema, unsigned long flags, std::list<std::string>& errors) | 459 | JSON schema, unsigned long flags, std::list<std::string>& errors) |
| 460 | { | 460 | { |
| 461 | return checkSchemaInternal( | 461 | return checkSchemaInternal( |
| 462 | - this->m->value.get(), schema.m->value.get(), flags, errors, ""); | 462 | + m->value.get(), schema.m->value.get(), flags, errors, ""); |
| 463 | } | 463 | } |
| 464 | 464 | ||
| 465 | bool | 465 | bool |
| @@ -1429,23 +1429,23 @@ JSON::parse(std::string const& s) | @@ -1429,23 +1429,23 @@ JSON::parse(std::string const& s) | ||
| 1429 | void | 1429 | void |
| 1430 | JSON::setStart(qpdf_offset_t start) | 1430 | JSON::setStart(qpdf_offset_t start) |
| 1431 | { | 1431 | { |
| 1432 | - this->m->start = start; | 1432 | + m->start = start; |
| 1433 | } | 1433 | } |
| 1434 | 1434 | ||
| 1435 | void | 1435 | void |
| 1436 | JSON::setEnd(qpdf_offset_t end) | 1436 | JSON::setEnd(qpdf_offset_t end) |
| 1437 | { | 1437 | { |
| 1438 | - this->m->end = end; | 1438 | + m->end = end; |
| 1439 | } | 1439 | } |
| 1440 | 1440 | ||
| 1441 | qpdf_offset_t | 1441 | qpdf_offset_t |
| 1442 | JSON::getStart() const | 1442 | JSON::getStart() const |
| 1443 | { | 1443 | { |
| 1444 | - return this->m->start; | 1444 | + return m->start; |
| 1445 | } | 1445 | } |
| 1446 | 1446 | ||
| 1447 | qpdf_offset_t | 1447 | qpdf_offset_t |
| 1448 | JSON::getEnd() const | 1448 | JSON::getEnd() const |
| 1449 | { | 1449 | { |
| 1450 | - return this->m->end; | 1450 | + return m->end; |
| 1451 | } | 1451 | } |
libqpdf/JSONHandler.cc
| @@ -18,51 +18,51 @@ JSONHandler::usage(std::string const& msg) | @@ -18,51 +18,51 @@ JSONHandler::usage(std::string const& msg) | ||
| 18 | void | 18 | void |
| 19 | JSONHandler::addAnyHandler(json_handler_t fn) | 19 | JSONHandler::addAnyHandler(json_handler_t fn) |
| 20 | { | 20 | { |
| 21 | - this->m->h.any_handler = fn; | 21 | + m->h.any_handler = fn; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | void | 24 | void |
| 25 | JSONHandler::addNullHandler(void_handler_t fn) | 25 | JSONHandler::addNullHandler(void_handler_t fn) |
| 26 | { | 26 | { |
| 27 | - this->m->h.null_handler = fn; | 27 | + m->h.null_handler = fn; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | void | 30 | void |
| 31 | JSONHandler::addStringHandler(string_handler_t fn) | 31 | JSONHandler::addStringHandler(string_handler_t fn) |
| 32 | { | 32 | { |
| 33 | - this->m->h.string_handler = fn; | 33 | + m->h.string_handler = fn; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | void | 36 | void |
| 37 | JSONHandler::addNumberHandler(string_handler_t fn) | 37 | JSONHandler::addNumberHandler(string_handler_t fn) |
| 38 | { | 38 | { |
| 39 | - this->m->h.number_handler = fn; | 39 | + m->h.number_handler = fn; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | void | 42 | void |
| 43 | JSONHandler::addBoolHandler(bool_handler_t fn) | 43 | JSONHandler::addBoolHandler(bool_handler_t fn) |
| 44 | { | 44 | { |
| 45 | - this->m->h.bool_handler = fn; | 45 | + m->h.bool_handler = fn; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void | 48 | void |
| 49 | JSONHandler::addDictHandlers(json_handler_t start_fn, void_handler_t end_fn) | 49 | JSONHandler::addDictHandlers(json_handler_t start_fn, void_handler_t end_fn) |
| 50 | { | 50 | { |
| 51 | - this->m->h.dict_start_handler = start_fn; | ||
| 52 | - this->m->h.dict_end_handler = end_fn; | 51 | + m->h.dict_start_handler = start_fn; |
| 52 | + m->h.dict_end_handler = end_fn; | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | void | 55 | void |
| 56 | JSONHandler::addDictKeyHandler( | 56 | JSONHandler::addDictKeyHandler( |
| 57 | std::string const& key, std::shared_ptr<JSONHandler> dkh) | 57 | std::string const& key, std::shared_ptr<JSONHandler> dkh) |
| 58 | { | 58 | { |
| 59 | - this->m->h.dict_handlers[key] = dkh; | 59 | + m->h.dict_handlers[key] = dkh; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | void | 62 | void |
| 63 | JSONHandler::addFallbackDictHandler(std::shared_ptr<JSONHandler> fdh) | 63 | JSONHandler::addFallbackDictHandler(std::shared_ptr<JSONHandler> fdh) |
| 64 | { | 64 | { |
| 65 | - this->m->h.fallback_dict_handler = fdh; | 65 | + m->h.fallback_dict_handler = fdh; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | void | 68 | void |
| @@ -71,71 +71,71 @@ JSONHandler::addArrayHandlers( | @@ -71,71 +71,71 @@ JSONHandler::addArrayHandlers( | ||
| 71 | void_handler_t end_fn, | 71 | void_handler_t end_fn, |
| 72 | std::shared_ptr<JSONHandler> ah) | 72 | std::shared_ptr<JSONHandler> ah) |
| 73 | { | 73 | { |
| 74 | - this->m->h.array_start_handler = start_fn; | ||
| 75 | - this->m->h.array_end_handler = end_fn; | ||
| 76 | - this->m->h.array_item_handler = ah; | 74 | + m->h.array_start_handler = start_fn; |
| 75 | + m->h.array_end_handler = end_fn; | ||
| 76 | + m->h.array_item_handler = ah; | ||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | void | 79 | void |
| 80 | JSONHandler::handle(std::string const& path, JSON j) | 80 | JSONHandler::handle(std::string const& path, JSON j) |
| 81 | { | 81 | { |
| 82 | - if (this->m->h.any_handler) { | ||
| 83 | - this->m->h.any_handler(path, j); | 82 | + if (m->h.any_handler) { |
| 83 | + m->h.any_handler(path, j); | ||
| 84 | return; | 84 | return; |
| 85 | } | 85 | } |
| 86 | bool handled = false; | 86 | bool handled = false; |
| 87 | bool bvalue = false; | 87 | bool bvalue = false; |
| 88 | std::string s_value; | 88 | std::string s_value; |
| 89 | - if (this->m->h.null_handler && j.isNull()) { | ||
| 90 | - this->m->h.null_handler(path); | 89 | + if (m->h.null_handler && j.isNull()) { |
| 90 | + m->h.null_handler(path); | ||
| 91 | handled = true; | 91 | handled = true; |
| 92 | } | 92 | } |
| 93 | - if (this->m->h.string_handler && j.getString(s_value)) { | ||
| 94 | - this->m->h.string_handler(path, s_value); | 93 | + if (m->h.string_handler && j.getString(s_value)) { |
| 94 | + m->h.string_handler(path, s_value); | ||
| 95 | handled = true; | 95 | handled = true; |
| 96 | } | 96 | } |
| 97 | - if (this->m->h.number_handler && j.getNumber(s_value)) { | ||
| 98 | - this->m->h.number_handler(path, s_value); | 97 | + if (m->h.number_handler && j.getNumber(s_value)) { |
| 98 | + m->h.number_handler(path, s_value); | ||
| 99 | handled = true; | 99 | handled = true; |
| 100 | } | 100 | } |
| 101 | - if (this->m->h.bool_handler && j.getBool(bvalue)) { | ||
| 102 | - this->m->h.bool_handler(path, bvalue); | 101 | + if (m->h.bool_handler && j.getBool(bvalue)) { |
| 102 | + m->h.bool_handler(path, bvalue); | ||
| 103 | handled = true; | 103 | handled = true; |
| 104 | } | 104 | } |
| 105 | - if (this->m->h.dict_start_handler && j.isDictionary()) { | ||
| 106 | - this->m->h.dict_start_handler(path, j); | 105 | + if (m->h.dict_start_handler && j.isDictionary()) { |
| 106 | + m->h.dict_start_handler(path, j); | ||
| 107 | std::string path_base = path; | 107 | std::string path_base = path; |
| 108 | if (path_base != ".") { | 108 | if (path_base != ".") { |
| 109 | path_base += "."; | 109 | path_base += "."; |
| 110 | } | 110 | } |
| 111 | - j.forEachDictItem([&path, &path_base, this]( | ||
| 112 | - std::string const& k, JSON v) { | ||
| 113 | - auto i = this->m->h.dict_handlers.find(k); | ||
| 114 | - if (i == this->m->h.dict_handlers.end()) { | ||
| 115 | - if (this->m->h.fallback_dict_handler.get()) { | ||
| 116 | - this->m->h.fallback_dict_handler->handle(path_base + k, v); | 111 | + j.forEachDictItem( |
| 112 | + [&path, &path_base, this](std::string const& k, JSON v) { | ||
| 113 | + auto i = m->h.dict_handlers.find(k); | ||
| 114 | + if (i == m->h.dict_handlers.end()) { | ||
| 115 | + if (m->h.fallback_dict_handler.get()) { | ||
| 116 | + m->h.fallback_dict_handler->handle(path_base + k, v); | ||
| 117 | + } else { | ||
| 118 | + QTC::TC("libtests", "JSONHandler unexpected key"); | ||
| 119 | + usage( | ||
| 120 | + "JSON handler found unexpected key " + k + | ||
| 121 | + " in object at " + path); | ||
| 122 | + } | ||
| 117 | } else { | 123 | } else { |
| 118 | - QTC::TC("libtests", "JSONHandler unexpected key"); | ||
| 119 | - usage( | ||
| 120 | - "JSON handler found unexpected key " + k + | ||
| 121 | - " in object at " + path); | 124 | + i->second->handle(path_base + k, v); |
| 122 | } | 125 | } |
| 123 | - } else { | ||
| 124 | - i->second->handle(path_base + k, v); | ||
| 125 | - } | ||
| 126 | - }); | ||
| 127 | - this->m->h.dict_end_handler(path); | 126 | + }); |
| 127 | + m->h.dict_end_handler(path); | ||
| 128 | handled = true; | 128 | handled = true; |
| 129 | } | 129 | } |
| 130 | - if (this->m->h.array_start_handler && j.isArray()) { | ||
| 131 | - this->m->h.array_start_handler(path, j); | 130 | + if (m->h.array_start_handler && j.isArray()) { |
| 131 | + m->h.array_start_handler(path, j); | ||
| 132 | size_t i = 0; | 132 | size_t i = 0; |
| 133 | j.forEachArrayItem([&i, &path, this](JSON v) { | 133 | j.forEachArrayItem([&i, &path, this](JSON v) { |
| 134 | - this->m->h.array_item_handler->handle( | 134 | + m->h.array_item_handler->handle( |
| 135 | path + "[" + std::to_string(i) + "]", v); | 135 | path + "[" + std::to_string(i) + "]", v); |
| 136 | ++i; | 136 | ++i; |
| 137 | }); | 137 | }); |
| 138 | - this->m->h.array_end_handler(path); | 138 | + m->h.array_end_handler(path); |
| 139 | handled = true; | 139 | handled = true; |
| 140 | } | 140 | } |
| 141 | 141 |
libqpdf/Pl_Buffer.cc
| @@ -20,8 +20,8 @@ Pl_Buffer::~Pl_Buffer() | @@ -20,8 +20,8 @@ Pl_Buffer::~Pl_Buffer() | ||
| 20 | void | 20 | void |
| 21 | Pl_Buffer::write(unsigned char const* buf, size_t len) | 21 | Pl_Buffer::write(unsigned char const* buf, size_t len) |
| 22 | { | 22 | { |
| 23 | - this->m->data.append(buf, len); | ||
| 24 | - this->m->ready = false; | 23 | + m->data.append(buf, len); |
| 24 | + m->ready = false; | ||
| 25 | 25 | ||
| 26 | if (getNext(true)) { | 26 | if (getNext(true)) { |
| 27 | getNext()->write(buf, len); | 27 | getNext()->write(buf, len); |
| @@ -31,7 +31,7 @@ Pl_Buffer::write(unsigned char const* buf, size_t len) | @@ -31,7 +31,7 @@ Pl_Buffer::write(unsigned char const* buf, size_t len) | ||
| 31 | void | 31 | void |
| 32 | Pl_Buffer::finish() | 32 | Pl_Buffer::finish() |
| 33 | { | 33 | { |
| 34 | - this->m->ready = true; | 34 | + m->ready = true; |
| 35 | if (getNext(true)) { | 35 | if (getNext(true)) { |
| 36 | getNext()->finish(); | 36 | getNext()->finish(); |
| 37 | } | 37 | } |
| @@ -40,17 +40,17 @@ Pl_Buffer::finish() | @@ -40,17 +40,17 @@ Pl_Buffer::finish() | ||
| 40 | Buffer* | 40 | Buffer* |
| 41 | Pl_Buffer::getBuffer() | 41 | Pl_Buffer::getBuffer() |
| 42 | { | 42 | { |
| 43 | - if (!this->m->ready) { | 43 | + if (!m->ready) { |
| 44 | throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); | 44 | throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | - auto size = this->m->data.length(); | 47 | + auto size = m->data.length(); |
| 48 | auto* b = new Buffer(size); | 48 | auto* b = new Buffer(size); |
| 49 | if (size > 0) { | 49 | if (size > 0) { |
| 50 | unsigned char* p = b->getBuffer(); | 50 | unsigned char* p = b->getBuffer(); |
| 51 | - memcpy(p, this->m->data.data(), size); | 51 | + memcpy(p, m->data.data(), size); |
| 52 | } | 52 | } |
| 53 | - this->m->data.clear(); | 53 | + m->data.clear(); |
| 54 | return b; | 54 | return b; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| @@ -63,17 +63,17 @@ Pl_Buffer::getBufferSharedPointer() | @@ -63,17 +63,17 @@ Pl_Buffer::getBufferSharedPointer() | ||
| 63 | void | 63 | void |
| 64 | Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len) | 64 | Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len) |
| 65 | { | 65 | { |
| 66 | - if (!this->m->ready) { | 66 | + if (!m->ready) { |
| 67 | throw std::logic_error( | 67 | throw std::logic_error( |
| 68 | "Pl_Buffer::getMallocBuffer() called when not ready"); | 68 | "Pl_Buffer::getMallocBuffer() called when not ready"); |
| 69 | } | 69 | } |
| 70 | - auto size = this->m->data.length(); | 70 | + auto size = m->data.length(); |
| 71 | *len = size; | 71 | *len = size; |
| 72 | if (size > 0) { | 72 | if (size > 0) { |
| 73 | *buf = reinterpret_cast<unsigned char*>(malloc(size)); | 73 | *buf = reinterpret_cast<unsigned char*>(malloc(size)); |
| 74 | - memcpy(*buf, this->m->data.data(), size); | 74 | + memcpy(*buf, m->data.data(), size); |
| 75 | } else { | 75 | } else { |
| 76 | *buf = nullptr; | 76 | *buf = nullptr; |
| 77 | } | 77 | } |
| 78 | - this->m->data.clear(); | 78 | + m->data.clear(); |
| 79 | } | 79 | } |
libqpdf/Pl_Count.cc
| @@ -24,8 +24,8 @@ void | @@ -24,8 +24,8 @@ void | ||
| 24 | Pl_Count::write(unsigned char const* buf, size_t len) | 24 | Pl_Count::write(unsigned char const* buf, size_t len) |
| 25 | { | 25 | { |
| 26 | if (len) { | 26 | if (len) { |
| 27 | - this->m->count += QIntC::to_offset(len); | ||
| 28 | - this->m->last_char = buf[len - 1]; | 27 | + m->count += QIntC::to_offset(len); |
| 28 | + m->last_char = buf[len - 1]; | ||
| 29 | getNext()->write(buf, len); | 29 | getNext()->write(buf, len); |
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| @@ -39,11 +39,11 @@ Pl_Count::finish() | @@ -39,11 +39,11 @@ Pl_Count::finish() | ||
| 39 | qpdf_offset_t | 39 | qpdf_offset_t |
| 40 | Pl_Count::getCount() const | 40 | Pl_Count::getCount() const |
| 41 | { | 41 | { |
| 42 | - return this->m->count; | 42 | + return m->count; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | unsigned char | 45 | unsigned char |
| 46 | Pl_Count::getLastChar() const | 46 | Pl_Count::getLastChar() const |
| 47 | { | 47 | { |
| 48 | - return this->m->last_char; | 48 | + return m->last_char; |
| 49 | } | 49 | } |
libqpdf/Pl_DCT.cc
| @@ -84,18 +84,18 @@ Pl_DCT::~Pl_DCT() | @@ -84,18 +84,18 @@ Pl_DCT::~Pl_DCT() | ||
| 84 | void | 84 | void |
| 85 | Pl_DCT::write(unsigned char const* data, size_t len) | 85 | Pl_DCT::write(unsigned char const* data, size_t len) |
| 86 | { | 86 | { |
| 87 | - this->m->buf.write(data, len); | 87 | + m->buf.write(data, len); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | void | 90 | void |
| 91 | Pl_DCT::finish() | 91 | Pl_DCT::finish() |
| 92 | { | 92 | { |
| 93 | - this->m->buf.finish(); | 93 | + m->buf.finish(); |
| 94 | 94 | ||
| 95 | // Using a std::shared_ptr<Buffer> here and passing it into compress | 95 | // Using a std::shared_ptr<Buffer> here and passing it into compress |
| 96 | // and decompress causes a memory leak with setjmp/longjmp. Just | 96 | // and decompress causes a memory leak with setjmp/longjmp. Just |
| 97 | // use a pointer and delete it. | 97 | // use a pointer and delete it. |
| 98 | - Buffer* b = this->m->buf.getBuffer(); | 98 | + Buffer* b = m->buf.getBuffer(); |
| 99 | if (b->getSize() == 0) { | 99 | if (b->getSize() == 0) { |
| 100 | // Special case: empty data will never succeed and probably | 100 | // Special case: empty data will never succeed and probably |
| 101 | // means we're calling finish a second time from an exception | 101 | // means we're calling finish a second time from an exception |
| @@ -118,7 +118,7 @@ Pl_DCT::finish() | @@ -118,7 +118,7 @@ Pl_DCT::finish() | ||
| 118 | // for exception handling. | 118 | // for exception handling. |
| 119 | if (setjmp(jerr.jmpbuf) == 0) { | 119 | if (setjmp(jerr.jmpbuf) == 0) { |
| 120 | try { | 120 | try { |
| 121 | - if (this->m->action == a_compress) { | 121 | + if (m->action == a_compress) { |
| 122 | compress(reinterpret_cast<void*>(&cinfo_compress), b); | 122 | compress(reinterpret_cast<void*>(&cinfo_compress), b); |
| 123 | } else { | 123 | } else { |
| 124 | decompress(reinterpret_cast<void*>(&cinfo_decompress), b); | 124 | decompress(reinterpret_cast<void*>(&cinfo_decompress), b); |
| @@ -135,10 +135,10 @@ Pl_DCT::finish() | @@ -135,10 +135,10 @@ Pl_DCT::finish() | ||
| 135 | } | 135 | } |
| 136 | delete b; | 136 | delete b; |
| 137 | 137 | ||
| 138 | - if (this->m->action == a_compress) { | 138 | + if (m->action == a_compress) { |
| 139 | jpeg_destroy_compress(&cinfo_compress); | 139 | jpeg_destroy_compress(&cinfo_compress); |
| 140 | } | 140 | } |
| 141 | - if (this->m->action == a_decompress) { | 141 | + if (m->action == a_decompress) { |
| 142 | jpeg_destroy_decompress(&cinfo_decompress); | 142 | jpeg_destroy_decompress(&cinfo_decompress); |
| 143 | } | 143 | } |
| 144 | if (error) { | 144 | if (error) { |
| @@ -279,13 +279,13 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) | @@ -279,13 +279,13 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) | ||
| 279 | unsigned char* outbuffer = outbuffer_ph.get(); | 279 | unsigned char* outbuffer = outbuffer_ph.get(); |
| 280 | jpeg_pipeline_dest(cinfo, outbuffer, BUF_SIZE, this->getNext()); | 280 | jpeg_pipeline_dest(cinfo, outbuffer, BUF_SIZE, this->getNext()); |
| 281 | 281 | ||
| 282 | - cinfo->image_width = this->m->image_width; | ||
| 283 | - cinfo->image_height = this->m->image_height; | ||
| 284 | - cinfo->input_components = this->m->components; | ||
| 285 | - cinfo->in_color_space = this->m->color_space; | 282 | + cinfo->image_width = m->image_width; |
| 283 | + cinfo->image_height = m->image_height; | ||
| 284 | + cinfo->input_components = m->components; | ||
| 285 | + cinfo->in_color_space = m->color_space; | ||
| 286 | jpeg_set_defaults(cinfo); | 286 | jpeg_set_defaults(cinfo); |
| 287 | - if (this->m->config_callback) { | ||
| 288 | - this->m->config_callback->apply(cinfo); | 287 | + if (m->config_callback) { |
| 288 | + m->config_callback->apply(cinfo); | ||
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | jpeg_start_compress(cinfo, TRUE); | 291 | jpeg_start_compress(cinfo, TRUE); |
libqpdf/Pl_Flate.cc
| @@ -72,21 +72,21 @@ Pl_Flate::~Pl_Flate() | @@ -72,21 +72,21 @@ Pl_Flate::~Pl_Flate() | ||
| 72 | void | 72 | void |
| 73 | Pl_Flate::setWarnCallback(std::function<void(char const*, int)> callback) | 73 | Pl_Flate::setWarnCallback(std::function<void(char const*, int)> callback) |
| 74 | { | 74 | { |
| 75 | - this->m->callback = callback; | 75 | + m->callback = callback; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | void | 78 | void |
| 79 | Pl_Flate::warn(char const* msg, int code) | 79 | Pl_Flate::warn(char const* msg, int code) |
| 80 | { | 80 | { |
| 81 | - if (this->m->callback != nullptr) { | ||
| 82 | - this->m->callback(msg, code); | 81 | + if (m->callback != nullptr) { |
| 82 | + m->callback(msg, code); | ||
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | void | 86 | void |
| 87 | Pl_Flate::write(unsigned char const* data, size_t len) | 87 | Pl_Flate::write(unsigned char const* data, size_t len) |
| 88 | { | 88 | { |
| 89 | - if (this->m->outbuf == nullptr) { | 89 | + if (m->outbuf == nullptr) { |
| 90 | throw std::logic_error( | 90 | throw std::logic_error( |
| 91 | this->identifier + | 91 | this->identifier + |
| 92 | ": Pl_Flate: write() called after finish() called"); | 92 | ": Pl_Flate: write() called after finish() called"); |
| @@ -100,9 +100,7 @@ Pl_Flate::write(unsigned char const* data, size_t len) | @@ -100,9 +100,7 @@ Pl_Flate::write(unsigned char const* data, size_t len) | ||
| 100 | while (bytes_left > 0) { | 100 | while (bytes_left > 0) { |
| 101 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 101 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 102 | handleData( | 102 | handleData( |
| 103 | - buf, | ||
| 104 | - bytes, | ||
| 105 | - (this->m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); | 103 | + buf, bytes, (m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); |
| 106 | bytes_left -= bytes; | 104 | bytes_left -= bytes; |
| 107 | buf += bytes; | 105 | buf += bytes; |
| 108 | } | 106 | } |
| @@ -115,13 +113,13 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -115,13 +113,13 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 115 | throw std::runtime_error("Pl_Flate: zlib doesn't support data" | 113 | throw std::runtime_error("Pl_Flate: zlib doesn't support data" |
| 116 | " blocks larger than int"); | 114 | " blocks larger than int"); |
| 117 | } | 115 | } |
| 118 | - z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); | 116 | + z_stream& zstream = *(static_cast<z_stream*>(m->zdata)); |
| 119 | // zlib is known not to modify the data pointed to by next_in but | 117 | // zlib is known not to modify the data pointed to by next_in but |
| 120 | // doesn't declare the field value const unless compiled to do so. | 118 | // doesn't declare the field value const unless compiled to do so. |
| 121 | zstream.next_in = const_cast<unsigned char*>(data); | 119 | zstream.next_in = const_cast<unsigned char*>(data); |
| 122 | zstream.avail_in = QIntC::to_uint(len); | 120 | zstream.avail_in = QIntC::to_uint(len); |
| 123 | 121 | ||
| 124 | - if (!this->m->initialized) { | 122 | + if (!m->initialized) { |
| 125 | int err = Z_OK; | 123 | int err = Z_OK; |
| 126 | 124 | ||
| 127 | // deflateInit and inflateInit are macros that use old-style | 125 | // deflateInit and inflateInit are macros that use old-style |
| @@ -132,7 +130,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -132,7 +130,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 132 | # pragma GCC diagnostic push | 130 | # pragma GCC diagnostic push |
| 133 | # pragma GCC diagnostic ignored "-Wold-style-cast" | 131 | # pragma GCC diagnostic ignored "-Wold-style-cast" |
| 134 | #endif | 132 | #endif |
| 135 | - if (this->m->action == a_deflate) { | 133 | + if (m->action == a_deflate) { |
| 136 | err = deflateInit(&zstream, compression_level); | 134 | err = deflateInit(&zstream, compression_level); |
| 137 | } else { | 135 | } else { |
| 138 | err = inflateInit(&zstream); | 136 | err = inflateInit(&zstream); |
| @@ -144,19 +142,19 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -144,19 +142,19 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 144 | #endif | 142 | #endif |
| 145 | 143 | ||
| 146 | checkError("Init", err); | 144 | checkError("Init", err); |
| 147 | - this->m->initialized = true; | 145 | + m->initialized = true; |
| 148 | } | 146 | } |
| 149 | 147 | ||
| 150 | int err = Z_OK; | 148 | int err = Z_OK; |
| 151 | 149 | ||
| 152 | bool done = false; | 150 | bool done = false; |
| 153 | while (!done) { | 151 | while (!done) { |
| 154 | - if (this->m->action == a_deflate) { | 152 | + if (m->action == a_deflate) { |
| 155 | err = deflate(&zstream, flush); | 153 | err = deflate(&zstream, flush); |
| 156 | } else { | 154 | } else { |
| 157 | err = inflate(&zstream, flush); | 155 | err = inflate(&zstream, flush); |
| 158 | } | 156 | } |
| 159 | - if ((this->m->action == a_inflate) && (err != Z_OK) && zstream.msg && | 157 | + if ((m->action == a_inflate) && (err != Z_OK) && zstream.msg && |
| 160 | (strcmp(zstream.msg, "incorrect data check") == 0)) { | 158 | (strcmp(zstream.msg, "incorrect data check") == 0)) { |
| 161 | // Other PDF readers ignore this specific error. Combining | 159 | // Other PDF readers ignore this specific error. Combining |
| 162 | // this with Z_SYNC_FLUSH enables qpdf to handle some | 160 | // this with Z_SYNC_FLUSH enables qpdf to handle some |
| @@ -191,11 +189,11 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -191,11 +189,11 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 191 | done = true; | 189 | done = true; |
| 192 | } | 190 | } |
| 193 | uLong ready = | 191 | uLong ready = |
| 194 | - QIntC::to_ulong(this->m->out_bufsize - zstream.avail_out); | 192 | + QIntC::to_ulong(m->out_bufsize - zstream.avail_out); |
| 195 | if (ready > 0) { | 193 | if (ready > 0) { |
| 196 | - this->getNext()->write(this->m->outbuf.get(), ready); | ||
| 197 | - zstream.next_out = this->m->outbuf.get(); | ||
| 198 | - zstream.avail_out = QIntC::to_uint(this->m->out_bufsize); | 194 | + this->getNext()->write(m->outbuf.get(), ready); |
| 195 | + zstream.next_out = m->outbuf.get(); | ||
| 196 | + zstream.avail_out = QIntC::to_uint(m->out_bufsize); | ||
| 199 | } | 197 | } |
| 200 | } | 198 | } |
| 201 | break; | 199 | break; |
| @@ -211,23 +209,23 @@ void | @@ -211,23 +209,23 @@ void | ||
| 211 | Pl_Flate::finish() | 209 | Pl_Flate::finish() |
| 212 | { | 210 | { |
| 213 | try { | 211 | try { |
| 214 | - if (this->m->outbuf.get()) { | ||
| 215 | - if (this->m->initialized) { | ||
| 216 | - z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); | 212 | + if (m->outbuf.get()) { |
| 213 | + if (m->initialized) { | ||
| 214 | + z_stream& zstream = *(static_cast<z_stream*>(m->zdata)); | ||
| 217 | unsigned char buf[1]; | 215 | unsigned char buf[1]; |
| 218 | buf[0] = '\0'; | 216 | buf[0] = '\0'; |
| 219 | handleData(buf, 0, Z_FINISH); | 217 | handleData(buf, 0, Z_FINISH); |
| 220 | int err = Z_OK; | 218 | int err = Z_OK; |
| 221 | - if (this->m->action == a_deflate) { | 219 | + if (m->action == a_deflate) { |
| 222 | err = deflateEnd(&zstream); | 220 | err = deflateEnd(&zstream); |
| 223 | } else { | 221 | } else { |
| 224 | err = inflateEnd(&zstream); | 222 | err = inflateEnd(&zstream); |
| 225 | } | 223 | } |
| 226 | - this->m->initialized = false; | 224 | + m->initialized = false; |
| 227 | checkError("End", err); | 225 | checkError("End", err); |
| 228 | } | 226 | } |
| 229 | 227 | ||
| 230 | - this->m->outbuf = nullptr; | 228 | + m->outbuf = nullptr; |
| 231 | } | 229 | } |
| 232 | } catch (std::exception& e) { | 230 | } catch (std::exception& e) { |
| 233 | try { | 231 | try { |
| @@ -249,10 +247,10 @@ Pl_Flate::setCompressionLevel(int level) | @@ -249,10 +247,10 @@ Pl_Flate::setCompressionLevel(int level) | ||
| 249 | void | 247 | void |
| 250 | Pl_Flate::checkError(char const* prefix, int error_code) | 248 | Pl_Flate::checkError(char const* prefix, int error_code) |
| 251 | { | 249 | { |
| 252 | - z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); | 250 | + z_stream& zstream = *(static_cast<z_stream*>(m->zdata)); |
| 253 | if (error_code != Z_OK) { | 251 | if (error_code != Z_OK) { |
| 254 | char const* action_str = | 252 | char const* action_str = |
| 255 | - (this->m->action == a_deflate ? "deflate" : "inflate"); | 253 | + (m->action == a_deflate ? "deflate" : "inflate"); |
| 256 | std::string msg = | 254 | std::string msg = |
| 257 | this->identifier + ": " + action_str + ": " + prefix + ": "; | 255 | this->identifier + ": " + action_str + ": " + prefix + ": "; |
| 258 | 256 |
libqpdf/Pl_Function.cc
| @@ -52,7 +52,7 @@ Pl_Function::~Pl_Function() | @@ -52,7 +52,7 @@ Pl_Function::~Pl_Function() | ||
| 52 | void | 52 | void |
| 53 | Pl_Function::write(unsigned char const* buf, size_t len) | 53 | Pl_Function::write(unsigned char const* buf, size_t len) |
| 54 | { | 54 | { |
| 55 | - this->m->fn(buf, len); | 55 | + m->fn(buf, len); |
| 56 | if (getNext(true)) { | 56 | if (getNext(true)) { |
| 57 | getNext()->write(buf, len); | 57 | getNext()->write(buf, len); |
| 58 | } | 58 | } |
libqpdf/Pl_OStream.cc
| @@ -22,12 +22,12 @@ Pl_OStream::~Pl_OStream() | @@ -22,12 +22,12 @@ Pl_OStream::~Pl_OStream() | ||
| 22 | void | 22 | void |
| 23 | Pl_OStream::write(unsigned char const* buf, size_t len) | 23 | Pl_OStream::write(unsigned char const* buf, size_t len) |
| 24 | { | 24 | { |
| 25 | - this->m->os.write( | 25 | + m->os.write( |
| 26 | reinterpret_cast<char const*>(buf), static_cast<std::streamsize>(len)); | 26 | reinterpret_cast<char const*>(buf), static_cast<std::streamsize>(len)); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | void | 29 | void |
| 30 | Pl_OStream::finish() | 30 | Pl_OStream::finish() |
| 31 | { | 31 | { |
| 32 | - this->m->os.flush(); | 32 | + m->os.flush(); |
| 33 | } | 33 | } |
libqpdf/Pl_QPDFTokenizer.cc
| @@ -33,37 +33,36 @@ Pl_QPDFTokenizer::~Pl_QPDFTokenizer() | @@ -33,37 +33,36 @@ Pl_QPDFTokenizer::~Pl_QPDFTokenizer() | ||
| 33 | void | 33 | void |
| 34 | Pl_QPDFTokenizer::write(unsigned char const* data, size_t len) | 34 | Pl_QPDFTokenizer::write(unsigned char const* data, size_t len) |
| 35 | { | 35 | { |
| 36 | - this->m->buf.write(data, len); | 36 | + m->buf.write(data, len); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void | 39 | void |
| 40 | Pl_QPDFTokenizer::finish() | 40 | Pl_QPDFTokenizer::finish() |
| 41 | { | 41 | { |
| 42 | - this->m->buf.finish(); | 42 | + m->buf.finish(); |
| 43 | auto input = std::shared_ptr<InputSource>( | 43 | auto input = std::shared_ptr<InputSource>( |
| 44 | // line-break | 44 | // line-break |
| 45 | - new BufferInputSource( | ||
| 46 | - "tokenizer data", this->m->buf.getBuffer(), true)); | 45 | + new BufferInputSource("tokenizer data", m->buf.getBuffer(), true)); |
| 47 | 46 | ||
| 48 | while (true) { | 47 | while (true) { |
| 49 | - QPDFTokenizer::Token token = this->m->tokenizer.readToken( | 48 | + QPDFTokenizer::Token token = m->tokenizer.readToken( |
| 50 | input, "offset " + std::to_string(input->tell()), true); | 49 | input, "offset " + std::to_string(input->tell()), true); |
| 51 | - this->m->filter->handleToken(token); | 50 | + m->filter->handleToken(token); |
| 52 | if (token.getType() == QPDFTokenizer::tt_eof) { | 51 | if (token.getType() == QPDFTokenizer::tt_eof) { |
| 53 | break; | 52 | break; |
| 54 | } else if (token.isWord("ID")) { | 53 | } else if (token.isWord("ID")) { |
| 55 | // Read the space after the ID. | 54 | // Read the space after the ID. |
| 56 | char ch = ' '; | 55 | char ch = ' '; |
| 57 | input->read(&ch, 1); | 56 | input->read(&ch, 1); |
| 58 | - this->m->filter->handleToken( | 57 | + m->filter->handleToken( |
| 59 | // line-break | 58 | // line-break |
| 60 | QPDFTokenizer::Token( | 59 | QPDFTokenizer::Token( |
| 61 | QPDFTokenizer::tt_space, std::string(1, ch))); | 60 | QPDFTokenizer::tt_space, std::string(1, ch))); |
| 62 | QTC::TC("qpdf", "Pl_QPDFTokenizer found ID"); | 61 | QTC::TC("qpdf", "Pl_QPDFTokenizer found ID"); |
| 63 | - this->m->tokenizer.expectInlineImage(input); | 62 | + m->tokenizer.expectInlineImage(input); |
| 64 | } | 63 | } |
| 65 | } | 64 | } |
| 66 | - this->m->filter->handleEOF(); | 65 | + m->filter->handleEOF(); |
| 67 | QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline( | 66 | QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline( |
| 68 | m->filter, nullptr); | 67 | m->filter, nullptr); |
| 69 | Pipeline* next = this->getNext(true); | 68 | Pipeline* next = this->getNext(true); |
libqpdf/Pl_RunLength.cc
| @@ -26,7 +26,7 @@ Pl_RunLength::~Pl_RunLength() | @@ -26,7 +26,7 @@ Pl_RunLength::~Pl_RunLength() | ||
| 26 | void | 26 | void |
| 27 | Pl_RunLength::write(unsigned char const* data, size_t len) | 27 | Pl_RunLength::write(unsigned char const* data, size_t len) |
| 28 | { | 28 | { |
| 29 | - if (this->m->action == a_encode) { | 29 | + if (m->action == a_encode) { |
| 30 | encode(data, len); | 30 | encode(data, len); |
| 31 | } else { | 31 | } else { |
| 32 | decode(data, len); | 32 | decode(data, len); |
| @@ -37,35 +37,35 @@ void | @@ -37,35 +37,35 @@ void | ||
| 37 | Pl_RunLength::encode(unsigned char const* data, size_t len) | 37 | Pl_RunLength::encode(unsigned char const* data, size_t len) |
| 38 | { | 38 | { |
| 39 | for (size_t i = 0; i < len; ++i) { | 39 | for (size_t i = 0; i < len; ++i) { |
| 40 | - if ((this->m->state == st_top) != (this->m->length <= 1)) { | 40 | + if ((m->state == st_top) != (m->length <= 1)) { |
| 41 | throw std::logic_error( | 41 | throw std::logic_error( |
| 42 | "Pl_RunLength::encode: state/length inconsistency"); | 42 | "Pl_RunLength::encode: state/length inconsistency"); |
| 43 | } | 43 | } |
| 44 | unsigned char ch = data[i]; | 44 | unsigned char ch = data[i]; |
| 45 | - if ((this->m->length > 0) && | ||
| 46 | - ((this->m->state == st_copying) || (this->m->length < 128)) && | ||
| 47 | - (ch == this->m->buf[this->m->length - 1])) { | 45 | + if ((m->length > 0) && |
| 46 | + ((m->state == st_copying) || (m->length < 128)) && | ||
| 47 | + (ch == m->buf[m->length - 1])) { | ||
| 48 | QTC::TC( | 48 | QTC::TC( |
| 49 | "libtests", | 49 | "libtests", |
| 50 | "Pl_RunLength: switch to run", | 50 | "Pl_RunLength: switch to run", |
| 51 | - (this->m->length == 128) ? 0 : 1); | ||
| 52 | - if (this->m->state == st_copying) { | ||
| 53 | - --this->m->length; | 51 | + (m->length == 128) ? 0 : 1); |
| 52 | + if (m->state == st_copying) { | ||
| 53 | + --m->length; | ||
| 54 | flush_encode(); | 54 | flush_encode(); |
| 55 | - this->m->buf[0] = ch; | ||
| 56 | - this->m->length = 1; | 55 | + m->buf[0] = ch; |
| 56 | + m->length = 1; | ||
| 57 | } | 57 | } |
| 58 | - this->m->state = st_run; | ||
| 59 | - this->m->buf[this->m->length] = ch; | ||
| 60 | - ++this->m->length; | 58 | + m->state = st_run; |
| 59 | + m->buf[m->length] = ch; | ||
| 60 | + ++m->length; | ||
| 61 | } else { | 61 | } else { |
| 62 | - if ((this->m->length == 128) || (this->m->state == st_run)) { | 62 | + if ((m->length == 128) || (m->state == st_run)) { |
| 63 | flush_encode(); | 63 | flush_encode(); |
| 64 | - } else if (this->m->length > 0) { | ||
| 65 | - this->m->state = st_copying; | 64 | + } else if (m->length > 0) { |
| 65 | + m->state = st_copying; | ||
| 66 | } | 66 | } |
| 67 | - this->m->buf[this->m->length] = ch; | ||
| 68 | - ++this->m->length; | 67 | + m->buf[m->length] = ch; |
| 68 | + ++m->length; | ||
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| @@ -75,16 +75,16 @@ Pl_RunLength::decode(unsigned char const* data, size_t len) | @@ -75,16 +75,16 @@ Pl_RunLength::decode(unsigned char const* data, size_t len) | ||
| 75 | { | 75 | { |
| 76 | for (size_t i = 0; i < len; ++i) { | 76 | for (size_t i = 0; i < len; ++i) { |
| 77 | unsigned char ch = data[i]; | 77 | unsigned char ch = data[i]; |
| 78 | - switch (this->m->state) { | 78 | + switch (m->state) { |
| 79 | case st_top: | 79 | case st_top: |
| 80 | if (ch < 128) { | 80 | if (ch < 128) { |
| 81 | // length represents remaining number of bytes to copy | 81 | // length represents remaining number of bytes to copy |
| 82 | - this->m->length = 1U + ch; | ||
| 83 | - this->m->state = st_copying; | 82 | + m->length = 1U + ch; |
| 83 | + m->state = st_copying; | ||
| 84 | } else if (ch > 128) { | 84 | } else if (ch > 128) { |
| 85 | // length represents number of copies of next byte | 85 | // length represents number of copies of next byte |
| 86 | - this->m->length = 257U - ch; | ||
| 87 | - this->m->state = st_run; | 86 | + m->length = 257U - ch; |
| 87 | + m->state = st_run; | ||
| 88 | } else // ch == 128 | 88 | } else // ch == 128 |
| 89 | { | 89 | { |
| 90 | // EOD; stay in this state | 90 | // EOD; stay in this state |
| @@ -93,16 +93,16 @@ Pl_RunLength::decode(unsigned char const* data, size_t len) | @@ -93,16 +93,16 @@ Pl_RunLength::decode(unsigned char const* data, size_t len) | ||
| 93 | 93 | ||
| 94 | case st_copying: | 94 | case st_copying: |
| 95 | this->getNext()->write(&ch, 1); | 95 | this->getNext()->write(&ch, 1); |
| 96 | - if (--this->m->length == 0) { | ||
| 97 | - this->m->state = st_top; | 96 | + if (--m->length == 0) { |
| 97 | + m->state = st_top; | ||
| 98 | } | 98 | } |
| 99 | break; | 99 | break; |
| 100 | 100 | ||
| 101 | case st_run: | 101 | case st_run: |
| 102 | - for (unsigned int j = 0; j < this->m->length; ++j) { | 102 | + for (unsigned int j = 0; j < m->length; ++j) { |
| 103 | this->getNext()->write(&ch, 1); | 103 | this->getNext()->write(&ch, 1); |
| 104 | } | 104 | } |
| 105 | - this->m->state = st_top; | 105 | + m->state = st_top; |
| 106 | break; | 106 | break; |
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| @@ -111,32 +111,32 @@ Pl_RunLength::decode(unsigned char const* data, size_t len) | @@ -111,32 +111,32 @@ Pl_RunLength::decode(unsigned char const* data, size_t len) | ||
| 111 | void | 111 | void |
| 112 | Pl_RunLength::flush_encode() | 112 | Pl_RunLength::flush_encode() |
| 113 | { | 113 | { |
| 114 | - if (this->m->length == 128) { | 114 | + if (m->length == 128) { |
| 115 | QTC::TC( | 115 | QTC::TC( |
| 116 | "libtests", | 116 | "libtests", |
| 117 | "Pl_RunLength flush full buffer", | 117 | "Pl_RunLength flush full buffer", |
| 118 | - (this->m->state == st_copying ? 0 | ||
| 119 | - : this->m->state == st_run ? 1 | ||
| 120 | - : -1)); | 118 | + (m->state == st_copying ? 0 |
| 119 | + : m->state == st_run ? 1 | ||
| 120 | + : -1)); | ||
| 121 | } | 121 | } |
| 122 | - if (this->m->length == 0) { | 122 | + if (m->length == 0) { |
| 123 | QTC::TC("libtests", "Pl_RunLength flush empty buffer"); | 123 | QTC::TC("libtests", "Pl_RunLength flush empty buffer"); |
| 124 | } | 124 | } |
| 125 | - if (this->m->state == st_run) { | ||
| 126 | - if ((this->m->length < 2) || (this->m->length > 128)) { | 125 | + if (m->state == st_run) { |
| 126 | + if ((m->length < 2) || (m->length > 128)) { | ||
| 127 | throw std::logic_error( | 127 | throw std::logic_error( |
| 128 | "Pl_RunLength: invalid length in flush_encode for run"); | 128 | "Pl_RunLength: invalid length in flush_encode for run"); |
| 129 | } | 129 | } |
| 130 | - auto ch = static_cast<unsigned char>(257 - this->m->length); | 130 | + auto ch = static_cast<unsigned char>(257 - m->length); |
| 131 | this->getNext()->write(&ch, 1); | 131 | this->getNext()->write(&ch, 1); |
| 132 | - this->getNext()->write(&this->m->buf[0], 1); | ||
| 133 | - } else if (this->m->length > 0) { | ||
| 134 | - auto ch = static_cast<unsigned char>(this->m->length - 1); | 132 | + this->getNext()->write(&m->buf[0], 1); |
| 133 | + } else if (m->length > 0) { | ||
| 134 | + auto ch = static_cast<unsigned char>(m->length - 1); | ||
| 135 | this->getNext()->write(&ch, 1); | 135 | this->getNext()->write(&ch, 1); |
| 136 | - this->getNext()->write(this->m->buf, this->m->length); | 136 | + this->getNext()->write(m->buf, m->length); |
| 137 | } | 137 | } |
| 138 | - this->m->state = st_top; | ||
| 139 | - this->m->length = 0; | 138 | + m->state = st_top; |
| 139 | + m->length = 0; | ||
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | void | 142 | void |
| @@ -146,7 +146,7 @@ Pl_RunLength::finish() | @@ -146,7 +146,7 @@ Pl_RunLength::finish() | ||
| 146 | // data, which means the stream was terminated early, but we will | 146 | // data, which means the stream was terminated early, but we will |
| 147 | // just ignore this case since this is the only sensible thing to | 147 | // just ignore this case since this is the only sensible thing to |
| 148 | // do. | 148 | // do. |
| 149 | - if (this->m->action == a_encode) { | 149 | + if (m->action == a_encode) { |
| 150 | flush_encode(); | 150 | flush_encode(); |
| 151 | unsigned char ch = 128; | 151 | unsigned char ch = 128; |
| 152 | this->getNext()->write(&ch, 1); | 152 | this->getNext()->write(&ch, 1); |
libqpdf/Pl_StdioFile.cc
| @@ -28,7 +28,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len) | @@ -28,7 +28,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len) | ||
| 28 | { | 28 | { |
| 29 | size_t so_far = 0; | 29 | size_t so_far = 0; |
| 30 | while (len > 0) { | 30 | while (len > 0) { |
| 31 | - so_far = fwrite(buf, 1, len, this->m->file); | 31 | + so_far = fwrite(buf, 1, len, m->file); |
| 32 | if (so_far == 0) { | 32 | if (so_far == 0) { |
| 33 | QUtil::throw_system_error( | 33 | QUtil::throw_system_error( |
| 34 | this->identifier + ": Pl_StdioFile::write"); | 34 | this->identifier + ": Pl_StdioFile::write"); |
| @@ -42,7 +42,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len) | @@ -42,7 +42,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len) | ||
| 42 | void | 42 | void |
| 43 | Pl_StdioFile::finish() | 43 | Pl_StdioFile::finish() |
| 44 | { | 44 | { |
| 45 | - if ((fflush(this->m->file) == -1) && (errno == EBADF)) { | 45 | + if ((fflush(m->file) == -1) && (errno == EBADF)) { |
| 46 | throw std::logic_error( | 46 | throw std::logic_error( |
| 47 | this->identifier + ": Pl_StdioFile::finish: stream already closed"); | 47 | this->identifier + ": Pl_StdioFile::finish: stream already closed"); |
| 48 | } | 48 | } |
libqpdf/Pl_String.cc
| @@ -22,7 +22,7 @@ Pl_String::~Pl_String() | @@ -22,7 +22,7 @@ Pl_String::~Pl_String() | ||
| 22 | void | 22 | void |
| 23 | Pl_String::write(unsigned char const* buf, size_t len) | 23 | Pl_String::write(unsigned char const* buf, size_t len) |
| 24 | { | 24 | { |
| 25 | - this->m->s.append(reinterpret_cast<char const*>(buf), len); | 25 | + m->s.append(reinterpret_cast<char const*>(buf), len); |
| 26 | if (getNext(true)) { | 26 | if (getNext(true)) { |
| 27 | getNext()->write(buf, len); | 27 | getNext()->write(buf, len); |
| 28 | } | 28 | } |
libqpdf/QPDF.cc
| @@ -246,8 +246,8 @@ QPDF::~QPDF() | @@ -246,8 +246,8 @@ QPDF::~QPDF() | ||
| 246 | // At this point, obviously no one is still using the QPDF object, | 246 | // At this point, obviously no one is still using the QPDF object, |
| 247 | // but we'll explicitly clear the xref table anyway just to | 247 | // but we'll explicitly clear the xref table anyway just to |
| 248 | // prevent any possibility of resolve() succeeding. | 248 | // prevent any possibility of resolve() succeeding. |
| 249 | - this->m->xref_table.clear(); | ||
| 250 | - for (auto const& iter: this->m->obj_cache) { | 249 | + m->xref_table.clear(); |
| 250 | + for (auto const& iter: m->obj_cache) { | ||
| 251 | iter.second.object->disconnect(); | 251 | iter.second.object->disconnect(); |
| 252 | if (iter.second.object->getTypeCode() != ::ot_null) { | 252 | if (iter.second.object->getTypeCode() != ::ot_null) { |
| 253 | iter.second.object->destroy(); | 253 | iter.second.object->destroy(); |
| @@ -297,20 +297,20 @@ void | @@ -297,20 +297,20 @@ void | ||
| 297 | QPDF::processInputSource( | 297 | QPDF::processInputSource( |
| 298 | std::shared_ptr<InputSource> source, char const* password) | 298 | std::shared_ptr<InputSource> source, char const* password) |
| 299 | { | 299 | { |
| 300 | - this->m->file = source; | 300 | + m->file = source; |
| 301 | parse(password); | 301 | parse(password); |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | void | 304 | void |
| 305 | QPDF::closeInputSource() | 305 | QPDF::closeInputSource() |
| 306 | { | 306 | { |
| 307 | - this->m->file = std::shared_ptr<InputSource>(new InvalidInputSource()); | 307 | + m->file = std::shared_ptr<InputSource>(new InvalidInputSource()); |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | void | 310 | void |
| 311 | QPDF::setPasswordIsHexKey(bool val) | 311 | QPDF::setPasswordIsHexKey(bool val) |
| 312 | { | 312 | { |
| 313 | - this->m->provided_password_is_hex_key = val; | 313 | + m->provided_password_is_hex_key = val; |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | void | 316 | void |
| @@ -330,64 +330,64 @@ QPDF::registerStreamFilter( | @@ -330,64 +330,64 @@ QPDF::registerStreamFilter( | ||
| 330 | void | 330 | void |
| 331 | QPDF::setIgnoreXRefStreams(bool val) | 331 | QPDF::setIgnoreXRefStreams(bool val) |
| 332 | { | 332 | { |
| 333 | - this->m->ignore_xref_streams = val; | 333 | + m->ignore_xref_streams = val; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | std::shared_ptr<QPDFLogger> | 336 | std::shared_ptr<QPDFLogger> |
| 337 | QPDF::getLogger() | 337 | QPDF::getLogger() |
| 338 | { | 338 | { |
| 339 | - return this->m->log; | 339 | + return m->log; |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | void | 342 | void |
| 343 | QPDF::setLogger(std::shared_ptr<QPDFLogger> l) | 343 | QPDF::setLogger(std::shared_ptr<QPDFLogger> l) |
| 344 | { | 344 | { |
| 345 | - this->m->log = l; | 345 | + m->log = l; |
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | void | 348 | void |
| 349 | QPDF::setOutputStreams(std::ostream* out, std::ostream* err) | 349 | QPDF::setOutputStreams(std::ostream* out, std::ostream* err) |
| 350 | { | 350 | { |
| 351 | setLogger(QPDFLogger::create()); | 351 | setLogger(QPDFLogger::create()); |
| 352 | - this->m->log->setOutputStreams(out, err); | 352 | + m->log->setOutputStreams(out, err); |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | void | 355 | void |
| 356 | QPDF::setSuppressWarnings(bool val) | 356 | QPDF::setSuppressWarnings(bool val) |
| 357 | { | 357 | { |
| 358 | - this->m->suppress_warnings = val; | 358 | + m->suppress_warnings = val; |
| 359 | } | 359 | } |
| 360 | 360 | ||
| 361 | void | 361 | void |
| 362 | QPDF::setAttemptRecovery(bool val) | 362 | QPDF::setAttemptRecovery(bool val) |
| 363 | { | 363 | { |
| 364 | - this->m->attempt_recovery = val; | 364 | + m->attempt_recovery = val; |
| 365 | } | 365 | } |
| 366 | 366 | ||
| 367 | void | 367 | void |
| 368 | QPDF::setImmediateCopyFrom(bool val) | 368 | QPDF::setImmediateCopyFrom(bool val) |
| 369 | { | 369 | { |
| 370 | - this->m->immediate_copy_from = val; | 370 | + m->immediate_copy_from = val; |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | std::vector<QPDFExc> | 373 | std::vector<QPDFExc> |
| 374 | QPDF::getWarnings() | 374 | QPDF::getWarnings() |
| 375 | { | 375 | { |
| 376 | - std::vector<QPDFExc> result = this->m->warnings; | ||
| 377 | - this->m->warnings.clear(); | 376 | + std::vector<QPDFExc> result = m->warnings; |
| 377 | + m->warnings.clear(); | ||
| 378 | return result; | 378 | return result; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | bool | 381 | bool |
| 382 | QPDF::anyWarnings() const | 382 | QPDF::anyWarnings() const |
| 383 | { | 383 | { |
| 384 | - return !this->m->warnings.empty(); | 384 | + return !m->warnings.empty(); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | size_t | 387 | size_t |
| 388 | QPDF::numWarnings() const | 388 | QPDF::numWarnings() const |
| 389 | { | 389 | { |
| 390 | - return this->m->warnings.size(); | 390 | + return m->warnings.size(); |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | bool | 393 | bool |
| @@ -413,8 +413,8 @@ QPDF::validatePDFVersion(char const*& p, std::string& version) | @@ -413,8 +413,8 @@ QPDF::validatePDFVersion(char const*& p, std::string& version) | ||
| 413 | bool | 413 | bool |
| 414 | QPDF::findHeader() | 414 | QPDF::findHeader() |
| 415 | { | 415 | { |
| 416 | - qpdf_offset_t global_offset = this->m->file->tell(); | ||
| 417 | - std::string line = this->m->file->readLine(1024); | 416 | + qpdf_offset_t global_offset = m->file->tell(); |
| 417 | + std::string line = m->file->readLine(1024); | ||
| 418 | char const* p = line.c_str(); | 418 | char const* p = line.c_str(); |
| 419 | if (strncmp(p, "%PDF-", 5) != 0) { | 419 | if (strncmp(p, "%PDF-", 5) != 0) { |
| 420 | throw std::logic_error("findHeader is not looking at %PDF-"); | 420 | throw std::logic_error("findHeader is not looking at %PDF-"); |
| @@ -427,15 +427,15 @@ QPDF::findHeader() | @@ -427,15 +427,15 @@ QPDF::findHeader() | ||
| 427 | // advancement. | 427 | // advancement. |
| 428 | bool valid = validatePDFVersion(p, version); | 428 | bool valid = validatePDFVersion(p, version); |
| 429 | if (valid) { | 429 | if (valid) { |
| 430 | - this->m->pdf_version = version; | 430 | + m->pdf_version = version; |
| 431 | if (global_offset != 0) { | 431 | if (global_offset != 0) { |
| 432 | // Empirical evidence strongly suggests that when there is | 432 | // Empirical evidence strongly suggests that when there is |
| 433 | // leading material prior to the PDF header, all explicit | 433 | // leading material prior to the PDF header, all explicit |
| 434 | // offsets in the file are such that 0 points to the | 434 | // offsets in the file are such that 0 points to the |
| 435 | // beginning of the header. | 435 | // beginning of the header. |
| 436 | QTC::TC("qpdf", "QPDF global offset"); | 436 | QTC::TC("qpdf", "QPDF global offset"); |
| 437 | - this->m->file = std::shared_ptr<InputSource>( | ||
| 438 | - new OffsetInputSource(this->m->file, global_offset)); | 437 | + m->file = std::shared_ptr<InputSource>( |
| 438 | + new OffsetInputSource(m->file, global_offset)); | ||
| 439 | } | 439 | } |
| 440 | } | 440 | } |
| 441 | return valid; | 441 | return valid; |
| @@ -447,7 +447,7 @@ QPDF::findStartxref() | @@ -447,7 +447,7 @@ QPDF::findStartxref() | ||
| 447 | if (readToken(m->file).isWord("startxref") && | 447 | if (readToken(m->file).isWord("startxref") && |
| 448 | readToken(m->file).isInteger()) { | 448 | readToken(m->file).isInteger()) { |
| 449 | // Position in front of offset token | 449 | // Position in front of offset token |
| 450 | - this->m->file->seek(this->m->file->getLastOffset(), SEEK_SET); | 450 | + m->file->seek(m->file->getLastOffset(), SEEK_SET); |
| 451 | return true; | 451 | return true; |
| 452 | } | 452 | } |
| 453 | return false; | 453 | return false; |
| @@ -457,30 +457,30 @@ void | @@ -457,30 +457,30 @@ void | ||
| 457 | QPDF::parse(char const* password) | 457 | QPDF::parse(char const* password) |
| 458 | { | 458 | { |
| 459 | if (password) { | 459 | if (password) { |
| 460 | - this->m->encp->provided_password = password; | 460 | + m->encp->provided_password = password; |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | // Find the header anywhere in the first 1024 bytes of the file. | 463 | // Find the header anywhere in the first 1024 bytes of the file. |
| 464 | PatternFinder hf(*this, &QPDF::findHeader); | 464 | PatternFinder hf(*this, &QPDF::findHeader); |
| 465 | - if (!this->m->file->findFirst("%PDF-", 0, 1024, hf)) { | 465 | + if (!m->file->findFirst("%PDF-", 0, 1024, hf)) { |
| 466 | QTC::TC("qpdf", "QPDF not a pdf file"); | 466 | QTC::TC("qpdf", "QPDF not a pdf file"); |
| 467 | warn(damagedPDF("", 0, "can't find PDF header")); | 467 | warn(damagedPDF("", 0, "can't find PDF header")); |
| 468 | // QPDFWriter writes files that usually require at least | 468 | // QPDFWriter writes files that usually require at least |
| 469 | // version 1.2 for /FlateDecode | 469 | // version 1.2 for /FlateDecode |
| 470 | - this->m->pdf_version = "1.2"; | 470 | + m->pdf_version = "1.2"; |
| 471 | } | 471 | } |
| 472 | 472 | ||
| 473 | // PDF spec says %%EOF must be found within the last 1024 bytes of | 473 | // PDF spec says %%EOF must be found within the last 1024 bytes of |
| 474 | // the file. We add an extra 30 characters to leave room for the | 474 | // the file. We add an extra 30 characters to leave room for the |
| 475 | // startxref stuff. | 475 | // startxref stuff. |
| 476 | - this->m->file->seek(0, SEEK_END); | ||
| 477 | - qpdf_offset_t end_offset = this->m->file->tell(); | 476 | + m->file->seek(0, SEEK_END); |
| 477 | + qpdf_offset_t end_offset = m->file->tell(); | ||
| 478 | qpdf_offset_t start_offset = (end_offset > 1054 ? end_offset - 1054 : 0); | 478 | qpdf_offset_t start_offset = (end_offset > 1054 ? end_offset - 1054 : 0); |
| 479 | PatternFinder sf(*this, &QPDF::findStartxref); | 479 | PatternFinder sf(*this, &QPDF::findStartxref); |
| 480 | qpdf_offset_t xref_offset = 0; | 480 | qpdf_offset_t xref_offset = 0; |
| 481 | - if (this->m->file->findLast("startxref", start_offset, 0, sf)) { | 481 | + if (m->file->findLast("startxref", start_offset, 0, sf)) { |
| 482 | xref_offset = | 482 | xref_offset = |
| 483 | - QUtil::string_to_ll(readToken(this->m->file).getValue().c_str()); | 483 | + QUtil::string_to_ll(readToken(m->file).getValue().c_str()); |
| 484 | } | 484 | } |
| 485 | 485 | ||
| 486 | try { | 486 | try { |
| @@ -497,7 +497,7 @@ QPDF::parse(char const* password) | @@ -497,7 +497,7 @@ QPDF::parse(char const* password) | ||
| 497 | "", 0, std::string("error reading xref: ") + e.what()); | 497 | "", 0, std::string("error reading xref: ") + e.what()); |
| 498 | } | 498 | } |
| 499 | } catch (QPDFExc& e) { | 499 | } catch (QPDFExc& e) { |
| 500 | - if (this->m->attempt_recovery) { | 500 | + if (m->attempt_recovery) { |
| 501 | reconstruct_xref(e); | 501 | reconstruct_xref(e); |
| 502 | QTC::TC("qpdf", "QPDF reconstructed xref table"); | 502 | QTC::TC("qpdf", "QPDF reconstructed xref table"); |
| 503 | } else { | 503 | } else { |
| @@ -506,29 +506,28 @@ QPDF::parse(char const* password) | @@ -506,29 +506,28 @@ QPDF::parse(char const* password) | ||
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | initializeEncryption(); | 508 | initializeEncryption(); |
| 509 | - this->m->parsed = true; | 509 | + m->parsed = true; |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | void | 512 | void |
| 513 | QPDF::inParse(bool v) | 513 | QPDF::inParse(bool v) |
| 514 | { | 514 | { |
| 515 | - if (this->m->in_parse == v) { | 515 | + if (m->in_parse == v) { |
| 516 | // This happens if QPDFParser::parse tries to | 516 | // This happens if QPDFParser::parse tries to |
| 517 | // resolve an indirect object while it is parsing. | 517 | // resolve an indirect object while it is parsing. |
| 518 | throw std::logic_error( | 518 | throw std::logic_error( |
| 519 | "QPDF: re-entrant parsing detected. This is a qpdf bug." | 519 | "QPDF: re-entrant parsing detected. This is a qpdf bug." |
| 520 | " Please report at https://github.com/qpdf/qpdf/issues."); | 520 | " Please report at https://github.com/qpdf/qpdf/issues."); |
| 521 | } | 521 | } |
| 522 | - this->m->in_parse = v; | 522 | + m->in_parse = v; |
| 523 | } | 523 | } |
| 524 | 524 | ||
| 525 | void | 525 | void |
| 526 | QPDF::warn(QPDFExc const& e) | 526 | QPDF::warn(QPDFExc const& e) |
| 527 | { | 527 | { |
| 528 | - this->m->warnings.push_back(e); | ||
| 529 | - if (!this->m->suppress_warnings) { | ||
| 530 | - *this->m->log->getWarn() | ||
| 531 | - << "WARNING: " << this->m->warnings.back().what() << "\n"; | 528 | + m->warnings.push_back(e); |
| 529 | + if (!m->suppress_warnings) { | ||
| 530 | + *m->log->getWarn() << "WARNING: " << m->warnings.back().what() << "\n"; | ||
| 532 | } | 531 | } |
| 533 | } | 532 | } |
| 534 | 533 | ||
| @@ -545,25 +544,25 @@ QPDF::warn( | @@ -545,25 +544,25 @@ QPDF::warn( | ||
| 545 | void | 544 | void |
| 546 | QPDF::setTrailer(QPDFObjectHandle obj) | 545 | QPDF::setTrailer(QPDFObjectHandle obj) |
| 547 | { | 546 | { |
| 548 | - if (this->m->trailer.isInitialized()) { | 547 | + if (m->trailer.isInitialized()) { |
| 549 | return; | 548 | return; |
| 550 | } | 549 | } |
| 551 | - this->m->trailer = obj; | 550 | + m->trailer = obj; |
| 552 | } | 551 | } |
| 553 | 552 | ||
| 554 | void | 553 | void |
| 555 | QPDF::reconstruct_xref(QPDFExc& e) | 554 | QPDF::reconstruct_xref(QPDFExc& e) |
| 556 | { | 555 | { |
| 557 | - if (this->m->reconstructed_xref) { | 556 | + if (m->reconstructed_xref) { |
| 558 | // Avoid xref reconstruction infinite loops. This is getting | 557 | // Avoid xref reconstruction infinite loops. This is getting |
| 559 | // very hard to reproduce because qpdf is throwing many fewer | 558 | // very hard to reproduce because qpdf is throwing many fewer |
| 560 | // exceptions while parsing. Most situations are warnings now. | 559 | // exceptions while parsing. Most situations are warnings now. |
| 561 | throw e; | 560 | throw e; |
| 562 | } | 561 | } |
| 563 | 562 | ||
| 564 | - this->m->reconstructed_xref = true; | 563 | + m->reconstructed_xref = true; |
| 565 | // We may find more objects, which may contain dangling references. | 564 | // We may find more objects, which may contain dangling references. |
| 566 | - this->m->fixed_dangling_refs = false; | 565 | + m->fixed_dangling_refs = false; |
| 567 | 566 | ||
| 568 | warn(damagedPDF("", 0, "file is damaged")); | 567 | warn(damagedPDF("", 0, "file is damaged")); |
| 569 | warn(e); | 568 | warn(e); |
| @@ -571,53 +570,53 @@ QPDF::reconstruct_xref(QPDFExc& e) | @@ -571,53 +570,53 @@ QPDF::reconstruct_xref(QPDFExc& e) | ||
| 571 | 570 | ||
| 572 | // Delete all references to type 1 (uncompressed) objects | 571 | // Delete all references to type 1 (uncompressed) objects |
| 573 | std::set<QPDFObjGen> to_delete; | 572 | std::set<QPDFObjGen> to_delete; |
| 574 | - for (auto const& iter: this->m->xref_table) { | 573 | + for (auto const& iter: m->xref_table) { |
| 575 | if (iter.second.getType() == 1) { | 574 | if (iter.second.getType() == 1) { |
| 576 | to_delete.insert(iter.first); | 575 | to_delete.insert(iter.first); |
| 577 | } | 576 | } |
| 578 | } | 577 | } |
| 579 | for (auto const& iter: to_delete) { | 578 | for (auto const& iter: to_delete) { |
| 580 | - this->m->xref_table.erase(iter); | 579 | + m->xref_table.erase(iter); |
| 581 | } | 580 | } |
| 582 | 581 | ||
| 583 | - this->m->file->seek(0, SEEK_END); | ||
| 584 | - qpdf_offset_t eof = this->m->file->tell(); | ||
| 585 | - this->m->file->seek(0, SEEK_SET); | 582 | + m->file->seek(0, SEEK_END); |
| 583 | + qpdf_offset_t eof = m->file->tell(); | ||
| 584 | + m->file->seek(0, SEEK_SET); | ||
| 586 | qpdf_offset_t line_start = 0; | 585 | qpdf_offset_t line_start = 0; |
| 587 | // Don't allow very long tokens here during recovery. | 586 | // Don't allow very long tokens here during recovery. |
| 588 | static size_t const MAX_LEN = 100; | 587 | static size_t const MAX_LEN = 100; |
| 589 | - while (this->m->file->tell() < eof) { | ||
| 590 | - this->m->file->findAndSkipNextEOL(); | ||
| 591 | - qpdf_offset_t next_line_start = this->m->file->tell(); | ||
| 592 | - this->m->file->seek(line_start, SEEK_SET); | ||
| 593 | - QPDFTokenizer::Token t1 = readToken(this->m->file, MAX_LEN); | 588 | + while (m->file->tell() < eof) { |
| 589 | + m->file->findAndSkipNextEOL(); | ||
| 590 | + qpdf_offset_t next_line_start = m->file->tell(); | ||
| 591 | + m->file->seek(line_start, SEEK_SET); | ||
| 592 | + QPDFTokenizer::Token t1 = readToken(m->file, MAX_LEN); | ||
| 594 | qpdf_offset_t token_start = | 593 | qpdf_offset_t token_start = |
| 595 | - this->m->file->tell() - toO(t1.getValue().length()); | 594 | + m->file->tell() - toO(t1.getValue().length()); |
| 596 | if (token_start >= next_line_start) { | 595 | if (token_start >= next_line_start) { |
| 597 | // don't process yet -- wait until we get to the line | 596 | // don't process yet -- wait until we get to the line |
| 598 | // containing this token | 597 | // containing this token |
| 599 | } else if (t1.isInteger()) { | 598 | } else if (t1.isInteger()) { |
| 600 | - QPDFTokenizer::Token t2 = readToken(this->m->file, MAX_LEN); | 599 | + QPDFTokenizer::Token t2 = readToken(m->file, MAX_LEN); |
| 601 | if ((t2.isInteger()) && | 600 | if ((t2.isInteger()) && |
| 602 | (readToken(m->file, MAX_LEN).isWord("obj"))) { | 601 | (readToken(m->file, MAX_LEN).isWord("obj"))) { |
| 603 | int obj = QUtil::string_to_int(t1.getValue().c_str()); | 602 | int obj = QUtil::string_to_int(t1.getValue().c_str()); |
| 604 | int gen = QUtil::string_to_int(t2.getValue().c_str()); | 603 | int gen = QUtil::string_to_int(t2.getValue().c_str()); |
| 605 | insertXrefEntry(obj, 1, token_start, gen, true); | 604 | insertXrefEntry(obj, 1, token_start, gen, true); |
| 606 | } | 605 | } |
| 607 | - } else if (!this->m->trailer.isInitialized() && t1.isWord("trailer")) { | 606 | + } else if (!m->trailer.isInitialized() && t1.isWord("trailer")) { |
| 608 | QPDFObjectHandle t = | 607 | QPDFObjectHandle t = |
| 609 | - readObject(this->m->file, "trailer", QPDFObjGen(), false); | 608 | + readObject(m->file, "trailer", QPDFObjGen(), false); |
| 610 | if (!t.isDictionary()) { | 609 | if (!t.isDictionary()) { |
| 611 | // Oh well. It was worth a try. | 610 | // Oh well. It was worth a try. |
| 612 | } else { | 611 | } else { |
| 613 | setTrailer(t); | 612 | setTrailer(t); |
| 614 | } | 613 | } |
| 615 | } | 614 | } |
| 616 | - this->m->file->seek(next_line_start, SEEK_SET); | 615 | + m->file->seek(next_line_start, SEEK_SET); |
| 617 | line_start = next_line_start; | 616 | line_start = next_line_start; |
| 618 | } | 617 | } |
| 619 | 618 | ||
| 620 | - if (!this->m->trailer.isInitialized()) { | 619 | + if (!m->trailer.isInitialized()) { |
| 621 | // We could check the last encountered object to see if it was | 620 | // We could check the last encountered object to see if it was |
| 622 | // an xref stream. If so, we could try to get the trailer | 621 | // an xref stream. If so, we could try to get the trailer |
| 623 | // from there. This may make it possible to recover files | 622 | // from there. This may make it possible to recover files |
| @@ -648,7 +647,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -648,7 +647,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 648 | visited.insert(xref_offset); | 647 | visited.insert(xref_offset); |
| 649 | char buf[7]; | 648 | char buf[7]; |
| 650 | memset(buf, 0, sizeof(buf)); | 649 | memset(buf, 0, sizeof(buf)); |
| 651 | - this->m->file->seek(xref_offset, SEEK_SET); | 650 | + m->file->seek(xref_offset, SEEK_SET); |
| 652 | // Some files miss the mark a little with startxref. We could | 651 | // Some files miss the mark a little with startxref. We could |
| 653 | // do a better job of searching in the neighborhood for | 652 | // do a better job of searching in the neighborhood for |
| 654 | // something that looks like either an xref table or stream, | 653 | // something that looks like either an xref table or stream, |
| @@ -659,11 +658,11 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -659,11 +658,11 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 659 | bool skipped_space = false; | 658 | bool skipped_space = false; |
| 660 | while (!done) { | 659 | while (!done) { |
| 661 | char ch; | 660 | char ch; |
| 662 | - if (1 == this->m->file->read(&ch, 1)) { | 661 | + if (1 == m->file->read(&ch, 1)) { |
| 663 | if (QUtil::is_space(ch)) { | 662 | if (QUtil::is_space(ch)) { |
| 664 | skipped_space = true; | 663 | skipped_space = true; |
| 665 | } else { | 664 | } else { |
| 666 | - this->m->file->unreadCh(ch); | 665 | + m->file->unreadCh(ch); |
| 667 | done = true; | 666 | done = true; |
| 668 | } | 667 | } |
| 669 | } else { | 668 | } else { |
| @@ -675,7 +674,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -675,7 +674,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 675 | } | 674 | } |
| 676 | } | 675 | } |
| 677 | 676 | ||
| 678 | - this->m->file->read(buf, sizeof(buf) - 1); | 677 | + m->file->read(buf, sizeof(buf) - 1); |
| 679 | // The PDF spec says xref must be followed by a line | 678 | // The PDF spec says xref must be followed by a line |
| 680 | // terminator, but files exist in the wild where it is | 679 | // terminator, but files exist in the wild where it is |
| 681 | // terminated by arbitrary whitespace. | 680 | // terminated by arbitrary whitespace. |
| @@ -708,16 +707,16 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -708,16 +707,16 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 708 | } | 707 | } |
| 709 | } | 708 | } |
| 710 | 709 | ||
| 711 | - if (!this->m->trailer.isInitialized()) { | 710 | + if (!m->trailer.isInitialized()) { |
| 712 | throw damagedPDF("", 0, "unable to find trailer while reading xref"); | 711 | throw damagedPDF("", 0, "unable to find trailer while reading xref"); |
| 713 | } | 712 | } |
| 714 | - int size = this->m->trailer.getKey("/Size").getIntValueAsInt(); | 713 | + int size = m->trailer.getKey("/Size").getIntValueAsInt(); |
| 715 | int max_obj = 0; | 714 | int max_obj = 0; |
| 716 | - if (!this->m->xref_table.empty()) { | ||
| 717 | - max_obj = (*(this->m->xref_table.rbegin())).first.getObj(); | 715 | + if (!m->xref_table.empty()) { |
| 716 | + max_obj = (*(m->xref_table.rbegin())).first.getObj(); | ||
| 718 | } | 717 | } |
| 719 | - if (!this->m->deleted_objects.empty()) { | ||
| 720 | - max_obj = std::max(max_obj, *(this->m->deleted_objects.rbegin())); | 718 | + if (!m->deleted_objects.empty()) { |
| 719 | + max_obj = std::max(max_obj, *(m->deleted_objects.rbegin())); | ||
| 721 | } | 720 | } |
| 722 | if ((size < 1) || (size - 1 != max_obj)) { | 721 | if ((size < 1) || (size - 1 != max_obj)) { |
| 723 | QTC::TC("qpdf", "QPDF xref size mismatch"); | 722 | QTC::TC("qpdf", "QPDF xref size mismatch"); |
| @@ -731,7 +730,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -731,7 +730,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 731 | 730 | ||
| 732 | // We no longer need the deleted_objects table, so go ahead and | 731 | // We no longer need the deleted_objects table, so go ahead and |
| 733 | // clear it out to make sure we never depend on its being set. | 732 | // clear it out to make sure we never depend on its being set. |
| 734 | - this->m->deleted_objects.clear(); | 733 | + m->deleted_objects.clear(); |
| 735 | } | 734 | } |
| 736 | 735 | ||
| 737 | bool | 736 | bool |
| @@ -864,12 +863,12 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -864,12 +863,12 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 864 | { | 863 | { |
| 865 | std::vector<QPDFObjGen> deleted_items; | 864 | std::vector<QPDFObjGen> deleted_items; |
| 866 | 865 | ||
| 867 | - this->m->file->seek(xref_offset, SEEK_SET); | 866 | + m->file->seek(xref_offset, SEEK_SET); |
| 868 | bool done = false; | 867 | bool done = false; |
| 869 | while (!done) { | 868 | while (!done) { |
| 870 | char linebuf[51]; | 869 | char linebuf[51]; |
| 871 | memset(linebuf, 0, sizeof(linebuf)); | 870 | memset(linebuf, 0, sizeof(linebuf)); |
| 872 | - this->m->file->read(linebuf, sizeof(linebuf) - 1); | 871 | + m->file->read(linebuf, sizeof(linebuf) - 1); |
| 873 | std::string line = linebuf; | 872 | std::string line = linebuf; |
| 874 | int obj = 0; | 873 | int obj = 0; |
| 875 | int num = 0; | 874 | int num = 0; |
| @@ -878,13 +877,13 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -878,13 +877,13 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 878 | QTC::TC("qpdf", "QPDF invalid xref"); | 877 | QTC::TC("qpdf", "QPDF invalid xref"); |
| 879 | throw damagedPDF("xref table", "xref syntax invalid"); | 878 | throw damagedPDF("xref table", "xref syntax invalid"); |
| 880 | } | 879 | } |
| 881 | - this->m->file->seek(this->m->file->getLastOffset() + bytes, SEEK_SET); | 880 | + m->file->seek(m->file->getLastOffset() + bytes, SEEK_SET); |
| 882 | for (qpdf_offset_t i = obj; i - num < obj; ++i) { | 881 | for (qpdf_offset_t i = obj; i - num < obj; ++i) { |
| 883 | if (i == 0) { | 882 | if (i == 0) { |
| 884 | // This is needed by checkLinearization() | 883 | // This is needed by checkLinearization() |
| 885 | - this->m->first_xref_item_offset = this->m->file->tell(); | 884 | + m->first_xref_item_offset = m->file->tell(); |
| 886 | } | 885 | } |
| 887 | - std::string xref_entry = this->m->file->readLine(30); | 886 | + std::string xref_entry = m->file->readLine(30); |
| 888 | // For xref_table, these will always be small enough to be ints | 887 | // For xref_table, these will always be small enough to be ints |
| 889 | qpdf_offset_t f1 = 0; | 888 | qpdf_offset_t f1 = 0; |
| 890 | int f2 = 0; | 889 | int f2 = 0; |
| @@ -903,30 +902,30 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -903,30 +902,30 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 903 | insertXrefEntry(toI(i), 1, f1, f2); | 902 | insertXrefEntry(toI(i), 1, f1, f2); |
| 904 | } | 903 | } |
| 905 | } | 904 | } |
| 906 | - qpdf_offset_t pos = this->m->file->tell(); | 905 | + qpdf_offset_t pos = m->file->tell(); |
| 907 | if (readToken(m->file).isWord("trailer")) { | 906 | if (readToken(m->file).isWord("trailer")) { |
| 908 | done = true; | 907 | done = true; |
| 909 | } else { | 908 | } else { |
| 910 | - this->m->file->seek(pos, SEEK_SET); | 909 | + m->file->seek(pos, SEEK_SET); |
| 911 | } | 910 | } |
| 912 | } | 911 | } |
| 913 | 912 | ||
| 914 | // Set offset to previous xref table if any | 913 | // Set offset to previous xref table if any |
| 915 | QPDFObjectHandle cur_trailer = | 914 | QPDFObjectHandle cur_trailer = |
| 916 | - readObject(this->m->file, "trailer", QPDFObjGen(), false); | 915 | + readObject(m->file, "trailer", QPDFObjGen(), false); |
| 917 | if (!cur_trailer.isDictionary()) { | 916 | if (!cur_trailer.isDictionary()) { |
| 918 | QTC::TC("qpdf", "QPDF missing trailer"); | 917 | QTC::TC("qpdf", "QPDF missing trailer"); |
| 919 | throw damagedPDF("", "expected trailer dictionary"); | 918 | throw damagedPDF("", "expected trailer dictionary"); |
| 920 | } | 919 | } |
| 921 | 920 | ||
| 922 | - if (!this->m->trailer.isInitialized()) { | 921 | + if (!m->trailer.isInitialized()) { |
| 923 | setTrailer(cur_trailer); | 922 | setTrailer(cur_trailer); |
| 924 | 923 | ||
| 925 | - if (!this->m->trailer.hasKey("/Size")) { | 924 | + if (!m->trailer.hasKey("/Size")) { |
| 926 | QTC::TC("qpdf", "QPDF trailer lacks size"); | 925 | QTC::TC("qpdf", "QPDF trailer lacks size"); |
| 927 | throw damagedPDF("trailer", "trailer dictionary lacks /Size key"); | 926 | throw damagedPDF("trailer", "trailer dictionary lacks /Size key"); |
| 928 | } | 927 | } |
| 929 | - if (!this->m->trailer.getKey("/Size").isInteger()) { | 928 | + if (!m->trailer.getKey("/Size").isInteger()) { |
| 930 | QTC::TC("qpdf", "QPDF trailer size not integer"); | 929 | QTC::TC("qpdf", "QPDF trailer size not integer"); |
| 931 | throw damagedPDF( | 930 | throw damagedPDF( |
| 932 | "trailer", "/Size key in trailer dictionary is not an integer"); | 931 | "trailer", "/Size key in trailer dictionary is not an integer"); |
| @@ -934,7 +933,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -934,7 +933,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 934 | } | 933 | } |
| 935 | 934 | ||
| 936 | if (cur_trailer.hasKey("/XRefStm")) { | 935 | if (cur_trailer.hasKey("/XRefStm")) { |
| 937 | - if (this->m->ignore_xref_streams) { | 936 | + if (m->ignore_xref_streams) { |
| 938 | QTC::TC("qpdf", "QPDF ignoring XRefStm in trailer"); | 937 | QTC::TC("qpdf", "QPDF ignoring XRefStm in trailer"); |
| 939 | } else { | 938 | } else { |
| 940 | if (cur_trailer.getKey("/XRefStm").isInteger()) { | 939 | if (cur_trailer.getKey("/XRefStm").isInteger()) { |
| @@ -974,7 +973,7 @@ qpdf_offset_t | @@ -974,7 +973,7 @@ qpdf_offset_t | ||
| 974 | QPDF::read_xrefStream(qpdf_offset_t xref_offset) | 973 | QPDF::read_xrefStream(qpdf_offset_t xref_offset) |
| 975 | { | 974 | { |
| 976 | bool found = false; | 975 | bool found = false; |
| 977 | - if (!this->m->ignore_xref_streams) { | 976 | + if (!m->ignore_xref_streams) { |
| 978 | QPDFObjGen x_og; | 977 | QPDFObjGen x_og; |
| 979 | QPDFObjectHandle xref_obj; | 978 | QPDFObjectHandle xref_obj; |
| 980 | try { | 979 | try { |
| @@ -1156,14 +1155,14 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1156,14 +1155,14 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1156 | 1155 | ||
| 1157 | if (saw_first_compressed_object) { | 1156 | if (saw_first_compressed_object) { |
| 1158 | if (fields[0] != 2) { | 1157 | if (fields[0] != 2) { |
| 1159 | - this->m->uncompressed_after_compressed = true; | 1158 | + m->uncompressed_after_compressed = true; |
| 1160 | } | 1159 | } |
| 1161 | } else if (fields[0] == 2) { | 1160 | } else if (fields[0] == 2) { |
| 1162 | saw_first_compressed_object = true; | 1161 | saw_first_compressed_object = true; |
| 1163 | } | 1162 | } |
| 1164 | if (obj == 0) { | 1163 | if (obj == 0) { |
| 1165 | // This is needed by checkLinearization() | 1164 | // This is needed by checkLinearization() |
| 1166 | - this->m->first_xref_item_offset = xref_offset; | 1165 | + m->first_xref_item_offset = xref_offset; |
| 1167 | } | 1166 | } |
| 1168 | if (fields[0] == 0) { | 1167 | if (fields[0] == 0) { |
| 1169 | // Ignore fields[2], which we don't care about in this | 1168 | // Ignore fields[2], which we don't care about in this |
| @@ -1175,7 +1174,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1175,7 +1174,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1175 | insertXrefEntry(obj, toI(fields[0]), fields[1], toI(fields[2])); | 1174 | insertXrefEntry(obj, toI(fields[0]), fields[1], toI(fields[2])); |
| 1176 | } | 1175 | } |
| 1177 | 1176 | ||
| 1178 | - if (!this->m->trailer.isInitialized()) { | 1177 | + if (!m->trailer.isInitialized()) { |
| 1179 | setTrailer(dict); | 1178 | setTrailer(dict); |
| 1180 | } | 1179 | } |
| 1181 | 1180 | ||
| @@ -1211,16 +1210,16 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | @@ -1211,16 +1210,16 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | ||
| 1211 | { // private scope | 1210 | { // private scope |
| 1212 | int gen = (f0 == 2 ? 0 : f2); | 1211 | int gen = (f0 == 2 ? 0 : f2); |
| 1213 | QPDFObjGen og(obj, gen); | 1212 | QPDFObjGen og(obj, gen); |
| 1214 | - if (this->m->xref_table.count(og)) { | 1213 | + if (m->xref_table.count(og)) { |
| 1215 | if (overwrite) { | 1214 | if (overwrite) { |
| 1216 | QTC::TC("qpdf", "QPDF xref overwrite object"); | 1215 | QTC::TC("qpdf", "QPDF xref overwrite object"); |
| 1217 | - this->m->xref_table.erase(og); | 1216 | + m->xref_table.erase(og); |
| 1218 | } else { | 1217 | } else { |
| 1219 | QTC::TC("qpdf", "QPDF xref reused object"); | 1218 | QTC::TC("qpdf", "QPDF xref reused object"); |
| 1220 | return; | 1219 | return; |
| 1221 | } | 1220 | } |
| 1222 | } | 1221 | } |
| 1223 | - if (this->m->deleted_objects.count(obj)) { | 1222 | + if (m->deleted_objects.count(obj)) { |
| 1224 | QTC::TC("qpdf", "QPDF xref deleted object"); | 1223 | QTC::TC("qpdf", "QPDF xref deleted object"); |
| 1225 | return; | 1224 | return; |
| 1226 | } | 1225 | } |
| @@ -1228,17 +1227,17 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | @@ -1228,17 +1227,17 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | ||
| 1228 | 1227 | ||
| 1229 | switch (f0) { | 1228 | switch (f0) { |
| 1230 | case 0: | 1229 | case 0: |
| 1231 | - this->m->deleted_objects.insert(obj); | 1230 | + m->deleted_objects.insert(obj); |
| 1232 | break; | 1231 | break; |
| 1233 | 1232 | ||
| 1234 | case 1: | 1233 | case 1: |
| 1235 | // f2 is generation | 1234 | // f2 is generation |
| 1236 | QTC::TC("qpdf", "QPDF xref gen > 0", ((f2 > 0) ? 1 : 0)); | 1235 | QTC::TC("qpdf", "QPDF xref gen > 0", ((f2 > 0) ? 1 : 0)); |
| 1237 | - this->m->xref_table[QPDFObjGen(obj, f2)] = QPDFXRefEntry(f1); | 1236 | + m->xref_table[QPDFObjGen(obj, f2)] = QPDFXRefEntry(f1); |
| 1238 | break; | 1237 | break; |
| 1239 | 1238 | ||
| 1240 | case 2: | 1239 | case 2: |
| 1241 | - this->m->xref_table[QPDFObjGen(obj, 0)] = QPDFXRefEntry(toI(f1), f2); | 1240 | + m->xref_table[QPDFObjGen(obj, 0)] = QPDFXRefEntry(toI(f1), f2); |
| 1242 | break; | 1241 | break; |
| 1243 | 1242 | ||
| 1244 | default: | 1243 | default: |
| @@ -1252,8 +1251,8 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | @@ -1252,8 +1251,8 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | ||
| 1252 | void | 1251 | void |
| 1253 | QPDF::showXRefTable() | 1252 | QPDF::showXRefTable() |
| 1254 | { | 1253 | { |
| 1255 | - auto& cout = *this->m->log->getInfo(); | ||
| 1256 | - for (auto const& iter: this->m->xref_table) { | 1254 | + auto& cout = *m->log->getInfo(); |
| 1255 | + for (auto const& iter: m->xref_table) { | ||
| 1257 | QPDFObjGen const& og = iter.first; | 1256 | QPDFObjGen const& og = iter.first; |
| 1258 | QPDFXRefEntry const& entry = iter.second; | 1257 | QPDFXRefEntry const& entry = iter.second; |
| 1259 | cout << og.unparse('/') << ": "; | 1258 | cout << og.unparse('/') << ": "; |
| @@ -1263,7 +1262,7 @@ QPDF::showXRefTable() | @@ -1263,7 +1262,7 @@ QPDF::showXRefTable() | ||
| 1263 | break; | 1262 | break; |
| 1264 | 1263 | ||
| 1265 | case 2: | 1264 | case 2: |
| 1266 | - *this->m->log->getInfo() | 1265 | + *m->log->getInfo() |
| 1267 | << "compressed; stream = " << entry.getObjStreamNumber() | 1266 | << "compressed; stream = " << entry.getObjStreamNumber() |
| 1268 | << ", index = " << entry.getObjStreamIndex(); | 1267 | << ", index = " << entry.getObjStreamIndex(); |
| 1269 | break; | 1268 | break; |
| @@ -1273,7 +1272,7 @@ QPDF::showXRefTable() | @@ -1273,7 +1272,7 @@ QPDF::showXRefTable() | ||
| 1273 | " showing xref_table"); | 1272 | " showing xref_table"); |
| 1274 | break; | 1273 | break; |
| 1275 | } | 1274 | } |
| 1276 | - this->m->log->info("\n"); | 1275 | + m->log->info("\n"); |
| 1277 | } | 1276 | } |
| 1278 | } | 1277 | } |
| 1279 | 1278 | ||
| @@ -1282,11 +1281,11 @@ QPDF::showXRefTable() | @@ -1282,11 +1281,11 @@ QPDF::showXRefTable() | ||
| 1282 | bool | 1281 | bool |
| 1283 | QPDF::resolveXRefTable() | 1282 | QPDF::resolveXRefTable() |
| 1284 | { | 1283 | { |
| 1285 | - bool may_change = !this->m->reconstructed_xref; | ||
| 1286 | - for (auto& iter: this->m->xref_table) { | 1284 | + bool may_change = !m->reconstructed_xref; |
| 1285 | + for (auto& iter: m->xref_table) { | ||
| 1287 | if (isUnresolved(iter.first)) { | 1286 | if (isUnresolved(iter.first)) { |
| 1288 | resolve(iter.first); | 1287 | resolve(iter.first); |
| 1289 | - if (may_change && this->m->reconstructed_xref) { | 1288 | + if (may_change && m->reconstructed_xref) { |
| 1290 | return false; | 1289 | return false; |
| 1291 | } | 1290 | } |
| 1292 | } | 1291 | } |
| @@ -1299,14 +1298,14 @@ QPDF::resolveXRefTable() | @@ -1299,14 +1298,14 @@ QPDF::resolveXRefTable() | ||
| 1299 | void | 1298 | void |
| 1300 | QPDF::fixDanglingReferences(bool force) | 1299 | QPDF::fixDanglingReferences(bool force) |
| 1301 | { | 1300 | { |
| 1302 | - if (this->m->fixed_dangling_refs) { | 1301 | + if (m->fixed_dangling_refs) { |
| 1303 | return; | 1302 | return; |
| 1304 | } | 1303 | } |
| 1305 | if (!resolveXRefTable()) { | 1304 | if (!resolveXRefTable()) { |
| 1306 | QTC::TC("qpdf", "QPDF fix dangling triggered xref reconstruction"); | 1305 | QTC::TC("qpdf", "QPDF fix dangling triggered xref reconstruction"); |
| 1307 | resolveXRefTable(); | 1306 | resolveXRefTable(); |
| 1308 | } | 1307 | } |
| 1309 | - this->m->fixed_dangling_refs = true; | 1308 | + m->fixed_dangling_refs = true; |
| 1310 | } | 1309 | } |
| 1311 | 1310 | ||
| 1312 | size_t | 1311 | size_t |
| @@ -1318,8 +1317,8 @@ QPDF::getObjectCount() | @@ -1318,8 +1317,8 @@ QPDF::getObjectCount() | ||
| 1318 | // will also be in obj_cache. | 1317 | // will also be in obj_cache. |
| 1319 | fixDanglingReferences(); | 1318 | fixDanglingReferences(); |
| 1320 | QPDFObjGen og; | 1319 | QPDFObjGen og; |
| 1321 | - if (!this->m->obj_cache.empty()) { | ||
| 1322 | - og = (*(this->m->obj_cache.rbegin())).first; | 1320 | + if (!m->obj_cache.empty()) { |
| 1321 | + og = (*(m->obj_cache.rbegin())).first; | ||
| 1323 | } | 1322 | } |
| 1324 | return toS(og.getObj()); | 1323 | return toS(og.getObj()); |
| 1325 | } | 1324 | } |
| @@ -1331,7 +1330,7 @@ QPDF::getAllObjects() | @@ -1331,7 +1330,7 @@ QPDF::getAllObjects() | ||
| 1331 | // object cache. | 1330 | // object cache. |
| 1332 | fixDanglingReferences(); | 1331 | fixDanglingReferences(); |
| 1333 | std::vector<QPDFObjectHandle> result; | 1332 | std::vector<QPDFObjectHandle> result; |
| 1334 | - for (auto const& iter: this->m->obj_cache) { | 1333 | + for (auto const& iter: m->obj_cache) { |
| 1335 | result.push_back(newIndirect(iter.first, iter.second.object)); | 1334 | result.push_back(newIndirect(iter.first, iter.second.object)); |
| 1336 | } | 1335 | } |
| 1337 | return result; | 1336 | return result; |
| @@ -1341,15 +1340,15 @@ void | @@ -1341,15 +1340,15 @@ void | ||
| 1341 | QPDF::setLastObjectDescription( | 1340 | QPDF::setLastObjectDescription( |
| 1342 | std::string const& description, QPDFObjGen const& og) | 1341 | std::string const& description, QPDFObjGen const& og) |
| 1343 | { | 1342 | { |
| 1344 | - this->m->last_object_description.clear(); | 1343 | + m->last_object_description.clear(); |
| 1345 | if (!description.empty()) { | 1344 | if (!description.empty()) { |
| 1346 | - this->m->last_object_description += description; | 1345 | + m->last_object_description += description; |
| 1347 | if (og.isIndirect()) { | 1346 | if (og.isIndirect()) { |
| 1348 | - this->m->last_object_description += ": "; | 1347 | + m->last_object_description += ": "; |
| 1349 | } | 1348 | } |
| 1350 | } | 1349 | } |
| 1351 | if (og.isIndirect()) { | 1350 | if (og.isIndirect()) { |
| 1352 | - this->m->last_object_description += "object " + og.unparse(' '); | 1351 | + m->last_object_description += "object " + og.unparse(' '); |
| 1353 | } | 1352 | } |
| 1354 | } | 1353 | } |
| 1355 | 1354 | ||
| @@ -1366,7 +1365,7 @@ QPDF::readObject( | @@ -1366,7 +1365,7 @@ QPDF::readObject( | ||
| 1366 | bool empty = false; | 1365 | bool empty = false; |
| 1367 | std::shared_ptr<StringDecrypter> decrypter_ph; | 1366 | std::shared_ptr<StringDecrypter> decrypter_ph; |
| 1368 | StringDecrypter* decrypter = nullptr; | 1367 | StringDecrypter* decrypter = nullptr; |
| 1369 | - if (this->m->encp->encrypted && (!in_object_stream)) { | 1368 | + if (m->encp->encrypted && (!in_object_stream)) { |
| 1370 | decrypter_ph = std::make_shared<StringDecrypter>(this, og); | 1369 | decrypter_ph = std::make_shared<StringDecrypter>(this, og); |
| 1371 | decrypter = decrypter_ph.get(); | 1370 | decrypter = decrypter_ph.get(); |
| 1372 | } | 1371 | } |
| @@ -1480,7 +1479,7 @@ QPDF::readObject( | @@ -1480,7 +1479,7 @@ QPDF::readObject( | ||
| 1480 | input, input->getLastOffset(), "expected endstream"); | 1479 | input, input->getLastOffset(), "expected endstream"); |
| 1481 | } | 1480 | } |
| 1482 | } catch (QPDFExc& e) { | 1481 | } catch (QPDFExc& e) { |
| 1483 | - if (this->m->attempt_recovery) { | 1482 | + if (m->attempt_recovery) { |
| 1484 | warn(e); | 1483 | warn(e); |
| 1485 | length = recoverStreamLength(input, og, stream_offset); | 1484 | length = recoverStreamLength(input, og, stream_offset); |
| 1486 | } else { | 1485 | } else { |
| @@ -1507,7 +1506,7 @@ QPDF::findEndstream() | @@ -1507,7 +1506,7 @@ QPDF::findEndstream() | ||
| 1507 | // Find endstream or endobj. Position the input at that token. | 1506 | // Find endstream or endobj. Position the input at that token. |
| 1508 | auto t = readToken(m->file, 20); | 1507 | auto t = readToken(m->file, 20); |
| 1509 | if (t.isWord("endobj") || t.isWord("endstream")) { | 1508 | if (t.isWord("endobj") || t.isWord("endstream")) { |
| 1510 | - this->m->file->seek(this->m->file->getLastOffset(), SEEK_SET); | 1509 | + m->file->seek(m->file->getLastOffset(), SEEK_SET); |
| 1511 | return true; | 1510 | return true; |
| 1512 | } | 1511 | } |
| 1513 | return false; | 1512 | return false; |
| @@ -1526,12 +1525,12 @@ QPDF::recoverStreamLength( | @@ -1526,12 +1525,12 @@ QPDF::recoverStreamLength( | ||
| 1526 | 1525 | ||
| 1527 | PatternFinder ef(*this, &QPDF::findEndstream); | 1526 | PatternFinder ef(*this, &QPDF::findEndstream); |
| 1528 | size_t length = 0; | 1527 | size_t length = 0; |
| 1529 | - if (this->m->file->findFirst("end", stream_offset, 0, ef)) { | ||
| 1530 | - length = toS(this->m->file->tell() - stream_offset); | 1528 | + if (m->file->findFirst("end", stream_offset, 0, ef)) { |
| 1529 | + length = toS(m->file->tell() - stream_offset); | ||
| 1531 | // Reread endstream but, if it was endobj, don't skip that. | 1530 | // Reread endstream but, if it was endobj, don't skip that. |
| 1532 | - QPDFTokenizer::Token t = readToken(this->m->file); | 1531 | + QPDFTokenizer::Token t = readToken(m->file); |
| 1533 | if (t.getValue() == "endobj") { | 1532 | if (t.getValue() == "endobj") { |
| 1534 | - this->m->file->seek(this->m->file->getLastOffset(), SEEK_SET); | 1533 | + m->file->seek(m->file->getLastOffset(), SEEK_SET); |
| 1535 | } | 1534 | } |
| 1536 | } | 1535 | } |
| 1537 | 1536 | ||
| @@ -1540,7 +1539,7 @@ QPDF::recoverStreamLength( | @@ -1540,7 +1539,7 @@ QPDF::recoverStreamLength( | ||
| 1540 | QPDFObjGen this_og; | 1539 | QPDFObjGen this_og; |
| 1541 | 1540 | ||
| 1542 | // Make sure this is inside this object | 1541 | // Make sure this is inside this object |
| 1543 | - for (auto const& iter: this->m->xref_table) { | 1542 | + for (auto const& iter: m->xref_table) { |
| 1544 | QPDFXRefEntry const& entry = iter.second; | 1543 | QPDFXRefEntry const& entry = iter.second; |
| 1545 | if (entry.getType() == 1) { | 1544 | if (entry.getType() == 1) { |
| 1546 | qpdf_offset_t obj_offset = entry.getOffset(); | 1545 | qpdf_offset_t obj_offset = entry.getOffset(); |
| @@ -1580,8 +1579,8 @@ QPDF::recoverStreamLength( | @@ -1580,8 +1579,8 @@ QPDF::recoverStreamLength( | ||
| 1580 | QPDFTokenizer::Token | 1579 | QPDFTokenizer::Token |
| 1581 | QPDF::readToken(std::shared_ptr<InputSource> input, size_t max_len) | 1580 | QPDF::readToken(std::shared_ptr<InputSource> input, size_t max_len) |
| 1582 | { | 1581 | { |
| 1583 | - return this->m->tokenizer.readToken( | ||
| 1584 | - input, this->m->last_object_description, true, max_len); | 1582 | + return m->tokenizer.readToken( |
| 1583 | + input, m->last_object_description, true, max_len); | ||
| 1585 | } | 1584 | } |
| 1586 | 1585 | ||
| 1587 | QPDFObjectHandle | 1586 | QPDFObjectHandle |
| @@ -1608,7 +1607,7 @@ QPDF::readObjectAtOffset( | @@ -1608,7 +1607,7 @@ QPDF::readObjectAtOffset( | ||
| 1608 | } | 1607 | } |
| 1609 | setLastObjectDescription(description, exp_og); | 1608 | setLastObjectDescription(description, exp_og); |
| 1610 | 1609 | ||
| 1611 | - if (!this->m->attempt_recovery) { | 1610 | + if (!m->attempt_recovery) { |
| 1612 | try_recovery = false; | 1611 | try_recovery = false; |
| 1613 | } | 1612 | } |
| 1614 | 1613 | ||
| @@ -1623,11 +1622,11 @@ QPDF::readObjectAtOffset( | @@ -1623,11 +1622,11 @@ QPDF::readObjectAtOffset( | ||
| 1623 | return QPDFObjectHandle::newNull(); | 1622 | return QPDFObjectHandle::newNull(); |
| 1624 | } | 1623 | } |
| 1625 | 1624 | ||
| 1626 | - this->m->file->seek(offset, SEEK_SET); | 1625 | + m->file->seek(offset, SEEK_SET); |
| 1627 | 1626 | ||
| 1628 | - QPDFTokenizer::Token tobjid = readToken(this->m->file); | ||
| 1629 | - QPDFTokenizer::Token tgen = readToken(this->m->file); | ||
| 1630 | - QPDFTokenizer::Token tobj = readToken(this->m->file); | 1627 | + QPDFTokenizer::Token tobjid = readToken(m->file); |
| 1628 | + QPDFTokenizer::Token tgen = readToken(m->file); | ||
| 1629 | + QPDFTokenizer::Token tobj = readToken(m->file); | ||
| 1631 | 1630 | ||
| 1632 | bool objidok = tobjid.isInteger(); | 1631 | bool objidok = tobjid.isInteger(); |
| 1633 | bool genok = tgen.isInteger(); | 1632 | bool genok = tgen.isInteger(); |
| @@ -1666,10 +1665,9 @@ QPDF::readObjectAtOffset( | @@ -1666,10 +1665,9 @@ QPDF::readObjectAtOffset( | ||
| 1666 | if (try_recovery) { | 1665 | if (try_recovery) { |
| 1667 | // Try again after reconstructing xref table | 1666 | // Try again after reconstructing xref table |
| 1668 | reconstruct_xref(e); | 1667 | reconstruct_xref(e); |
| 1669 | - if (this->m->xref_table.count(exp_og) && | ||
| 1670 | - (this->m->xref_table[exp_og].getType() == 1)) { | ||
| 1671 | - qpdf_offset_t new_offset = | ||
| 1672 | - this->m->xref_table[exp_og].getOffset(); | 1668 | + if (m->xref_table.count(exp_og) && |
| 1669 | + (m->xref_table[exp_og].getType() == 1)) { | ||
| 1670 | + qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset(); | ||
| 1673 | QPDFObjectHandle result = readObjectAtOffset( | 1671 | QPDFObjectHandle result = readObjectAtOffset( |
| 1674 | false, new_offset, description, exp_og, og, false); | 1672 | false, new_offset, description, exp_og, og, false); |
| 1675 | QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset"); | 1673 | QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset"); |
| @@ -1689,9 +1687,9 @@ QPDF::readObjectAtOffset( | @@ -1689,9 +1687,9 @@ QPDF::readObjectAtOffset( | ||
| 1689 | } | 1687 | } |
| 1690 | } | 1688 | } |
| 1691 | 1689 | ||
| 1692 | - QPDFObjectHandle oh = readObject(this->m->file, description, og, false); | 1690 | + QPDFObjectHandle oh = readObject(m->file, description, og, false); |
| 1693 | 1691 | ||
| 1694 | - if (!readToken(this->m->file).isWord("endobj")) { | 1692 | + if (!readToken(m->file).isWord("endobj")) { |
| 1695 | QTC::TC("qpdf", "QPDF err expected endobj"); | 1693 | QTC::TC("qpdf", "QPDF err expected endobj"); |
| 1696 | warn(damagedPDF("expected endobj")); | 1694 | warn(damagedPDF("expected endobj")); |
| 1697 | } | 1695 | } |
| @@ -1707,22 +1705,22 @@ QPDF::readObjectAtOffset( | @@ -1707,22 +1705,22 @@ QPDF::readObjectAtOffset( | ||
| 1707 | // linearization hint tables. Offsets and lengths of objects | 1705 | // linearization hint tables. Offsets and lengths of objects |
| 1708 | // may imply the end of an object to be anywhere between these | 1706 | // may imply the end of an object to be anywhere between these |
| 1709 | // values. | 1707 | // values. |
| 1710 | - qpdf_offset_t end_before_space = this->m->file->tell(); | 1708 | + qpdf_offset_t end_before_space = m->file->tell(); |
| 1711 | 1709 | ||
| 1712 | // skip over spaces | 1710 | // skip over spaces |
| 1713 | while (true) { | 1711 | while (true) { |
| 1714 | char ch; | 1712 | char ch; |
| 1715 | - if (this->m->file->read(&ch, 1)) { | 1713 | + if (m->file->read(&ch, 1)) { |
| 1716 | if (!isspace(static_cast<unsigned char>(ch))) { | 1714 | if (!isspace(static_cast<unsigned char>(ch))) { |
| 1717 | - this->m->file->seek(-1, SEEK_CUR); | 1715 | + m->file->seek(-1, SEEK_CUR); |
| 1718 | break; | 1716 | break; |
| 1719 | } | 1717 | } |
| 1720 | } else { | 1718 | } else { |
| 1721 | throw damagedPDF(m->file->tell(), "EOF after endobj"); | 1719 | throw damagedPDF(m->file->tell(), "EOF after endobj"); |
| 1722 | } | 1720 | } |
| 1723 | } | 1721 | } |
| 1724 | - qpdf_offset_t end_after_space = this->m->file->tell(); | ||
| 1725 | - if (skip_cache_if_in_xref && this->m->xref_table.count(og)) { | 1722 | + qpdf_offset_t end_after_space = m->file->tell(); |
| 1723 | + if (skip_cache_if_in_xref && m->xref_table.count(og)) { | ||
| 1726 | // Ordinarily, an object gets read here when resolved | 1724 | // Ordinarily, an object gets read here when resolved |
| 1727 | // through xref table or stream. In the special case of | 1725 | // through xref table or stream. In the special case of |
| 1728 | // the xref stream and linearization hint tables, the | 1726 | // the xref stream and linearization hint tables, the |
| @@ -1774,7 +1772,7 @@ QPDF::resolve(QPDFObjGen og) | @@ -1774,7 +1772,7 @@ QPDF::resolve(QPDFObjGen og) | ||
| 1774 | return; | 1772 | return; |
| 1775 | } | 1773 | } |
| 1776 | 1774 | ||
| 1777 | - if (this->m->resolving.count(og)) { | 1775 | + if (m->resolving.count(og)) { |
| 1778 | // This can happen if an object references itself directly or | 1776 | // This can happen if an object references itself directly or |
| 1779 | // indirectly in some key that has to be resolved during | 1777 | // indirectly in some key that has to be resolved during |
| 1780 | // object parsing, such as stream length. | 1778 | // object parsing, such as stream length. |
| @@ -1787,7 +1785,7 @@ QPDF::resolve(QPDFObjGen og) | @@ -1787,7 +1785,7 @@ QPDF::resolve(QPDFObjGen og) | ||
| 1787 | ResolveRecorder rr(this, og); | 1785 | ResolveRecorder rr(this, og); |
| 1788 | 1786 | ||
| 1789 | if (m->xref_table.count(og) != 0) { | 1787 | if (m->xref_table.count(og) != 0) { |
| 1790 | - QPDFXRefEntry const& entry = this->m->xref_table[og]; | 1788 | + QPDFXRefEntry const& entry = m->xref_table[og]; |
| 1791 | try { | 1789 | try { |
| 1792 | switch (entry.getType()) { | 1790 | switch (entry.getType()) { |
| 1793 | case 1: | 1791 | case 1: |
| @@ -1828,17 +1826,17 @@ QPDF::resolve(QPDFObjGen og) | @@ -1828,17 +1826,17 @@ QPDF::resolve(QPDFObjGen og) | ||
| 1828 | updateCache(og, QPDF_Null::create(), -1, -1); | 1826 | updateCache(og, QPDF_Null::create(), -1, -1); |
| 1829 | } | 1827 | } |
| 1830 | 1828 | ||
| 1831 | - auto result(this->m->obj_cache[og].object); | 1829 | + auto result(m->obj_cache[og].object); |
| 1832 | result->setDefaultDescription(this, og); | 1830 | result->setDefaultDescription(this, og); |
| 1833 | } | 1831 | } |
| 1834 | 1832 | ||
| 1835 | void | 1833 | void |
| 1836 | QPDF::resolveObjectsInStream(int obj_stream_number) | 1834 | QPDF::resolveObjectsInStream(int obj_stream_number) |
| 1837 | { | 1835 | { |
| 1838 | - if (this->m->resolved_object_streams.count(obj_stream_number)) { | 1836 | + if (m->resolved_object_streams.count(obj_stream_number)) { |
| 1839 | return; | 1837 | return; |
| 1840 | } | 1838 | } |
| 1841 | - this->m->resolved_object_streams.insert(obj_stream_number); | 1839 | + m->resolved_object_streams.insert(obj_stream_number); |
| 1842 | // Force resolution of object stream | 1840 | // Force resolution of object stream |
| 1843 | QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0); | 1841 | QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0); |
| 1844 | if (!obj_stream.isStream()) { | 1842 | if (!obj_stream.isStream()) { |
| @@ -1850,10 +1848,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1850,10 +1848,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1850 | // For linearization data in the object, use the data from the | 1848 | // For linearization data in the object, use the data from the |
| 1851 | // object stream for the objects in the stream. | 1849 | // object stream for the objects in the stream. |
| 1852 | QPDFObjGen stream_og(obj_stream_number, 0); | 1850 | QPDFObjGen stream_og(obj_stream_number, 0); |
| 1853 | - qpdf_offset_t end_before_space = | ||
| 1854 | - this->m->obj_cache[stream_og].end_before_space; | ||
| 1855 | - qpdf_offset_t end_after_space = | ||
| 1856 | - this->m->obj_cache[stream_og].end_after_space; | 1851 | + qpdf_offset_t end_before_space = m->obj_cache[stream_og].end_before_space; |
| 1852 | + qpdf_offset_t end_after_space = m->obj_cache[stream_og].end_after_space; | ||
| 1857 | 1853 | ||
| 1858 | QPDFObjectHandle dict = obj_stream.getDict(); | 1854 | QPDFObjectHandle dict = obj_stream.getDict(); |
| 1859 | if (!dict.isDictionaryOfType("/ObjStm")) { | 1855 | if (!dict.isDictionaryOfType("/ObjStm")) { |
| @@ -1878,7 +1874,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1878,7 +1874,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1878 | auto input = std::shared_ptr<InputSource>( | 1874 | auto input = std::shared_ptr<InputSource>( |
| 1879 | // line-break | 1875 | // line-break |
| 1880 | new BufferInputSource( | 1876 | new BufferInputSource( |
| 1881 | - (this->m->file->getName() + " object stream " + | 1877 | + (m->file->getName() + " object stream " + |
| 1882 | std::to_string(obj_stream_number)), | 1878 | std::to_string(obj_stream_number)), |
| 1883 | bp.get())); | 1879 | bp.get())); |
| 1884 | 1880 | ||
| @@ -1888,7 +1884,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1888,7 +1884,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1888 | if (!(tnum.isInteger() && toffset.isInteger())) { | 1884 | if (!(tnum.isInteger() && toffset.isInteger())) { |
| 1889 | throw damagedPDF( | 1885 | throw damagedPDF( |
| 1890 | input, | 1886 | input, |
| 1891 | - this->m->last_object_description, | 1887 | + m->last_object_description, |
| 1892 | input->getLastOffset(), | 1888 | input->getLastOffset(), |
| 1893 | "expected integer in object stream header"); | 1889 | "expected integer in object stream header"); |
| 1894 | } | 1890 | } |
| @@ -1905,7 +1901,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1905,7 +1901,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1905 | // xref table and only cache what would actually be resolved here. | 1901 | // xref table and only cache what would actually be resolved here. |
| 1906 | for (auto const& iter: offsets) { | 1902 | for (auto const& iter: offsets) { |
| 1907 | QPDFObjGen og(iter.first, 0); | 1903 | QPDFObjGen og(iter.first, 0); |
| 1908 | - QPDFXRefEntry const& entry = this->m->xref_table[og]; | 1904 | + QPDFXRefEntry const& entry = m->xref_table[og]; |
| 1909 | if ((entry.getType() == 2) && | 1905 | if ((entry.getType() == 2) && |
| 1910 | (entry.getObjStreamNumber() == obj_stream_number)) { | 1906 | (entry.getObjStreamNumber() == obj_stream_number)) { |
| 1911 | int offset = iter.second; | 1907 | int offset = iter.second; |
| @@ -2146,7 +2142,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | @@ -2146,7 +2142,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | ||
| 2146 | "QPDF::copyForeign called with object from this QPDF"); | 2142 | "QPDF::copyForeign called with object from this QPDF"); |
| 2147 | } | 2143 | } |
| 2148 | 2144 | ||
| 2149 | - ObjCopier& obj_copier = this->m->object_copiers[other.m->unique_id]; | 2145 | + ObjCopier& obj_copier = m->object_copiers[other.m->unique_id]; |
| 2150 | if (!obj_copier.visiting.empty()) { | 2146 | if (!obj_copier.visiting.empty()) { |
| 2151 | throw std::logic_error("obj_copier.visiting is not empty" | 2147 | throw std::logic_error("obj_copier.visiting is not empty" |
| 2152 | " at the beginning of copyForeignObject"); | 2148 | " at the beginning of copyForeignObject"); |
| @@ -2310,12 +2306,11 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2310,12 +2306,11 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2310 | 2306 | ||
| 2311 | QPDFObjectHandle dict = result.getDict(); | 2307 | QPDFObjectHandle dict = result.getDict(); |
| 2312 | QPDFObjectHandle old_dict = foreign.getDict(); | 2308 | QPDFObjectHandle old_dict = foreign.getDict(); |
| 2313 | - if (this->m->copied_stream_data_provider == nullptr) { | ||
| 2314 | - this->m->copied_stream_data_provider = | ||
| 2315 | - new CopiedStreamDataProvider(*this); | ||
| 2316 | - this->m->copied_streams = | 2309 | + if (m->copied_stream_data_provider == nullptr) { |
| 2310 | + m->copied_stream_data_provider = new CopiedStreamDataProvider(*this); | ||
| 2311 | + m->copied_streams = | ||
| 2317 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider>( | 2312 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider>( |
| 2318 | - this->m->copied_stream_data_provider); | 2313 | + m->copied_stream_data_provider); |
| 2319 | } | 2314 | } |
| 2320 | QPDFObjGen local_og(result.getObjGen()); | 2315 | QPDFObjGen local_og(result.getObjGen()); |
| 2321 | // Copy information from the foreign stream so we can pipe its | 2316 | // Copy information from the foreign stream so we can pipe its |
| @@ -2352,10 +2347,10 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2352,10 +2347,10 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2352 | } else if (stream_provider.get()) { | 2347 | } else if (stream_provider.get()) { |
| 2353 | // In this case, the remote stream's QPDF must stay in scope. | 2348 | // In this case, the remote stream's QPDF must stay in scope. |
| 2354 | QTC::TC("qpdf", "QPDF copy foreign stream with provider"); | 2349 | QTC::TC("qpdf", "QPDF copy foreign stream with provider"); |
| 2355 | - this->m->copied_stream_data_provider->registerForeignStream( | 2350 | + m->copied_stream_data_provider->registerForeignStream( |
| 2356 | local_og, foreign); | 2351 | local_og, foreign); |
| 2357 | result.replaceStreamData( | 2352 | result.replaceStreamData( |
| 2358 | - this->m->copied_streams, | 2353 | + m->copied_streams, |
| 2359 | dict.getKey("/Filter"), | 2354 | dict.getKey("/Filter"), |
| 2360 | dict.getKey("/DecodeParms")); | 2355 | dict.getKey("/DecodeParms")); |
| 2361 | } else { | 2356 | } else { |
| @@ -2366,10 +2361,10 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2366,10 +2361,10 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2366 | stream->getParsedOffset(), | 2361 | stream->getParsedOffset(), |
| 2367 | stream->getLength(), | 2362 | stream->getLength(), |
| 2368 | dict); | 2363 | dict); |
| 2369 | - this->m->copied_stream_data_provider->registerForeignStream( | 2364 | + m->copied_stream_data_provider->registerForeignStream( |
| 2370 | local_og, foreign_stream_data); | 2365 | local_og, foreign_stream_data); |
| 2371 | result.replaceStreamData( | 2366 | result.replaceStreamData( |
| 2372 | - this->m->copied_streams, | 2367 | + m->copied_streams, |
| 2373 | dict.getKey("/Filter"), | 2368 | dict.getKey("/Filter"), |
| 2374 | dict.getKey("/DecodeParms")); | 2369 | dict.getKey("/DecodeParms")); |
| 2375 | } | 2370 | } |
| @@ -2395,13 +2390,13 @@ QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2) | @@ -2395,13 +2390,13 @@ QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2) | ||
| 2395 | unsigned long long | 2390 | unsigned long long |
| 2396 | QPDF::getUniqueId() const | 2391 | QPDF::getUniqueId() const |
| 2397 | { | 2392 | { |
| 2398 | - return this->m->unique_id; | 2393 | + return m->unique_id; |
| 2399 | } | 2394 | } |
| 2400 | 2395 | ||
| 2401 | std::string | 2396 | std::string |
| 2402 | QPDF::getFilename() const | 2397 | QPDF::getFilename() const |
| 2403 | { | 2398 | { |
| 2404 | - return this->m->file->getName(); | 2399 | + return m->file->getName(); |
| 2405 | } | 2400 | } |
| 2406 | 2401 | ||
| 2407 | PDFVersion | 2402 | PDFVersion |
| @@ -2412,10 +2407,10 @@ QPDF::getVersionAsPDFVersion() | @@ -2412,10 +2407,10 @@ QPDF::getVersionAsPDFVersion() | ||
| 2412 | int extension_level = getExtensionLevel(); | 2407 | int extension_level = getExtensionLevel(); |
| 2413 | 2408 | ||
| 2414 | std::regex v("^[[:space:]]*([0-9]+)\\.([0-9]+)"); | 2409 | std::regex v("^[[:space:]]*([0-9]+)\\.([0-9]+)"); |
| 2415 | - std::smatch m; | ||
| 2416 | - if (std::regex_search(this->m->pdf_version, m, v)) { | ||
| 2417 | - major = QUtil::string_to_int(m[1].str().c_str()); | ||
| 2418 | - minor = QUtil::string_to_int(m[2].str().c_str()); | 2410 | + std::smatch match; |
| 2411 | + if (std::regex_search(m->pdf_version, match, v)) { | ||
| 2412 | + major = QUtil::string_to_int(match[1].str().c_str()); | ||
| 2413 | + minor = QUtil::string_to_int(match[2].str().c_str()); | ||
| 2419 | } | 2414 | } |
| 2420 | 2415 | ||
| 2421 | return PDFVersion(major, minor, extension_level); | 2416 | return PDFVersion(major, minor, extension_level); |
| @@ -2424,7 +2419,7 @@ QPDF::getVersionAsPDFVersion() | @@ -2424,7 +2419,7 @@ QPDF::getVersionAsPDFVersion() | ||
| 2424 | std::string | 2419 | std::string |
| 2425 | QPDF::getPDFVersion() const | 2420 | QPDF::getPDFVersion() const |
| 2426 | { | 2421 | { |
| 2427 | - return this->m->pdf_version; | 2422 | + return m->pdf_version; |
| 2428 | } | 2423 | } |
| 2429 | 2424 | ||
| 2430 | int | 2425 | int |
| @@ -2450,13 +2445,13 @@ QPDF::getExtensionLevel() | @@ -2450,13 +2445,13 @@ QPDF::getExtensionLevel() | ||
| 2450 | QPDFObjectHandle | 2445 | QPDFObjectHandle |
| 2451 | QPDF::getTrailer() | 2446 | QPDF::getTrailer() |
| 2452 | { | 2447 | { |
| 2453 | - return this->m->trailer; | 2448 | + return m->trailer; |
| 2454 | } | 2449 | } |
| 2455 | 2450 | ||
| 2456 | QPDFObjectHandle | 2451 | QPDFObjectHandle |
| 2457 | QPDF::getRoot() | 2452 | QPDF::getRoot() |
| 2458 | { | 2453 | { |
| 2459 | - QPDFObjectHandle root = this->m->trailer.getKey("/Root"); | 2454 | + QPDFObjectHandle root = m->trailer.getKey("/Root"); |
| 2460 | if (!root.isDictionary()) { | 2455 | if (!root.isDictionary()) { |
| 2461 | throw damagedPDF("", 0, "unable to find /Root dictionary"); | 2456 | throw damagedPDF("", 0, "unable to find /Root dictionary"); |
| 2462 | } else if ( | 2457 | } else if ( |
| @@ -2473,17 +2468,17 @@ QPDF::getRoot() | @@ -2473,17 +2468,17 @@ QPDF::getRoot() | ||
| 2473 | std::map<QPDFObjGen, QPDFXRefEntry> | 2468 | std::map<QPDFObjGen, QPDFXRefEntry> |
| 2474 | QPDF::getXRefTable() | 2469 | QPDF::getXRefTable() |
| 2475 | { | 2470 | { |
| 2476 | - if (!this->m->parsed) { | 2471 | + if (!m->parsed) { |
| 2477 | throw std::logic_error("QPDF::getXRefTable called before parsing."); | 2472 | throw std::logic_error("QPDF::getXRefTable called before parsing."); |
| 2478 | } | 2473 | } |
| 2479 | 2474 | ||
| 2480 | - return this->m->xref_table; | 2475 | + return m->xref_table; |
| 2481 | } | 2476 | } |
| 2482 | 2477 | ||
| 2483 | void | 2478 | void |
| 2484 | QPDF::getObjectStreamData(std::map<int, int>& omap) | 2479 | QPDF::getObjectStreamData(std::map<int, int>& omap) |
| 2485 | { | 2480 | { |
| 2486 | - for (auto const& iter: this->m->xref_table) { | 2481 | + for (auto const& iter: m->xref_table) { |
| 2487 | QPDFObjGen const& og = iter.first; | 2482 | QPDFObjGen const& og = iter.first; |
| 2488 | QPDFXRefEntry const& entry = iter.second; | 2483 | QPDFXRefEntry const& entry = iter.second; |
| 2489 | if (entry.getType() == 2) { | 2484 | if (entry.getType() == 2) { |
| @@ -2505,12 +2500,12 @@ QPDF::getCompressibleObjGens() | @@ -2505,12 +2500,12 @@ QPDF::getCompressibleObjGens() | ||
| 2505 | // orphaned items. | 2500 | // orphaned items. |
| 2506 | 2501 | ||
| 2507 | // Exclude encryption dictionary, if any | 2502 | // Exclude encryption dictionary, if any |
| 2508 | - QPDFObjectHandle encryption_dict = this->m->trailer.getKey("/Encrypt"); | 2503 | + QPDFObjectHandle encryption_dict = m->trailer.getKey("/Encrypt"); |
| 2509 | QPDFObjGen encryption_dict_og = encryption_dict.getObjGen(); | 2504 | QPDFObjGen encryption_dict_og = encryption_dict.getObjGen(); |
| 2510 | 2505 | ||
| 2511 | QPDFObjGen::set visited; | 2506 | QPDFObjGen::set visited; |
| 2512 | std::list<QPDFObjectHandle> queue; | 2507 | std::list<QPDFObjectHandle> queue; |
| 2513 | - queue.push_front(this->m->trailer); | 2508 | + queue.push_front(m->trailer); |
| 2514 | std::vector<QPDFObjGen> result; | 2509 | std::vector<QPDFObjGen> result; |
| 2515 | while (!queue.empty()) { | 2510 | while (!queue.empty()) { |
| 2516 | QPDFObjectHandle obj = queue.front(); | 2511 | QPDFObjectHandle obj = queue.front(); |
| @@ -2647,8 +2642,8 @@ QPDF::pipeStreamData( | @@ -2647,8 +2642,8 @@ QPDF::pipeStreamData( | ||
| 2647 | bool will_retry) | 2642 | bool will_retry) |
| 2648 | { | 2643 | { |
| 2649 | return pipeStreamData( | 2644 | return pipeStreamData( |
| 2650 | - this->m->encp, | ||
| 2651 | - this->m->file, | 2645 | + m->encp, |
| 2646 | + m->file, | ||
| 2652 | *this, | 2647 | *this, |
| 2653 | og, | 2648 | og, |
| 2654 | offset, | 2649 | offset, |
| @@ -2753,13 +2748,13 @@ QPDF::damagedPDF(std::string const& message) | @@ -2753,13 +2748,13 @@ QPDF::damagedPDF(std::string const& message) | ||
| 2753 | bool | 2748 | bool |
| 2754 | QPDF::everCalledGetAllPages() const | 2749 | QPDF::everCalledGetAllPages() const |
| 2755 | { | 2750 | { |
| 2756 | - return this->m->ever_called_get_all_pages; | 2751 | + return m->ever_called_get_all_pages; |
| 2757 | } | 2752 | } |
| 2758 | 2753 | ||
| 2759 | bool | 2754 | bool |
| 2760 | QPDF::everPushedInheritedAttributesToPages() const | 2755 | QPDF::everPushedInheritedAttributesToPages() const |
| 2761 | { | 2756 | { |
| 2762 | - return this->m->ever_pushed_inherited_attributes_to_pages; | 2757 | + return m->ever_pushed_inherited_attributes_to_pages; |
| 2763 | } | 2758 | } |
| 2764 | 2759 | ||
| 2765 | void | 2760 | void |
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -24,9 +24,9 @@ QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : | @@ -24,9 +24,9 @@ QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : | ||
| 24 | void | 24 | void |
| 25 | QPDFAcroFormDocumentHelper::invalidateCache() | 25 | QPDFAcroFormDocumentHelper::invalidateCache() |
| 26 | { | 26 | { |
| 27 | - this->m->cache_valid = false; | ||
| 28 | - this->m->field_to_annotations.clear(); | ||
| 29 | - this->m->annotation_to_field.clear(); | 27 | + m->cache_valid = false; |
| 28 | + m->field_to_annotations.clear(); | ||
| 29 | + m->annotation_to_field.clear(); | ||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | bool | 32 | bool |
| @@ -133,21 +133,20 @@ QPDFAcroFormDocumentHelper::removeFormFields( | @@ -133,21 +133,20 @@ QPDFAcroFormDocumentHelper::removeFormFields( | ||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | for (auto const& og: to_remove) { | 135 | for (auto const& og: to_remove) { |
| 136 | - auto annotations = this->m->field_to_annotations.find(og); | ||
| 137 | - if (annotations != this->m->field_to_annotations.end()) { | 136 | + auto annotations = m->field_to_annotations.find(og); |
| 137 | + if (annotations != m->field_to_annotations.end()) { | ||
| 138 | for (auto aoh: annotations->second) { | 138 | for (auto aoh: annotations->second) { |
| 139 | - this->m->annotation_to_field.erase( | ||
| 140 | - aoh.getObjectHandle().getObjGen()); | 139 | + m->annotation_to_field.erase(aoh.getObjectHandle().getObjGen()); |
| 141 | } | 140 | } |
| 142 | - this->m->field_to_annotations.erase(og); | 141 | + m->field_to_annotations.erase(og); |
| 143 | } | 142 | } |
| 144 | - auto name = this->m->field_to_name.find(og); | ||
| 145 | - if (name != this->m->field_to_name.end()) { | ||
| 146 | - this->m->name_to_fields[name->second].erase(og); | ||
| 147 | - if (this->m->name_to_fields[name->second].empty()) { | ||
| 148 | - this->m->name_to_fields.erase(name->second); | 143 | + auto name = m->field_to_name.find(og); |
| 144 | + if (name != m->field_to_name.end()) { | ||
| 145 | + m->name_to_fields[name->second].erase(og); | ||
| 146 | + if (m->name_to_fields[name->second].empty()) { | ||
| 147 | + m->name_to_fields.erase(name->second); | ||
| 149 | } | 148 | } |
| 150 | - this->m->field_to_name.erase(og); | 149 | + m->field_to_name.erase(og); |
| 151 | } | 150 | } |
| 152 | } | 151 | } |
| 153 | 152 | ||
| @@ -177,7 +176,7 @@ QPDFAcroFormDocumentHelper::getFormFields() | @@ -177,7 +176,7 @@ QPDFAcroFormDocumentHelper::getFormFields() | ||
| 177 | { | 176 | { |
| 178 | analyze(); | 177 | analyze(); |
| 179 | std::vector<QPDFFormFieldObjectHelper> result; | 178 | std::vector<QPDFFormFieldObjectHelper> result; |
| 180 | - for (auto const& iter: this->m->field_to_annotations) { | 179 | + for (auto const& iter: m->field_to_annotations) { |
| 181 | result.push_back(this->qpdf.getObject(iter.first)); | 180 | result.push_back(this->qpdf.getObject(iter.first)); |
| 182 | } | 181 | } |
| 183 | return result; | 182 | return result; |
| @@ -188,8 +187,8 @@ QPDFAcroFormDocumentHelper::getFieldsWithQualifiedName(std::string const& name) | @@ -188,8 +187,8 @@ QPDFAcroFormDocumentHelper::getFieldsWithQualifiedName(std::string const& name) | ||
| 188 | { | 187 | { |
| 189 | analyze(); | 188 | analyze(); |
| 190 | // Keep from creating an empty entry | 189 | // Keep from creating an empty entry |
| 191 | - auto iter = this->m->name_to_fields.find(name); | ||
| 192 | - if (iter != this->m->name_to_fields.end()) { | 190 | + auto iter = m->name_to_fields.find(name); |
| 191 | + if (iter != m->name_to_fields.end()) { | ||
| 193 | return iter->second; | 192 | return iter->second; |
| 194 | } | 193 | } |
| 195 | return {}; | 194 | return {}; |
| @@ -201,8 +200,8 @@ QPDFAcroFormDocumentHelper::getAnnotationsForField(QPDFFormFieldObjectHelper h) | @@ -201,8 +200,8 @@ QPDFAcroFormDocumentHelper::getAnnotationsForField(QPDFFormFieldObjectHelper h) | ||
| 201 | analyze(); | 200 | analyze(); |
| 202 | std::vector<QPDFAnnotationObjectHelper> result; | 201 | std::vector<QPDFAnnotationObjectHelper> result; |
| 203 | QPDFObjGen og(h.getObjectHandle().getObjGen()); | 202 | QPDFObjGen og(h.getObjectHandle().getObjGen()); |
| 204 | - if (this->m->field_to_annotations.count(og)) { | ||
| 205 | - result = this->m->field_to_annotations[og]; | 203 | + if (m->field_to_annotations.count(og)) { |
| 204 | + result = m->field_to_annotations[og]; | ||
| 206 | } | 205 | } |
| 207 | return result; | 206 | return result; |
| 208 | } | 207 | } |
| @@ -238,8 +237,8 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) | @@ -238,8 +237,8 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) | ||
| 238 | } | 237 | } |
| 239 | analyze(); | 238 | analyze(); |
| 240 | QPDFObjGen og(oh.getObjGen()); | 239 | QPDFObjGen og(oh.getObjGen()); |
| 241 | - if (this->m->annotation_to_field.count(og)) { | ||
| 242 | - result = this->m->annotation_to_field[og]; | 240 | + if (m->annotation_to_field.count(og)) { |
| 241 | + result = m->annotation_to_field[og]; | ||
| 243 | } | 242 | } |
| 244 | return result; | 243 | return result; |
| 245 | } | 244 | } |
| @@ -247,10 +246,10 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) | @@ -247,10 +246,10 @@ QPDFAcroFormDocumentHelper::getFieldForAnnotation(QPDFAnnotationObjectHelper h) | ||
| 247 | void | 246 | void |
| 248 | QPDFAcroFormDocumentHelper::analyze() | 247 | QPDFAcroFormDocumentHelper::analyze() |
| 249 | { | 248 | { |
| 250 | - if (this->m->cache_valid) { | 249 | + if (m->cache_valid) { |
| 251 | return; | 250 | return; |
| 252 | } | 251 | } |
| 253 | - this->m->cache_valid = true; | 252 | + m->cache_valid = true; |
| 254 | QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); | 253 | QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); |
| 255 | if (!(acroform.isDictionary() && acroform.hasKey("/Fields"))) { | 254 | if (!(acroform.isDictionary() && acroform.hasKey("/Fields"))) { |
| 256 | return; | 255 | return; |
| @@ -286,7 +285,7 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -286,7 +285,7 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 286 | for (auto const& iter: getWidgetAnnotationsForPage(ph)) { | 285 | for (auto const& iter: getWidgetAnnotationsForPage(ph)) { |
| 287 | QPDFObjectHandle annot(iter.getObjectHandle()); | 286 | QPDFObjectHandle annot(iter.getObjectHandle()); |
| 288 | QPDFObjGen og(annot.getObjGen()); | 287 | QPDFObjGen og(annot.getObjGen()); |
| 289 | - if (this->m->annotation_to_field.count(og) == 0) { | 288 | + if (m->annotation_to_field.count(og) == 0) { |
| 290 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget"); | 289 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget"); |
| 291 | // This is not supposed to happen, but it's easy | 290 | // This is not supposed to happen, but it's easy |
| 292 | // enough for us to handle this case. Treat the | 291 | // enough for us to handle this case. Treat the |
| @@ -298,9 +297,8 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -298,9 +297,8 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 298 | annot.warnIfPossible( | 297 | annot.warnIfPossible( |
| 299 | "this widget annotation is not" | 298 | "this widget annotation is not" |
| 300 | " reachable from /AcroForm in the document catalog"); | 299 | " reachable from /AcroForm in the document catalog"); |
| 301 | - this->m->annotation_to_field[og] = | ||
| 302 | - QPDFFormFieldObjectHelper(annot); | ||
| 303 | - this->m->field_to_annotations[og].push_back( | 300 | + m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot); |
| 301 | + m->field_to_annotations[og].push_back( | ||
| 304 | QPDFAnnotationObjectHelper(annot)); | 302 | QPDFAnnotationObjectHelper(annot)); |
| 305 | } | 303 | } |
| 306 | } | 304 | } |
| @@ -376,24 +374,24 @@ QPDFAcroFormDocumentHelper::traverseField( | @@ -376,24 +374,24 @@ QPDFAcroFormDocumentHelper::traverseField( | ||
| 376 | 374 | ||
| 377 | if (is_annotation) { | 375 | if (is_annotation) { |
| 378 | QPDFObjectHandle our_field = (is_field ? field : parent); | 376 | QPDFObjectHandle our_field = (is_field ? field : parent); |
| 379 | - this->m->field_to_annotations[our_field.getObjGen()].push_back( | 377 | + m->field_to_annotations[our_field.getObjGen()].push_back( |
| 380 | QPDFAnnotationObjectHelper(field)); | 378 | QPDFAnnotationObjectHelper(field)); |
| 381 | - this->m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field); | 379 | + m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field); |
| 382 | } | 380 | } |
| 383 | 381 | ||
| 384 | if (is_field && (field.hasKey("/T"))) { | 382 | if (is_field && (field.hasKey("/T"))) { |
| 385 | QPDFFormFieldObjectHelper foh(field); | 383 | QPDFFormFieldObjectHelper foh(field); |
| 386 | auto f_og = field.getObjGen(); | 384 | auto f_og = field.getObjGen(); |
| 387 | std::string name = foh.getFullyQualifiedName(); | 385 | std::string name = foh.getFullyQualifiedName(); |
| 388 | - auto old = this->m->field_to_name.find(f_og); | ||
| 389 | - if (old != this->m->field_to_name.end()) { | 386 | + auto old = m->field_to_name.find(f_og); |
| 387 | + if (old != m->field_to_name.end()) { | ||
| 390 | // We might be updating after a name change, so remove any | 388 | // We might be updating after a name change, so remove any |
| 391 | // old information | 389 | // old information |
| 392 | std::string old_name = old->second; | 390 | std::string old_name = old->second; |
| 393 | - this->m->name_to_fields[old_name].erase(f_og); | 391 | + m->name_to_fields[old_name].erase(f_og); |
| 394 | } | 392 | } |
| 395 | - this->m->field_to_name[f_og] = name; | ||
| 396 | - this->m->name_to_fields[name].insert(f_og); | 393 | + m->field_to_name[f_og] = name; |
| 394 | + m->name_to_fields[name].insert(f_og); | ||
| 397 | } | 395 | } |
| 398 | } | 396 | } |
| 399 | 397 |
libqpdf/QPDFArgParser.cc
| @@ -45,41 +45,41 @@ QPDFArgParser::QPDFArgParser( | @@ -45,41 +45,41 @@ QPDFArgParser::QPDFArgParser( | ||
| 45 | void | 45 | void |
| 46 | QPDFArgParser::selectMainOptionTable() | 46 | QPDFArgParser::selectMainOptionTable() |
| 47 | { | 47 | { |
| 48 | - this->m->option_table = &this->m->main_option_table; | ||
| 49 | - this->m->option_table_name = "main"; | 48 | + m->option_table = &m->main_option_table; |
| 49 | + m->option_table_name = "main"; | ||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | void | 52 | void |
| 53 | QPDFArgParser::selectHelpOptionTable() | 53 | QPDFArgParser::selectHelpOptionTable() |
| 54 | { | 54 | { |
| 55 | - this->m->option_table = &this->m->help_option_table; | ||
| 56 | - this->m->option_table_name = "help"; | 55 | + m->option_table = &m->help_option_table; |
| 56 | + m->option_table_name = "help"; | ||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | void | 59 | void |
| 60 | QPDFArgParser::selectOptionTable(std::string const& name) | 60 | QPDFArgParser::selectOptionTable(std::string const& name) |
| 61 | { | 61 | { |
| 62 | - auto t = this->m->option_tables.find(name); | ||
| 63 | - if (t == this->m->option_tables.end()) { | 62 | + auto t = m->option_tables.find(name); |
| 63 | + if (t == m->option_tables.end()) { | ||
| 64 | QTC::TC("libtests", "QPDFArgParser select unregistered table"); | 64 | QTC::TC("libtests", "QPDFArgParser select unregistered table"); |
| 65 | throw std::logic_error( | 65 | throw std::logic_error( |
| 66 | "QPDFArgParser: selecting unregistered option table " + name); | 66 | "QPDFArgParser: selecting unregistered option table " + name); |
| 67 | } | 67 | } |
| 68 | - this->m->option_table = &(t->second); | ||
| 69 | - this->m->option_table_name = name; | 68 | + m->option_table = &(t->second); |
| 69 | + m->option_table_name = name; | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | void | 72 | void |
| 73 | QPDFArgParser::registerOptionTable( | 73 | QPDFArgParser::registerOptionTable( |
| 74 | std::string const& name, bare_arg_handler_t end_handler) | 74 | std::string const& name, bare_arg_handler_t end_handler) |
| 75 | { | 75 | { |
| 76 | - if (0 != this->m->option_tables.count(name)) { | 76 | + if (0 != m->option_tables.count(name)) { |
| 77 | QTC::TC("libtests", "QPDFArgParser register registered table"); | 77 | QTC::TC("libtests", "QPDFArgParser register registered table"); |
| 78 | throw std::logic_error( | 78 | throw std::logic_error( |
| 79 | "QPDFArgParser: registering already registered option table " + | 79 | "QPDFArgParser: registering already registered option table " + |
| 80 | name); | 80 | name); |
| 81 | } | 81 | } |
| 82 | - this->m->option_tables[name]; | 82 | + m->option_tables[name]; |
| 83 | selectOptionTable(name); | 83 | selectOptionTable(name); |
| 84 | addBare("--", end_handler); | 84 | addBare("--", end_handler); |
| 85 | } | 85 | } |
| @@ -87,13 +87,13 @@ QPDFArgParser::registerOptionTable( | @@ -87,13 +87,13 @@ QPDFArgParser::registerOptionTable( | ||
| 87 | QPDFArgParser::OptionEntry& | 87 | QPDFArgParser::OptionEntry& |
| 88 | QPDFArgParser::registerArg(std::string const& arg) | 88 | QPDFArgParser::registerArg(std::string const& arg) |
| 89 | { | 89 | { |
| 90 | - if (0 != this->m->option_table->count(arg)) { | 90 | + if (0 != m->option_table->count(arg)) { |
| 91 | QTC::TC("libtests", "QPDFArgParser duplicate handler"); | 91 | QTC::TC("libtests", "QPDFArgParser duplicate handler"); |
| 92 | throw std::logic_error( | 92 | throw std::logic_error( |
| 93 | "QPDFArgParser: adding a duplicate handler for option " + arg + | 93 | "QPDFArgParser: adding a duplicate handler for option " + arg + |
| 94 | - " in " + this->m->option_table_name + " option table"); | 94 | + " in " + m->option_table_name + " option table"); |
| 95 | } | 95 | } |
| 96 | - return ((*this->m->option_table)[arg]); | 96 | + return ((*m->option_table)[arg]); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | void | 99 | void |
| @@ -151,8 +151,8 @@ void | @@ -151,8 +151,8 @@ void | ||
| 151 | QPDFArgParser::addInvalidChoiceHandler( | 151 | QPDFArgParser::addInvalidChoiceHandler( |
| 152 | std::string const& arg, param_arg_handler_t handler) | 152 | std::string const& arg, param_arg_handler_t handler) |
| 153 | { | 153 | { |
| 154 | - auto i = this->m->option_table->find(arg); | ||
| 155 | - if (i == this->m->option_table->end()) { | 154 | + auto i = m->option_table->find(arg); |
| 155 | + if (i == m->option_table->end()) { | ||
| 156 | QTC::TC("libtests", "QPDFArgParser invalid choice handler to unknown"); | 156 | QTC::TC("libtests", "QPDFArgParser invalid choice handler to unknown"); |
| 157 | throw std::logic_error( | 157 | throw std::logic_error( |
| 158 | "QPDFArgParser: attempt to add invalid choice handler" | 158 | "QPDFArgParser: attempt to add invalid choice handler" |
| @@ -165,42 +165,42 @@ QPDFArgParser::addInvalidChoiceHandler( | @@ -165,42 +165,42 @@ QPDFArgParser::addInvalidChoiceHandler( | ||
| 165 | void | 165 | void |
| 166 | QPDFArgParser::addFinalCheck(bare_arg_handler_t handler) | 166 | QPDFArgParser::addFinalCheck(bare_arg_handler_t handler) |
| 167 | { | 167 | { |
| 168 | - this->m->final_check_handler = handler; | 168 | + m->final_check_handler = handler; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | bool | 171 | bool |
| 172 | QPDFArgParser::isCompleting() const | 172 | QPDFArgParser::isCompleting() const |
| 173 | { | 173 | { |
| 174 | - return this->m->bash_completion; | 174 | + return m->bash_completion; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | int | 177 | int |
| 178 | QPDFArgParser::argsLeft() const | 178 | QPDFArgParser::argsLeft() const |
| 179 | { | 179 | { |
| 180 | - return this->m->argc - this->m->cur_arg - 1; | 180 | + return m->argc - m->cur_arg - 1; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | void | 183 | void |
| 184 | QPDFArgParser::insertCompletion(std::string const& arg) | 184 | QPDFArgParser::insertCompletion(std::string const& arg) |
| 185 | { | 185 | { |
| 186 | - this->m->completions.insert(arg); | 186 | + m->completions.insert(arg); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | void | 189 | void |
| 190 | QPDFArgParser::completionCommon(bool zsh) | 190 | QPDFArgParser::completionCommon(bool zsh) |
| 191 | { | 191 | { |
| 192 | - std::string progname = this->m->argv[0]; | 192 | + std::string progname = m->argv[0]; |
| 193 | std::string executable; | 193 | std::string executable; |
| 194 | std::string appdir; | 194 | std::string appdir; |
| 195 | std::string appimage; | 195 | std::string appimage; |
| 196 | - if (QUtil::get_env(this->m->progname_env.c_str(), &executable)) { | 196 | + if (QUtil::get_env(m->progname_env.c_str(), &executable)) { |
| 197 | progname = executable; | 197 | progname = executable; |
| 198 | } else if ( | 198 | } else if ( |
| 199 | QUtil::get_env("APPDIR", &appdir) && | 199 | QUtil::get_env("APPDIR", &appdir) && |
| 200 | QUtil::get_env("APPIMAGE", &appimage)) { | 200 | QUtil::get_env("APPIMAGE", &appimage)) { |
| 201 | // Detect if we're in an AppImage and adjust | 201 | // Detect if we're in an AppImage and adjust |
| 202 | - if ((appdir.length() < strlen(this->m->argv[0])) && | ||
| 203 | - (strncmp(appdir.c_str(), this->m->argv[0], appdir.length()) == 0)) { | 202 | + if ((appdir.length() < strlen(m->argv[0])) && |
| 203 | + (strncmp(appdir.c_str(), m->argv[0], appdir.length()) == 0)) { | ||
| 204 | progname = appimage; | 204 | progname = appimage; |
| 205 | } | 205 | } |
| 206 | } | 206 | } |
| @@ -211,12 +211,12 @@ QPDFArgParser::completionCommon(bool zsh) | @@ -211,12 +211,12 @@ QPDFArgParser::completionCommon(bool zsh) | ||
| 211 | if (!zsh) { | 211 | if (!zsh) { |
| 212 | std::cout << " -o nospace"; | 212 | std::cout << " -o nospace"; |
| 213 | } | 213 | } |
| 214 | - std::cout << " -C " << progname << " " << this->m->whoami << std::endl; | 214 | + std::cout << " -C " << progname << " " << m->whoami << std::endl; |
| 215 | // Put output before error so calling from zsh works properly | 215 | // Put output before error so calling from zsh works properly |
| 216 | std::string path = progname; | 216 | std::string path = progname; |
| 217 | size_t slash = path.find('/'); | 217 | size_t slash = path.find('/'); |
| 218 | if ((slash != 0) && (slash != std::string::npos)) { | 218 | if ((slash != 0) && (slash != std::string::npos)) { |
| 219 | - std::cerr << "WARNING: " << this->m->whoami << " completion enabled" | 219 | + std::cerr << "WARNING: " << m->whoami << " completion enabled" |
| 220 | << " using relative path to executable" << std::endl; | 220 | << " using relative path to executable" << std::endl; |
| 221 | } | 221 | } |
| 222 | } | 222 | } |
| @@ -252,11 +252,11 @@ QPDFArgParser::handleArgFileArguments() | @@ -252,11 +252,11 @@ QPDFArgParser::handleArgFileArguments() | ||
| 252 | // Support reading arguments from files. Create a new argv. Ensure | 252 | // Support reading arguments from files. Create a new argv. Ensure |
| 253 | // that argv itself as well as all its contents are automatically | 253 | // that argv itself as well as all its contents are automatically |
| 254 | // deleted by using shared pointers to back the pointers in argv. | 254 | // deleted by using shared pointers to back the pointers in argv. |
| 255 | - this->m->new_argv.push_back(QUtil::make_shared_cstr(this->m->argv[0])); | ||
| 256 | - for (int i = 1; i < this->m->argc; ++i) { | 255 | + m->new_argv.push_back(QUtil::make_shared_cstr(m->argv[0])); |
| 256 | + for (int i = 1; i < m->argc; ++i) { | ||
| 257 | char const* argfile = nullptr; | 257 | char const* argfile = nullptr; |
| 258 | - if ((strlen(this->m->argv[i]) > 1) && (this->m->argv[i][0] == '@')) { | ||
| 259 | - argfile = 1 + this->m->argv[i]; | 258 | + if ((strlen(m->argv[i]) > 1) && (m->argv[i][0] == '@')) { |
| 259 | + argfile = 1 + m->argv[i]; | ||
| 260 | if (strcmp(argfile, "-") != 0) { | 260 | if (strcmp(argfile, "-") != 0) { |
| 261 | if (!QUtil::file_can_be_opened(argfile)) { | 261 | if (!QUtil::file_can_be_opened(argfile)) { |
| 262 | // The file's not there; treating as regular option | 262 | // The file's not there; treating as regular option |
| @@ -265,20 +265,18 @@ QPDFArgParser::handleArgFileArguments() | @@ -265,20 +265,18 @@ QPDFArgParser::handleArgFileArguments() | ||
| 265 | } | 265 | } |
| 266 | } | 266 | } |
| 267 | if (argfile) { | 267 | if (argfile) { |
| 268 | - readArgsFromFile(1 + this->m->argv[i]); | 268 | + readArgsFromFile(1 + m->argv[i]); |
| 269 | } else { | 269 | } else { |
| 270 | - this->m->new_argv.push_back( | ||
| 271 | - QUtil::make_shared_cstr(this->m->argv[i])); | 270 | + m->new_argv.push_back(QUtil::make_shared_cstr(m->argv[i])); |
| 272 | } | 271 | } |
| 273 | } | 272 | } |
| 274 | - this->m->argv_ph = | ||
| 275 | - QUtil::make_shared_array<char const*>(1 + this->m->new_argv.size()); | ||
| 276 | - for (size_t i = 0; i < this->m->new_argv.size(); ++i) { | ||
| 277 | - this->m->argv_ph.get()[i] = this->m->new_argv.at(i).get(); | 273 | + m->argv_ph = QUtil::make_shared_array<char const*>(1 + m->new_argv.size()); |
| 274 | + for (size_t i = 0; i < m->new_argv.size(); ++i) { | ||
| 275 | + m->argv_ph.get()[i] = m->new_argv.at(i).get(); | ||
| 278 | } | 276 | } |
| 279 | - this->m->argc = QIntC::to_int(this->m->new_argv.size()); | ||
| 280 | - this->m->argv_ph.get()[this->m->argc] = nullptr; | ||
| 281 | - this->m->argv = this->m->argv_ph.get(); | 277 | + m->argc = QIntC::to_int(m->new_argv.size()); |
| 278 | + m->argv_ph.get()[m->argc] = nullptr; | ||
| 279 | + m->argv = m->argv_ph.get(); | ||
| 282 | } | 280 | } |
| 283 | 281 | ||
| 284 | void | 282 | void |
| @@ -288,14 +286,14 @@ QPDFArgParser::handleBashArguments() | @@ -288,14 +286,14 @@ QPDFArgParser::handleBashArguments() | ||
| 288 | // doesn't do everything the shell does (e.g. $(...), variable | 286 | // doesn't do everything the shell does (e.g. $(...), variable |
| 289 | // expansion, arithmetic, globs, etc.), but it should be good | 287 | // expansion, arithmetic, globs, etc.), but it should be good |
| 290 | // enough for purposes of handling completion. As we build up the | 288 | // enough for purposes of handling completion. As we build up the |
| 291 | - // new argv, we can't use this->m->new_argv because this code has to | 289 | + // new argv, we can't use m->new_argv because this code has to |
| 292 | // interoperate with @file arguments, so memory for both ways of | 290 | // interoperate with @file arguments, so memory for both ways of |
| 293 | // fabricating argv has to be protected. | 291 | // fabricating argv has to be protected. |
| 294 | 292 | ||
| 295 | bool last_was_backslash = false; | 293 | bool last_was_backslash = false; |
| 296 | enum { st_top, st_squote, st_dquote } state = st_top; | 294 | enum { st_top, st_squote, st_dquote } state = st_top; |
| 297 | std::string arg; | 295 | std::string arg; |
| 298 | - for (char ch: this->m->bash_line) { | 296 | + for (char ch: m->bash_line) { |
| 299 | if (last_was_backslash) { | 297 | if (last_was_backslash) { |
| 300 | arg.append(1, ch); | 298 | arg.append(1, ch); |
| 301 | last_was_backslash = false; | 299 | last_was_backslash = false; |
| @@ -307,8 +305,7 @@ QPDFArgParser::handleBashArguments() | @@ -307,8 +305,7 @@ QPDFArgParser::handleBashArguments() | ||
| 307 | case st_top: | 305 | case st_top: |
| 308 | if (QUtil::is_space(ch)) { | 306 | if (QUtil::is_space(ch)) { |
| 309 | if (!arg.empty()) { | 307 | if (!arg.empty()) { |
| 310 | - this->m->bash_argv.push_back( | ||
| 311 | - QUtil::make_shared_cstr(arg)); | 308 | + m->bash_argv.push_back(QUtil::make_shared_cstr(arg)); |
| 312 | arg.clear(); | 309 | arg.clear(); |
| 313 | } | 310 | } |
| 314 | } else if (ch == '"') { | 311 | } else if (ch == '"') { |
| @@ -341,27 +338,27 @@ QPDFArgParser::handleBashArguments() | @@ -341,27 +338,27 @@ QPDFArgParser::handleBashArguments() | ||
| 341 | } | 338 | } |
| 342 | } | 339 | } |
| 343 | } | 340 | } |
| 344 | - if (this->m->bash_argv.empty()) { | 341 | + if (m->bash_argv.empty()) { |
| 345 | // This can't happen if properly invoked by bash, but ensure | 342 | // This can't happen if properly invoked by bash, but ensure |
| 346 | // we have a valid argv[0] regardless. | 343 | // we have a valid argv[0] regardless. |
| 347 | - this->m->bash_argv.push_back(QUtil::make_shared_cstr(this->m->argv[0])); | 344 | + m->bash_argv.push_back(QUtil::make_shared_cstr(m->argv[0])); |
| 348 | } | 345 | } |
| 349 | // Explicitly discard any non-space-terminated word. The "current | 346 | // Explicitly discard any non-space-terminated word. The "current |
| 350 | // word" is handled specially. | 347 | // word" is handled specially. |
| 351 | - this->m->bash_argv_ph = | ||
| 352 | - QUtil::make_shared_array<char const*>(1 + this->m->bash_argv.size()); | ||
| 353 | - for (size_t i = 0; i < this->m->bash_argv.size(); ++i) { | ||
| 354 | - this->m->bash_argv_ph.get()[i] = this->m->bash_argv.at(i).get(); | 348 | + m->bash_argv_ph = |
| 349 | + QUtil::make_shared_array<char const*>(1 + m->bash_argv.size()); | ||
| 350 | + for (size_t i = 0; i < m->bash_argv.size(); ++i) { | ||
| 351 | + m->bash_argv_ph.get()[i] = m->bash_argv.at(i).get(); | ||
| 355 | } | 352 | } |
| 356 | - this->m->argc = QIntC::to_int(this->m->bash_argv.size()); | ||
| 357 | - this->m->bash_argv_ph.get()[this->m->argc] = nullptr; | ||
| 358 | - this->m->argv = this->m->bash_argv_ph.get(); | 353 | + m->argc = QIntC::to_int(m->bash_argv.size()); |
| 354 | + m->bash_argv_ph.get()[m->argc] = nullptr; | ||
| 355 | + m->argv = m->bash_argv_ph.get(); | ||
| 359 | } | 356 | } |
| 360 | 357 | ||
| 361 | void | 358 | void |
| 362 | QPDFArgParser::usage(std::string const& message) | 359 | QPDFArgParser::usage(std::string const& message) |
| 363 | { | 360 | { |
| 364 | - if (this->m->bash_completion) { | 361 | + if (m->bash_completion) { |
| 365 | // This will cause bash to fall back to regular file completion. | 362 | // This will cause bash to fall back to regular file completion. |
| 366 | exit(0); | 363 | exit(0); |
| 367 | } | 364 | } |
| @@ -380,7 +377,7 @@ QPDFArgParser::readArgsFromFile(std::string const& filename) | @@ -380,7 +377,7 @@ QPDFArgParser::readArgsFromFile(std::string const& filename) | ||
| 380 | lines = QUtil::read_lines_from_file(filename.c_str()); | 377 | lines = QUtil::read_lines_from_file(filename.c_str()); |
| 381 | } | 378 | } |
| 382 | for (auto const& line: lines) { | 379 | for (auto const& line: lines) { |
| 383 | - this->m->new_argv.push_back(QUtil::make_shared_cstr(line)); | 380 | + m->new_argv.push_back(QUtil::make_shared_cstr(line)); |
| 384 | } | 381 | } |
| 385 | } | 382 | } |
| 386 | 383 | ||
| @@ -395,17 +392,17 @@ QPDFArgParser::checkCompletion() | @@ -395,17 +392,17 @@ QPDFArgParser::checkCompletion() | ||
| 395 | // which bash doesn't set COMP_LINE. Therefore, enter this logic | 392 | // which bash doesn't set COMP_LINE. Therefore, enter this logic |
| 396 | // if either COMP_LINE or COMP_POINT are set. They will both be | 393 | // if either COMP_LINE or COMP_POINT are set. They will both be |
| 397 | // set together under ordinary circumstances. | 394 | // set together under ordinary circumstances. |
| 398 | - bool got_line = QUtil::get_env("COMP_LINE", &this->m->bash_line); | 395 | + bool got_line = QUtil::get_env("COMP_LINE", &m->bash_line); |
| 399 | bool got_point = QUtil::get_env("COMP_POINT", &bash_point_env); | 396 | bool got_point = QUtil::get_env("COMP_POINT", &bash_point_env); |
| 400 | if (got_line || got_point) { | 397 | if (got_line || got_point) { |
| 401 | size_t p = QUtil::string_to_uint(bash_point_env.c_str()); | 398 | size_t p = QUtil::string_to_uint(bash_point_env.c_str()); |
| 402 | - if (p < this->m->bash_line.length()) { | 399 | + if (p < m->bash_line.length()) { |
| 403 | // Truncate the line. We ignore everything at or after the | 400 | // Truncate the line. We ignore everything at or after the |
| 404 | // cursor for completion purposes. | 401 | // cursor for completion purposes. |
| 405 | - this->m->bash_line = this->m->bash_line.substr(0, p); | 402 | + m->bash_line = m->bash_line.substr(0, p); |
| 406 | } | 403 | } |
| 407 | - if (p > this->m->bash_line.length()) { | ||
| 408 | - p = this->m->bash_line.length(); | 404 | + if (p > m->bash_line.length()) { |
| 405 | + p = m->bash_line.length(); | ||
| 409 | } | 406 | } |
| 410 | // Set bash_cur and bash_prev based on bash_line rather than | 407 | // Set bash_cur and bash_prev based on bash_line rather than |
| 411 | // relying on argv. This enables us to use bashcompinit to get | 408 | // relying on argv. This enables us to use bashcompinit to get |
| @@ -419,46 +416,44 @@ QPDFArgParser::checkCompletion() | @@ -419,46 +416,44 @@ QPDFArgParser::checkCompletion() | ||
| 419 | char sep(0); | 416 | char sep(0); |
| 420 | while (p > 0) { | 417 | while (p > 0) { |
| 421 | --p; | 418 | --p; |
| 422 | - char ch = this->m->bash_line.at(p); | 419 | + char ch = m->bash_line.at(p); |
| 423 | if ((ch == ' ') || (ch == '=') || (ch == ':')) { | 420 | if ((ch == ' ') || (ch == '=') || (ch == ':')) { |
| 424 | sep = ch; | 421 | sep = ch; |
| 425 | break; | 422 | break; |
| 426 | } | 423 | } |
| 427 | } | 424 | } |
| 428 | - if (1 + p <= this->m->bash_line.length()) { | ||
| 429 | - this->m->bash_cur = | ||
| 430 | - this->m->bash_line.substr(1 + p, std::string::npos); | 425 | + if (1 + p <= m->bash_line.length()) { |
| 426 | + m->bash_cur = m->bash_line.substr(1 + p, std::string::npos); | ||
| 431 | } | 427 | } |
| 432 | if ((sep == ':') || (sep == '=')) { | 428 | if ((sep == ':') || (sep == '=')) { |
| 433 | // Bash sets prev to the non-space separator if any. | 429 | // Bash sets prev to the non-space separator if any. |
| 434 | // Actually, if there are multiple separators in a row, | 430 | // Actually, if there are multiple separators in a row, |
| 435 | // they are all included in prev, but that detail is not | 431 | // they are all included in prev, but that detail is not |
| 436 | // important to us and not worth coding. | 432 | // important to us and not worth coding. |
| 437 | - this->m->bash_prev = this->m->bash_line.substr(p, 1); | 433 | + m->bash_prev = m->bash_line.substr(p, 1); |
| 438 | } else { | 434 | } else { |
| 439 | // Go back to the last separator and set prev based on | 435 | // Go back to the last separator and set prev based on |
| 440 | // that. | 436 | // that. |
| 441 | size_t p1 = p; | 437 | size_t p1 = p; |
| 442 | while (p1 > 0) { | 438 | while (p1 > 0) { |
| 443 | --p1; | 439 | --p1; |
| 444 | - char ch = this->m->bash_line.at(p1); | 440 | + char ch = m->bash_line.at(p1); |
| 445 | if ((ch == ' ') || (ch == ':') || (ch == '=')) { | 441 | if ((ch == ' ') || (ch == ':') || (ch == '=')) { |
| 446 | - this->m->bash_prev = | ||
| 447 | - this->m->bash_line.substr(p1 + 1, p - p1 - 1); | 442 | + m->bash_prev = m->bash_line.substr(p1 + 1, p - p1 - 1); |
| 448 | break; | 443 | break; |
| 449 | } | 444 | } |
| 450 | } | 445 | } |
| 451 | } | 446 | } |
| 452 | - if (this->m->bash_prev.empty()) { | ||
| 453 | - this->m->bash_prev = this->m->bash_line.substr(0, p); | 447 | + if (m->bash_prev.empty()) { |
| 448 | + m->bash_prev = m->bash_line.substr(0, p); | ||
| 454 | } | 449 | } |
| 455 | - if (this->m->argc == 1) { | 450 | + if (m->argc == 1) { |
| 456 | // This is probably zsh using bashcompinit. There are a | 451 | // This is probably zsh using bashcompinit. There are a |
| 457 | // few differences in the expected output. | 452 | // few differences in the expected output. |
| 458 | - this->m->zsh_completion = true; | 453 | + m->zsh_completion = true; |
| 459 | } | 454 | } |
| 460 | handleBashArguments(); | 455 | handleBashArguments(); |
| 461 | - this->m->bash_completion = true; | 456 | + m->bash_completion = true; |
| 462 | } | 457 | } |
| 463 | } | 458 | } |
| 464 | 459 | ||
| @@ -468,12 +463,11 @@ QPDFArgParser::parseArgs() | @@ -468,12 +463,11 @@ QPDFArgParser::parseArgs() | ||
| 468 | selectMainOptionTable(); | 463 | selectMainOptionTable(); |
| 469 | checkCompletion(); | 464 | checkCompletion(); |
| 470 | handleArgFileArguments(); | 465 | handleArgFileArguments(); |
| 471 | - for (this->m->cur_arg = 1; this->m->cur_arg < this->m->argc; | ||
| 472 | - ++this->m->cur_arg) { | 466 | + for (m->cur_arg = 1; m->cur_arg < m->argc; ++m->cur_arg) { |
| 473 | bool help_option = false; | 467 | bool help_option = false; |
| 474 | bool end_option = false; | 468 | bool end_option = false; |
| 475 | - auto oep = this->m->option_table->end(); | ||
| 476 | - char const* arg = this->m->argv[this->m->cur_arg]; | 469 | + auto oep = m->option_table->end(); |
| 470 | + char const* arg = m->argv[m->cur_arg]; | ||
| 477 | std::string parameter; | 471 | std::string parameter; |
| 478 | bool have_parameter = false; | 472 | bool have_parameter = false; |
| 479 | std::string o_arg(arg); | 473 | std::string o_arg(arg); |
| @@ -481,9 +475,9 @@ QPDFArgParser::parseArgs() | @@ -481,9 +475,9 @@ QPDFArgParser::parseArgs() | ||
| 481 | if (strcmp(arg, "--") == 0) { | 475 | if (strcmp(arg, "--") == 0) { |
| 482 | // Special case for -- option, which is used to break out | 476 | // Special case for -- option, which is used to break out |
| 483 | // of subparsers. | 477 | // of subparsers. |
| 484 | - oep = this->m->option_table->find("--"); | 478 | + oep = m->option_table->find("--"); |
| 485 | end_option = true; | 479 | end_option = true; |
| 486 | - if (oep == this->m->option_table->end()) { | 480 | + if (oep == m->option_table->end()) { |
| 487 | // This is registered automatically, so this can't happen. | 481 | // This is registered automatically, so this can't happen. |
| 488 | throw std::logic_error( | 482 | throw std::logic_error( |
| 489 | "QPDFArgParser: -- handler not registered"); | 483 | "QPDFArgParser: -- handler not registered"); |
| @@ -513,32 +507,31 @@ QPDFArgParser::parseArgs() | @@ -513,32 +507,31 @@ QPDFArgParser::parseArgs() | ||
| 513 | arg_s = arg_s.substr(0, equal_pos); | 507 | arg_s = arg_s.substr(0, equal_pos); |
| 514 | } | 508 | } |
| 515 | 509 | ||
| 516 | - if ((!this->m->bash_completion) && (this->m->argc == 2) && | ||
| 517 | - (this->m->cur_arg == 1) && | ||
| 518 | - this->m->help_option_table.count(arg_s)) { | 510 | + if ((!m->bash_completion) && (m->argc == 2) && (m->cur_arg == 1) && |
| 511 | + m->help_option_table.count(arg_s)) { | ||
| 519 | // Handle help option, which is only valid as the sole | 512 | // Handle help option, which is only valid as the sole |
| 520 | // option. | 513 | // option. |
| 521 | QTC::TC("libtests", "QPDFArgParser help option"); | 514 | QTC::TC("libtests", "QPDFArgParser help option"); |
| 522 | - oep = this->m->help_option_table.find(arg_s); | 515 | + oep = m->help_option_table.find(arg_s); |
| 523 | help_option = true; | 516 | help_option = true; |
| 524 | } | 517 | } |
| 525 | 518 | ||
| 526 | if (!(help_option || arg_s.empty() || (arg_s.at(0) == '-'))) { | 519 | if (!(help_option || arg_s.empty() || (arg_s.at(0) == '-'))) { |
| 527 | - oep = this->m->option_table->find(arg_s); | 520 | + oep = m->option_table->find(arg_s); |
| 528 | } | 521 | } |
| 529 | } else { | 522 | } else { |
| 530 | // The empty string maps to the positional argument | 523 | // The empty string maps to the positional argument |
| 531 | // handler. | 524 | // handler. |
| 532 | QTC::TC("libtests", "QPDFArgParser positional"); | 525 | QTC::TC("libtests", "QPDFArgParser positional"); |
| 533 | - oep = this->m->option_table->find(""); | 526 | + oep = m->option_table->find(""); |
| 534 | parameter = arg; | 527 | parameter = arg; |
| 535 | } | 528 | } |
| 536 | 529 | ||
| 537 | - if (oep == this->m->option_table->end()) { | 530 | + if (oep == m->option_table->end()) { |
| 538 | QTC::TC("libtests", "QPDFArgParser unrecognized"); | 531 | QTC::TC("libtests", "QPDFArgParser unrecognized"); |
| 539 | std::string message = "unrecognized argument " + o_arg; | 532 | std::string message = "unrecognized argument " + o_arg; |
| 540 | - if (this->m->option_table != &this->m->main_option_table) { | ||
| 541 | - message += " (" + this->m->option_table_name + | 533 | + if (m->option_table != &m->main_option_table) { |
| 534 | + message += " (" + m->option_table_name + | ||
| 542 | " options must be terminated with --)"; | 535 | " options must be terminated with --)"; |
| 543 | } | 536 | } |
| 544 | usage(message); | 537 | usage(message); |
| @@ -589,7 +582,7 @@ QPDFArgParser::parseArgs() | @@ -589,7 +582,7 @@ QPDFArgParser::parseArgs() | ||
| 589 | selectMainOptionTable(); | 582 | selectMainOptionTable(); |
| 590 | } | 583 | } |
| 591 | } | 584 | } |
| 592 | - if (this->m->bash_completion) { | 585 | + if (m->bash_completion) { |
| 593 | handleCompletion(); | 586 | handleCompletion(); |
| 594 | } else { | 587 | } else { |
| 595 | doFinalChecks(); | 588 | doFinalChecks(); |
| @@ -599,19 +592,18 @@ QPDFArgParser::parseArgs() | @@ -599,19 +592,18 @@ QPDFArgParser::parseArgs() | ||
| 599 | std::string | 592 | std::string |
| 600 | QPDFArgParser::getProgname() | 593 | QPDFArgParser::getProgname() |
| 601 | { | 594 | { |
| 602 | - return this->m->whoami; | 595 | + return m->whoami; |
| 603 | } | 596 | } |
| 604 | 597 | ||
| 605 | void | 598 | void |
| 606 | QPDFArgParser::doFinalChecks() | 599 | QPDFArgParser::doFinalChecks() |
| 607 | { | 600 | { |
| 608 | - if (this->m->option_table != &(this->m->main_option_table)) { | 601 | + if (m->option_table != &(m->main_option_table)) { |
| 609 | QTC::TC("libtests", "QPDFArgParser missing --"); | 602 | QTC::TC("libtests", "QPDFArgParser missing --"); |
| 610 | - usage( | ||
| 611 | - "missing -- at end of " + this->m->option_table_name + " options"); | 603 | + usage("missing -- at end of " + m->option_table_name + " options"); |
| 612 | } | 604 | } |
| 613 | - if (this->m->final_check_handler != nullptr) { | ||
| 614 | - this->m->final_check_handler(); | 605 | + if (m->final_check_handler != nullptr) { |
| 606 | + m->final_check_handler(); | ||
| 615 | } | 607 | } |
| 616 | } | 608 | } |
| 617 | 609 | ||
| @@ -625,7 +617,7 @@ QPDFArgParser::addChoicesToCompletions( | @@ -625,7 +617,7 @@ QPDFArgParser::addChoicesToCompletions( | ||
| 625 | OptionEntry& oe = option_table[option]; | 617 | OptionEntry& oe = option_table[option]; |
| 626 | for (auto const& choice: oe.choices) { | 618 | for (auto const& choice: oe.choices) { |
| 627 | QTC::TC("libtests", "QPDFArgParser complete choices"); | 619 | QTC::TC("libtests", "QPDFArgParser complete choices"); |
| 628 | - this->m->completions.insert(extra_prefix + choice); | 620 | + m->completions.insert(extra_prefix + choice); |
| 629 | } | 621 | } |
| 630 | } | 622 | } |
| 631 | } | 623 | } |
| @@ -641,15 +633,15 @@ QPDFArgParser::addOptionsToCompletions(option_table_t& option_table) | @@ -641,15 +633,15 @@ QPDFArgParser::addOptionsToCompletions(option_table_t& option_table) | ||
| 641 | OptionEntry& oe = iter.second; | 633 | OptionEntry& oe = iter.second; |
| 642 | std::string base = "--" + arg; | 634 | std::string base = "--" + arg; |
| 643 | if (oe.param_arg_handler) { | 635 | if (oe.param_arg_handler) { |
| 644 | - if (this->m->zsh_completion) { | 636 | + if (m->zsh_completion) { |
| 645 | // zsh doesn't treat = as a word separator, so add all | 637 | // zsh doesn't treat = as a word separator, so add all |
| 646 | // the options so we don't get a space after the =. | 638 | // the options so we don't get a space after the =. |
| 647 | addChoicesToCompletions(option_table, arg, base + "="); | 639 | addChoicesToCompletions(option_table, arg, base + "="); |
| 648 | } | 640 | } |
| 649 | - this->m->completions.insert(base + "="); | 641 | + m->completions.insert(base + "="); |
| 650 | } | 642 | } |
| 651 | if (!oe.parameter_needed) { | 643 | if (!oe.parameter_needed) { |
| 652 | - this->m->completions.insert(base); | 644 | + m->completions.insert(base); |
| 653 | } | 645 | } |
| 654 | } | 646 | } |
| 655 | } | 647 | } |
| @@ -662,8 +654,7 @@ QPDFArgParser::insertCompletions( | @@ -662,8 +654,7 @@ QPDFArgParser::insertCompletions( | ||
| 662 | { | 654 | { |
| 663 | if (!choice_option.empty()) { | 655 | if (!choice_option.empty()) { |
| 664 | addChoicesToCompletions(option_table, choice_option, extra_prefix); | 656 | addChoicesToCompletions(option_table, choice_option, extra_prefix); |
| 665 | - } else if ( | ||
| 666 | - (!this->m->bash_cur.empty()) && (this->m->bash_cur.at(0) == '-')) { | 657 | + } else if ((!m->bash_cur.empty()) && (m->bash_cur.at(0) == '-')) { |
| 667 | addOptionsToCompletions(option_table); | 658 | addOptionsToCompletions(option_table); |
| 668 | } | 659 | } |
| 669 | } | 660 | } |
| @@ -672,26 +663,24 @@ void | @@ -672,26 +663,24 @@ void | ||
| 672 | QPDFArgParser::handleCompletion() | 663 | QPDFArgParser::handleCompletion() |
| 673 | { | 664 | { |
| 674 | std::string extra_prefix; | 665 | std::string extra_prefix; |
| 675 | - if (this->m->completions.empty()) { | 666 | + if (m->completions.empty()) { |
| 676 | // Detect --option=... Bash treats the = as a word separator. | 667 | // Detect --option=... Bash treats the = as a word separator. |
| 677 | std::string choice_option; | 668 | std::string choice_option; |
| 678 | - if (this->m->bash_cur.empty() && (this->m->bash_prev.length() > 2) && | ||
| 679 | - (this->m->bash_prev.at(0) == '-') && | ||
| 680 | - (this->m->bash_prev.at(1) == '-') && | ||
| 681 | - (this->m->bash_line.at(this->m->bash_line.length() - 1) == '=')) { | ||
| 682 | - choice_option = this->m->bash_prev.substr(2, std::string::npos); | 669 | + if (m->bash_cur.empty() && (m->bash_prev.length() > 2) && |
| 670 | + (m->bash_prev.at(0) == '-') && (m->bash_prev.at(1) == '-') && | ||
| 671 | + (m->bash_line.at(m->bash_line.length() - 1) == '=')) { | ||
| 672 | + choice_option = m->bash_prev.substr(2, std::string::npos); | ||
| 683 | } else if ( | 673 | } else if ( |
| 684 | - (this->m->bash_prev == "=") && | ||
| 685 | - (this->m->bash_line.length() > (this->m->bash_cur.length() + 1))) { | 674 | + (m->bash_prev == "=") && |
| 675 | + (m->bash_line.length() > (m->bash_cur.length() + 1))) { | ||
| 686 | // We're sitting at --option=x. Find previous option. | 676 | // We're sitting at --option=x. Find previous option. |
| 687 | - size_t end_mark = | ||
| 688 | - this->m->bash_line.length() - this->m->bash_cur.length() - 1; | ||
| 689 | - char before_cur = this->m->bash_line.at(end_mark); | 677 | + size_t end_mark = m->bash_line.length() - m->bash_cur.length() - 1; |
| 678 | + char before_cur = m->bash_line.at(end_mark); | ||
| 690 | if (before_cur == '=') { | 679 | if (before_cur == '=') { |
| 691 | - size_t space = this->m->bash_line.find_last_of(' ', end_mark); | 680 | + size_t space = m->bash_line.find_last_of(' ', end_mark); |
| 692 | if (space != std::string::npos) { | 681 | if (space != std::string::npos) { |
| 693 | - std::string candidate = this->m->bash_line.substr( | ||
| 694 | - space + 1, end_mark - space - 1); | 682 | + std::string candidate = |
| 683 | + m->bash_line.substr(space + 1, end_mark - space - 1); | ||
| 695 | if ((candidate.length() > 2) && (candidate.at(0) == '-') && | 684 | if ((candidate.length() > 2) && (candidate.at(0) == '-') && |
| 696 | (candidate.at(1) == '-')) { | 685 | (candidate.at(1) == '-')) { |
| 697 | choice_option = candidate.substr(2, std::string::npos); | 686 | choice_option = candidate.substr(2, std::string::npos); |
| @@ -699,19 +688,19 @@ QPDFArgParser::handleCompletion() | @@ -699,19 +688,19 @@ QPDFArgParser::handleCompletion() | ||
| 699 | } | 688 | } |
| 700 | } | 689 | } |
| 701 | } | 690 | } |
| 702 | - if (this->m->zsh_completion && (!choice_option.empty())) { | 691 | + if (m->zsh_completion && (!choice_option.empty())) { |
| 703 | // zsh wants --option=choice rather than just choice | 692 | // zsh wants --option=choice rather than just choice |
| 704 | extra_prefix = "--" + choice_option + "="; | 693 | extra_prefix = "--" + choice_option + "="; |
| 705 | } | 694 | } |
| 706 | - insertCompletions(*this->m->option_table, choice_option, extra_prefix); | ||
| 707 | - if (this->m->argc == 1) { | 695 | + insertCompletions(*m->option_table, choice_option, extra_prefix); |
| 696 | + if (m->argc == 1) { | ||
| 708 | // Help options are valid only by themselves. | 697 | // Help options are valid only by themselves. |
| 709 | insertCompletions( | 698 | insertCompletions( |
| 710 | - this->m->help_option_table, choice_option, extra_prefix); | 699 | + m->help_option_table, choice_option, extra_prefix); |
| 711 | } | 700 | } |
| 712 | } | 701 | } |
| 713 | - std::string prefix = extra_prefix + this->m->bash_cur; | ||
| 714 | - for (auto const& iter: this->m->completions) { | 702 | + std::string prefix = extra_prefix + m->bash_cur; |
| 703 | + for (auto const& iter: m->completions) { | ||
| 715 | if (prefix.empty() || (iter.substr(0, prefix.length()) == prefix)) { | 704 | if (prefix.empty() || (iter.substr(0, prefix.length()) == prefix)) { |
| 716 | std::cout << iter << std::endl; | 705 | std::cout << iter << std::endl; |
| 717 | } | 706 | } |
| @@ -722,7 +711,7 @@ QPDFArgParser::handleCompletion() | @@ -722,7 +711,7 @@ QPDFArgParser::handleCompletion() | ||
| 722 | void | 711 | void |
| 723 | QPDFArgParser::addHelpFooter(std::string const& text) | 712 | QPDFArgParser::addHelpFooter(std::string const& text) |
| 724 | { | 713 | { |
| 725 | - this->m->help_footer = "\n" + text; | 714 | + m->help_footer = "\n" + text; |
| 726 | } | 715 | } |
| 727 | 716 | ||
| 728 | void | 717 | void |
| @@ -741,14 +730,14 @@ QPDFArgParser::addHelpTopic( | @@ -741,14 +730,14 @@ QPDFArgParser::addHelpTopic( | ||
| 741 | throw std::logic_error( | 730 | throw std::logic_error( |
| 742 | "QPDFArgParser: help topics must not start with -"); | 731 | "QPDFArgParser: help topics must not start with -"); |
| 743 | } | 732 | } |
| 744 | - if (this->m->help_topics.count(topic)) { | 733 | + if (m->help_topics.count(topic)) { |
| 745 | QTC::TC("libtests", "QPDFArgParser add existing topic"); | 734 | QTC::TC("libtests", "QPDFArgParser add existing topic"); |
| 746 | throw std::logic_error( | 735 | throw std::logic_error( |
| 747 | "QPDFArgParser: topic " + topic + " has already been added"); | 736 | "QPDFArgParser: topic " + topic + " has already been added"); |
| 748 | } | 737 | } |
| 749 | 738 | ||
| 750 | - this->m->help_topics[topic] = HelpTopic(short_text, long_text); | ||
| 751 | - this->m->help_option_table["help"].choices.insert(topic); | 739 | + m->help_topics[topic] = HelpTopic(short_text, long_text); |
| 740 | + m->help_option_table["help"].choices.insert(topic); | ||
| 752 | } | 741 | } |
| 753 | 742 | ||
| 754 | void | 743 | void |
| @@ -764,35 +753,35 @@ QPDFArgParser::addOptionHelp( | @@ -764,35 +753,35 @@ QPDFArgParser::addOptionHelp( | ||
| 764 | throw std::logic_error( | 753 | throw std::logic_error( |
| 765 | "QPDFArgParser: options for help must start with --"); | 754 | "QPDFArgParser: options for help must start with --"); |
| 766 | } | 755 | } |
| 767 | - if (this->m->option_help.count(option_name)) { | 756 | + if (m->option_help.count(option_name)) { |
| 768 | QTC::TC("libtests", "QPDFArgParser duplicate option help"); | 757 | QTC::TC("libtests", "QPDFArgParser duplicate option help"); |
| 769 | throw std::logic_error( | 758 | throw std::logic_error( |
| 770 | "QPDFArgParser: option " + option_name + " already has help"); | 759 | "QPDFArgParser: option " + option_name + " already has help"); |
| 771 | } | 760 | } |
| 772 | - auto ht = this->m->help_topics.find(topic); | ||
| 773 | - if (ht == this->m->help_topics.end()) { | 761 | + auto ht = m->help_topics.find(topic); |
| 762 | + if (ht == m->help_topics.end()) { | ||
| 774 | QTC::TC("libtests", "QPDFArgParser add to unknown topic"); | 763 | QTC::TC("libtests", "QPDFArgParser add to unknown topic"); |
| 775 | throw std::logic_error( | 764 | throw std::logic_error( |
| 776 | "QPDFArgParser: unable to add option " + option_name + | 765 | "QPDFArgParser: unable to add option " + option_name + |
| 777 | " to unknown help topic " + topic); | 766 | " to unknown help topic " + topic); |
| 778 | } | 767 | } |
| 779 | - this->m->option_help[option_name] = HelpTopic(short_text, long_text); | 768 | + m->option_help[option_name] = HelpTopic(short_text, long_text); |
| 780 | ht->second.options.insert(option_name); | 769 | ht->second.options.insert(option_name); |
| 781 | - this->m->help_option_table["help"].choices.insert(option_name); | 770 | + m->help_option_table["help"].choices.insert(option_name); |
| 782 | } | 771 | } |
| 783 | 772 | ||
| 784 | void | 773 | void |
| 785 | QPDFArgParser::getTopHelp(std::ostringstream& msg) | 774 | QPDFArgParser::getTopHelp(std::ostringstream& msg) |
| 786 | { | 775 | { |
| 787 | - msg << "Run \"" << this->m->whoami << " --help=topic\" for help on a topic." | 776 | + msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." |
| 777 | + << std::endl | ||
| 778 | + << "Run \"" << m->whoami << " --help=--option\" for help on an option." | ||
| 779 | + << std::endl | ||
| 780 | + << "Run \"" << m->whoami << " --help=all\" to see all available help." | ||
| 788 | << std::endl | 781 | << std::endl |
| 789 | - << "Run \"" << this->m->whoami | ||
| 790 | - << " --help=--option\" for help on an option." << std::endl | ||
| 791 | - << "Run \"" << this->m->whoami | ||
| 792 | - << " --help=all\" to see all available help." << std::endl | ||
| 793 | << std::endl | 782 | << std::endl |
| 794 | << "Topics:" << std::endl; | 783 | << "Topics:" << std::endl; |
| 795 | - for (auto const& i: this->m->help_topics) { | 784 | + for (auto const& i: m->help_topics) { |
| 796 | msg << " " << i.first << ": " << i.second.short_text << std::endl; | 785 | msg << " " << i.first << ": " << i.second.short_text << std::endl; |
| 797 | } | 786 | } |
| 798 | } | 787 | } |
| @@ -811,8 +800,8 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) | @@ -811,8 +800,8 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) | ||
| 811 | getTopicHelp(topic, i.second, msg); | 800 | getTopicHelp(topic, i.second, msg); |
| 812 | } | 801 | } |
| 813 | }; | 802 | }; |
| 814 | - show(this->m->help_topics); | ||
| 815 | - show(this->m->option_help); | 803 | + show(m->help_topics); |
| 804 | + show(m->option_help); | ||
| 816 | msg << std::endl << "====" << std::endl; | 805 | msg << std::endl << "====" << std::endl; |
| 817 | } | 806 | } |
| 818 | 807 | ||
| @@ -828,7 +817,7 @@ QPDFArgParser::getTopicHelp( | @@ -828,7 +817,7 @@ QPDFArgParser::getTopicHelp( | ||
| 828 | if (!ht.options.empty()) { | 817 | if (!ht.options.empty()) { |
| 829 | msg << std::endl << "Related options:" << std::endl; | 818 | msg << std::endl << "Related options:" << std::endl; |
| 830 | for (auto const& i: ht.options) { | 819 | for (auto const& i: ht.options) { |
| 831 | - msg << " " << i << ": " << this->m->option_help[i].short_text | 820 | + msg << " " << i << ": " << m->option_help[i].short_text |
| 832 | << std::endl; | 821 | << std::endl; |
| 833 | } | 822 | } |
| 834 | } | 823 | } |
| @@ -843,15 +832,15 @@ QPDFArgParser::getHelp(std::string const& arg) | @@ -843,15 +832,15 @@ QPDFArgParser::getHelp(std::string const& arg) | ||
| 843 | } else { | 832 | } else { |
| 844 | if (arg == "all") { | 833 | if (arg == "all") { |
| 845 | getAllHelp(msg); | 834 | getAllHelp(msg); |
| 846 | - } else if (this->m->option_help.count(arg)) { | ||
| 847 | - getTopicHelp(arg, this->m->option_help[arg], msg); | ||
| 848 | - } else if (this->m->help_topics.count(arg)) { | ||
| 849 | - getTopicHelp(arg, this->m->help_topics[arg], msg); | 835 | + } else if (m->option_help.count(arg)) { |
| 836 | + getTopicHelp(arg, m->option_help[arg], msg); | ||
| 837 | + } else if (m->help_topics.count(arg)) { | ||
| 838 | + getTopicHelp(arg, m->help_topics[arg], msg); | ||
| 850 | } else { | 839 | } else { |
| 851 | // should not be possible | 840 | // should not be possible |
| 852 | getTopHelp(msg); | 841 | getTopHelp(msg); |
| 853 | } | 842 | } |
| 854 | } | 843 | } |
| 855 | - msg << this->m->help_footer; | 844 | + msg << m->help_footer; |
| 856 | return msg.str(); | 845 | return msg.str(); |
| 857 | } | 846 | } |
libqpdf/QPDFCryptoProvider.cc
| @@ -73,32 +73,32 @@ QPDFCryptoProvider::getInstance() | @@ -73,32 +73,32 @@ QPDFCryptoProvider::getInstance() | ||
| 73 | std::shared_ptr<QPDFCryptoImpl> | 73 | std::shared_ptr<QPDFCryptoImpl> |
| 74 | QPDFCryptoProvider::getImpl_internal(std::string const& name) const | 74 | QPDFCryptoProvider::getImpl_internal(std::string const& name) const |
| 75 | { | 75 | { |
| 76 | - auto iter = this->m->providers.find(name); | ||
| 77 | - if (iter == this->m->providers.end()) { | 76 | + auto iter = m->providers.find(name); |
| 77 | + if (iter == m->providers.end()) { | ||
| 78 | throw std::logic_error( | 78 | throw std::logic_error( |
| 79 | "QPDFCryptoProvider requested unknown implementation \"" + name + | 79 | "QPDFCryptoProvider requested unknown implementation \"" + name + |
| 80 | "\""); | 80 | "\""); |
| 81 | } | 81 | } |
| 82 | - return this->m->providers[name](); | 82 | + return m->providers[name](); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | template <typename T> | 85 | template <typename T> |
| 86 | void | 86 | void |
| 87 | QPDFCryptoProvider::registerImpl_internal(std::string const& name) | 87 | QPDFCryptoProvider::registerImpl_internal(std::string const& name) |
| 88 | { | 88 | { |
| 89 | - this->m->providers[name] = std::make_shared<T>; | 89 | + m->providers[name] = std::make_shared<T>; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | void | 92 | void |
| 93 | QPDFCryptoProvider::setDefaultProvider_internal(std::string const& name) | 93 | QPDFCryptoProvider::setDefaultProvider_internal(std::string const& name) |
| 94 | { | 94 | { |
| 95 | - if (!this->m->providers.count(name)) { | 95 | + if (!m->providers.count(name)) { |
| 96 | throw std::logic_error( | 96 | throw std::logic_error( |
| 97 | "QPDFCryptoProvider: request to set default" | 97 | "QPDFCryptoProvider: request to set default" |
| 98 | " provider to unknown implementation \"" + | 98 | " provider to unknown implementation \"" + |
| 99 | name + "\""); | 99 | name + "\""); |
| 100 | } | 100 | } |
| 101 | - this->m->default_provider = name; | 101 | + m->default_provider = name; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | std::set<std::string> | 104 | std::set<std::string> |
libqpdf/QPDFEmbeddedFileDocumentHelper.cc
| @@ -40,9 +40,8 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) : | @@ -40,9 +40,8 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) : | ||
| 40 | if (names.isDictionary()) { | 40 | if (names.isDictionary()) { |
| 41 | auto embedded_files = names.getKey("/EmbeddedFiles"); | 41 | auto embedded_files = names.getKey("/EmbeddedFiles"); |
| 42 | if (embedded_files.isDictionary()) { | 42 | if (embedded_files.isDictionary()) { |
| 43 | - this->m->embedded_files = | ||
| 44 | - std::make_shared<QPDFNameTreeObjectHelper>( | ||
| 45 | - embedded_files, qpdf); | 43 | + m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>( |
| 44 | + embedded_files, qpdf); | ||
| 46 | } | 45 | } |
| 47 | } | 46 | } |
| 48 | } | 47 | } |
| @@ -50,7 +49,7 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) : | @@ -50,7 +49,7 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) : | ||
| 50 | bool | 49 | bool |
| 51 | QPDFEmbeddedFileDocumentHelper::hasEmbeddedFiles() const | 50 | QPDFEmbeddedFileDocumentHelper::hasEmbeddedFiles() const |
| 52 | { | 51 | { |
| 53 | - return (this->m->embedded_files != nullptr); | 52 | + return (m->embedded_files != nullptr); |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | void | 55 | void |
| @@ -69,8 +68,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | @@ -69,8 +68,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | ||
| 69 | if (!embedded_files.isDictionary()) { | 68 | if (!embedded_files.isDictionary()) { |
| 70 | auto nth = QPDFNameTreeObjectHelper::newEmpty(this->qpdf); | 69 | auto nth = QPDFNameTreeObjectHelper::newEmpty(this->qpdf); |
| 71 | names.replaceKey("/EmbeddedFiles", nth.getObjectHandle()); | 70 | names.replaceKey("/EmbeddedFiles", nth.getObjectHandle()); |
| 72 | - this->m->embedded_files = | ||
| 73 | - std::make_shared<QPDFNameTreeObjectHelper>(nth); | 71 | + m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>(nth); |
| 74 | } | 72 | } |
| 75 | } | 73 | } |
| 76 | 74 | ||
| @@ -78,9 +76,9 @@ std::shared_ptr<QPDFFileSpecObjectHelper> | @@ -78,9 +76,9 @@ std::shared_ptr<QPDFFileSpecObjectHelper> | ||
| 78 | QPDFEmbeddedFileDocumentHelper::getEmbeddedFile(std::string const& name) | 76 | QPDFEmbeddedFileDocumentHelper::getEmbeddedFile(std::string const& name) |
| 79 | { | 77 | { |
| 80 | std::shared_ptr<QPDFFileSpecObjectHelper> result; | 78 | std::shared_ptr<QPDFFileSpecObjectHelper> result; |
| 81 | - if (this->m->embedded_files) { | ||
| 82 | - auto i = this->m->embedded_files->find(name); | ||
| 83 | - if (i != this->m->embedded_files->end()) { | 79 | + if (m->embedded_files) { |
| 80 | + auto i = m->embedded_files->find(name); | ||
| 81 | + if (i != m->embedded_files->end()) { | ||
| 84 | result = std::make_shared<QPDFFileSpecObjectHelper>(i->second); | 82 | result = std::make_shared<QPDFFileSpecObjectHelper>(i->second); |
| 85 | } | 83 | } |
| 86 | } | 84 | } |
| @@ -91,8 +89,8 @@ std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> | @@ -91,8 +89,8 @@ std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> | ||
| 91 | QPDFEmbeddedFileDocumentHelper::getEmbeddedFiles() | 89 | QPDFEmbeddedFileDocumentHelper::getEmbeddedFiles() |
| 92 | { | 90 | { |
| 93 | std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> result; | 91 | std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> result; |
| 94 | - if (this->m->embedded_files) { | ||
| 95 | - for (auto const& i: *(this->m->embedded_files)) { | 92 | + if (m->embedded_files) { |
| 93 | + for (auto const& i: *(m->embedded_files)) { | ||
| 96 | result[i.first] = | 94 | result[i.first] = |
| 97 | std::make_shared<QPDFFileSpecObjectHelper>(i.second); | 95 | std::make_shared<QPDFFileSpecObjectHelper>(i.second); |
| 98 | } | 96 | } |
| @@ -105,7 +103,7 @@ QPDFEmbeddedFileDocumentHelper::replaceEmbeddedFile( | @@ -105,7 +103,7 @@ QPDFEmbeddedFileDocumentHelper::replaceEmbeddedFile( | ||
| 105 | std::string const& name, QPDFFileSpecObjectHelper const& fs) | 103 | std::string const& name, QPDFFileSpecObjectHelper const& fs) |
| 106 | { | 104 | { |
| 107 | initEmbeddedFiles(); | 105 | initEmbeddedFiles(); |
| 108 | - this->m->embedded_files->insert(name, fs.getObjectHandle()); | 106 | + m->embedded_files->insert(name, fs.getObjectHandle()); |
| 109 | } | 107 | } |
| 110 | 108 | ||
| 111 | bool | 109 | bool |
| @@ -114,8 +112,8 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const& name) | @@ -114,8 +112,8 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const& name) | ||
| 114 | if (!hasEmbeddedFiles()) { | 112 | if (!hasEmbeddedFiles()) { |
| 115 | return false; | 113 | return false; |
| 116 | } | 114 | } |
| 117 | - auto iter = this->m->embedded_files->find(name); | ||
| 118 | - if (iter == this->m->embedded_files->end()) { | 115 | + auto iter = m->embedded_files->find(name); |
| 116 | + if (iter == m->embedded_files->end()) { | ||
| 119 | return false; | 117 | return false; |
| 120 | } | 118 | } |
| 121 | auto oh = iter->second; | 119 | auto oh = iter->second; |
libqpdf/QPDFJob.cc
| @@ -323,46 +323,46 @@ QPDFJob::usage(std::string const& msg) | @@ -323,46 +323,46 @@ QPDFJob::usage(std::string const& msg) | ||
| 323 | void | 323 | void |
| 324 | QPDFJob::setMessagePrefix(std::string const& message_prefix) | 324 | QPDFJob::setMessagePrefix(std::string const& message_prefix) |
| 325 | { | 325 | { |
| 326 | - this->m->message_prefix = message_prefix; | 326 | + m->message_prefix = message_prefix; |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | std::string | 329 | std::string |
| 330 | QPDFJob::getMessagePrefix() const | 330 | QPDFJob::getMessagePrefix() const |
| 331 | { | 331 | { |
| 332 | - return this->m->message_prefix; | 332 | + return m->message_prefix; |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | std::shared_ptr<QPDFLogger> | 335 | std::shared_ptr<QPDFLogger> |
| 336 | QPDFJob::getLogger() | 336 | QPDFJob::getLogger() |
| 337 | { | 337 | { |
| 338 | - return this->m->log; | 338 | + return m->log; |
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | void | 341 | void |
| 342 | QPDFJob::setLogger(std::shared_ptr<QPDFLogger> l) | 342 | QPDFJob::setLogger(std::shared_ptr<QPDFLogger> l) |
| 343 | { | 343 | { |
| 344 | - this->m->log = l; | 344 | + m->log = l; |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | void | 347 | void |
| 348 | QPDFJob::setOutputStreams(std::ostream* out, std::ostream* err) | 348 | QPDFJob::setOutputStreams(std::ostream* out, std::ostream* err) |
| 349 | { | 349 | { |
| 350 | setLogger(QPDFLogger::create()); | 350 | setLogger(QPDFLogger::create()); |
| 351 | - this->m->log->setOutputStreams(out, err); | 351 | + m->log->setOutputStreams(out, err); |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | void | 354 | void |
| 355 | QPDFJob::registerProgressReporter(std::function<void(int)> handler) | 355 | QPDFJob::registerProgressReporter(std::function<void(int)> handler) |
| 356 | { | 356 | { |
| 357 | - this->m->progress_handler = handler; | 357 | + m->progress_handler = handler; |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | void | 360 | void |
| 361 | QPDFJob::doIfVerbose( | 361 | QPDFJob::doIfVerbose( |
| 362 | std::function<void(Pipeline&, std::string const& prefix)> fn) | 362 | std::function<void(Pipeline&, std::string const& prefix)> fn) |
| 363 | { | 363 | { |
| 364 | - if (this->m->verbose) { | ||
| 365 | - fn(*this->m->log->getInfo(), this->m->message_prefix); | 364 | + if (m->verbose) { |
| 365 | + fn(*m->log->getInfo(), m->message_prefix); | ||
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| 368 | 368 | ||
| @@ -459,12 +459,12 @@ QPDFJob::createQPDF() | @@ -459,12 +459,12 @@ QPDFJob::createQPDF() | ||
| 459 | // Allow certain operations to work when an incorrect | 459 | // Allow certain operations to work when an incorrect |
| 460 | // password is supplied. | 460 | // password is supplied. |
| 461 | if (m->check_is_encrypted || m->check_requires_password) { | 461 | if (m->check_is_encrypted || m->check_requires_password) { |
| 462 | - this->m->encryption_status = | 462 | + m->encryption_status = |
| 463 | qpdf_es_encrypted | qpdf_es_password_incorrect; | 463 | qpdf_es_encrypted | qpdf_es_password_incorrect; |
| 464 | return nullptr; | 464 | return nullptr; |
| 465 | } | 465 | } |
| 466 | if (m->show_encryption && pdf_sp) { | 466 | if (m->show_encryption && pdf_sp) { |
| 467 | - this->m->log->info("Incorrect password supplied\n"); | 467 | + m->log->info("Incorrect password supplied\n"); |
| 468 | showEncryption(*pdf_sp); | 468 | showEncryption(*pdf_sp); |
| 469 | return nullptr; | 469 | return nullptr; |
| 470 | } | 470 | } |
| @@ -473,7 +473,7 @@ QPDFJob::createQPDF() | @@ -473,7 +473,7 @@ QPDFJob::createQPDF() | ||
| 473 | } | 473 | } |
| 474 | QPDF& pdf = *pdf_sp; | 474 | QPDF& pdf = *pdf_sp; |
| 475 | if (pdf.isEncrypted()) { | 475 | if (pdf.isEncrypted()) { |
| 476 | - this->m->encryption_status = qpdf_es_encrypted; | 476 | + m->encryption_status = qpdf_es_encrypted; |
| 477 | } | 477 | } |
| 478 | 478 | ||
| 479 | if (m->check_is_encrypted || m->check_requires_password) { | 479 | if (m->check_is_encrypted || m->check_requires_password) { |
| @@ -482,8 +482,8 @@ QPDFJob::createQPDF() | @@ -482,8 +482,8 @@ QPDFJob::createQPDF() | ||
| 482 | 482 | ||
| 483 | // If we are updating from JSON, this has to be done first before | 483 | // If we are updating from JSON, this has to be done first before |
| 484 | // other options may cause transformations to the input. | 484 | // other options may cause transformations to the input. |
| 485 | - if (!this->m->update_from_json.empty()) { | ||
| 486 | - pdf.updateFromJSON(this->m->update_from_json); | 485 | + if (!m->update_from_json.empty()) { |
| 486 | + pdf.updateFromJSON(m->update_from_json); | ||
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | std::vector<std::unique_ptr<QPDF>> page_heap; | 489 | std::vector<std::unique_ptr<QPDF>> page_heap; |
| @@ -509,17 +509,16 @@ QPDFJob::writeQPDF(QPDF& pdf) | @@ -509,17 +509,16 @@ QPDFJob::writeQPDF(QPDF& pdf) | ||
| 509 | writeOutfile(pdf); | 509 | writeOutfile(pdf); |
| 510 | } | 510 | } |
| 511 | if (!pdf.getWarnings().empty()) { | 511 | if (!pdf.getWarnings().empty()) { |
| 512 | - this->m->warnings = true; | 512 | + m->warnings = true; |
| 513 | } | 513 | } |
| 514 | - if (this->m->warnings && (!this->m->suppress_warnings)) { | 514 | + if (m->warnings && (!m->suppress_warnings)) { |
| 515 | if (createsOutput()) { | 515 | if (createsOutput()) { |
| 516 | - *this->m->log->getWarn() | ||
| 517 | - << this->m->message_prefix | ||
| 518 | - << ": operation succeeded with warnings;" | 516 | + *m->log->getWarn() |
| 517 | + << m->message_prefix << ": operation succeeded with warnings;" | ||
| 519 | << " resulting file may have some problems\n"; | 518 | << " resulting file may have some problems\n"; |
| 520 | } else { | 519 | } else { |
| 521 | - *this->m->log->getWarn() << this->m->message_prefix | ||
| 522 | - << ": operation succeeded with warnings\n"; | 520 | + *m->log->getWarn() |
| 521 | + << m->message_prefix << ": operation succeeded with warnings\n"; | ||
| 523 | } | 522 | } |
| 524 | } | 523 | } |
| 525 | if (m->report_mem_usage) { | 524 | if (m->report_mem_usage) { |
| @@ -527,8 +526,7 @@ QPDFJob::writeQPDF(QPDF& pdf) | @@ -527,8 +526,7 @@ QPDFJob::writeQPDF(QPDF& pdf) | ||
| 527 | // debugging, it's easier if print statements from | 526 | // debugging, it's easier if print statements from |
| 528 | // get_max_memory_usage are not interleaved with the output. | 527 | // get_max_memory_usage are not interleaved with the output. |
| 529 | auto mem_usage = QUtil::get_max_memory_usage(); | 528 | auto mem_usage = QUtil::get_max_memory_usage(); |
| 530 | - *this->m->log->getWarn() | ||
| 531 | - << "qpdf-max-memory-usage " << mem_usage << "\n"; | 529 | + *m->log->getWarn() << "qpdf-max-memory-usage " << mem_usage << "\n"; |
| 532 | } | 530 | } |
| 533 | } | 531 | } |
| 534 | 532 | ||
| @@ -544,7 +542,7 @@ QPDFJob::run() | @@ -544,7 +542,7 @@ QPDFJob::run() | ||
| 544 | bool | 542 | bool |
| 545 | QPDFJob::hasWarnings() const | 543 | QPDFJob::hasWarnings() const |
| 546 | { | 544 | { |
| 547 | - return this->m->warnings; | 545 | + return m->warnings; |
| 548 | } | 546 | } |
| 549 | 547 | ||
| 550 | bool | 548 | bool |
| @@ -556,17 +554,17 @@ QPDFJob::createsOutput() const | @@ -556,17 +554,17 @@ QPDFJob::createsOutput() const | ||
| 556 | int | 554 | int |
| 557 | QPDFJob::getExitCode() const | 555 | QPDFJob::getExitCode() const |
| 558 | { | 556 | { |
| 559 | - if (this->m->check_is_encrypted) { | ||
| 560 | - if (this->m->encryption_status & qpdf_es_encrypted) { | 557 | + if (m->check_is_encrypted) { |
| 558 | + if (m->encryption_status & qpdf_es_encrypted) { | ||
| 561 | QTC::TC("qpdf", "QPDFJob check encrypted encrypted"); | 559 | QTC::TC("qpdf", "QPDFJob check encrypted encrypted"); |
| 562 | return 0; | 560 | return 0; |
| 563 | } else { | 561 | } else { |
| 564 | QTC::TC("qpdf", "QPDFJob check encrypted not encrypted"); | 562 | QTC::TC("qpdf", "QPDFJob check encrypted not encrypted"); |
| 565 | return EXIT_IS_NOT_ENCRYPTED; | 563 | return EXIT_IS_NOT_ENCRYPTED; |
| 566 | } | 564 | } |
| 567 | - } else if (this->m->check_requires_password) { | ||
| 568 | - if (this->m->encryption_status & qpdf_es_encrypted) { | ||
| 569 | - if (this->m->encryption_status & qpdf_es_password_incorrect) { | 565 | + } else if (m->check_requires_password) { |
| 566 | + if (m->encryption_status & qpdf_es_encrypted) { | ||
| 567 | + if (m->encryption_status & qpdf_es_password_incorrect) { | ||
| 570 | QTC::TC("qpdf", "QPDFJob check password password incorrect"); | 568 | QTC::TC("qpdf", "QPDFJob check password password incorrect"); |
| 571 | return 0; | 569 | return 0; |
| 572 | } else { | 570 | } else { |
| @@ -579,7 +577,7 @@ QPDFJob::getExitCode() const | @@ -579,7 +577,7 @@ QPDFJob::getExitCode() const | ||
| 579 | } | 577 | } |
| 580 | } | 578 | } |
| 581 | 579 | ||
| 582 | - if (this->m->warnings && (!this->m->warnings_exit_zero)) { | 580 | + if (m->warnings && (!m->warnings_exit_zero)) { |
| 583 | return EXIT_WARNING; | 581 | return EXIT_WARNING; |
| 584 | } | 582 | } |
| 585 | return 0; | 583 | return 0; |
| @@ -656,7 +654,7 @@ QPDFJob::checkConfiguration() | @@ -656,7 +654,7 @@ QPDFJob::checkConfiguration() | ||
| 656 | save_to_stdout = true; | 654 | save_to_stdout = true; |
| 657 | } | 655 | } |
| 658 | if (save_to_stdout) { | 656 | if (save_to_stdout) { |
| 659 | - this->m->log->saveToStandardOutput(true); | 657 | + m->log->saveToStandardOutput(true); |
| 660 | } | 658 | } |
| 661 | if ((!m->split_pages) && | 659 | if ((!m->split_pages) && |
| 662 | QUtil::same_file(m->infilename.get(), m->outfilename.get())) { | 660 | QUtil::same_file(m->infilename.get(), m->outfilename.get())) { |
| @@ -681,13 +679,13 @@ QPDFJob::checkConfiguration() | @@ -681,13 +679,13 @@ QPDFJob::checkConfiguration() | ||
| 681 | unsigned long | 679 | unsigned long |
| 682 | QPDFJob::getEncryptionStatus() | 680 | QPDFJob::getEncryptionStatus() |
| 683 | { | 681 | { |
| 684 | - return this->m->encryption_status; | 682 | + return m->encryption_status; |
| 685 | } | 683 | } |
| 686 | 684 | ||
| 687 | void | 685 | void |
| 688 | QPDFJob::setQPDFOptions(QPDF& pdf) | 686 | QPDFJob::setQPDFOptions(QPDF& pdf) |
| 689 | { | 687 | { |
| 690 | - pdf.setLogger(this->m->log); | 688 | + pdf.setLogger(m->log); |
| 691 | if (m->ignore_xref_streams) { | 689 | if (m->ignore_xref_streams) { |
| 692 | pdf.setIgnoreXRefStreams(true); | 690 | pdf.setIgnoreXRefStreams(true); |
| 693 | } | 691 | } |
| @@ -743,7 +741,7 @@ QPDFJob::showEncryption(QPDF& pdf) | @@ -743,7 +741,7 @@ QPDFJob::showEncryption(QPDF& pdf) | ||
| 743 | QPDF::encryption_method_e stream_method = QPDF::e_unknown; | 741 | QPDF::encryption_method_e stream_method = QPDF::e_unknown; |
| 744 | QPDF::encryption_method_e string_method = QPDF::e_unknown; | 742 | QPDF::encryption_method_e string_method = QPDF::e_unknown; |
| 745 | QPDF::encryption_method_e file_method = QPDF::e_unknown; | 743 | QPDF::encryption_method_e file_method = QPDF::e_unknown; |
| 746 | - auto& cout = *this->m->log->getInfo(); | 744 | + auto& cout = *m->log->getInfo(); |
| 747 | if (!pdf.isEncrypted(R, P, V, stream_method, string_method, file_method)) { | 745 | if (!pdf.isEncrypted(R, P, V, stream_method, string_method, file_method)) { |
| 748 | cout << "File is not encrypted\n"; | 746 | cout << "File is not encrypted\n"; |
| 749 | } else { | 747 | } else { |
| @@ -796,7 +794,7 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -796,7 +794,7 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 796 | // continue to perform additional checks after finding | 794 | // continue to perform additional checks after finding |
| 797 | // errors. | 795 | // errors. |
| 798 | bool okay = true; | 796 | bool okay = true; |
| 799 | - auto& cout = *this->m->log->getInfo(); | 797 | + auto& cout = *m->log->getInfo(); |
| 800 | cout << "checking " << m->infilename.get() << "\n"; | 798 | cout << "checking " << m->infilename.get() << "\n"; |
| 801 | QPDF::JobSetter::setCheckMode(pdf, true); | 799 | QPDF::JobSetter::setCheckMode(pdf, true); |
| 802 | try { | 800 | try { |
| @@ -832,12 +830,12 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -832,12 +830,12 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 832 | page.parseContents(&discard_contents); | 830 | page.parseContents(&discard_contents); |
| 833 | } catch (QPDFExc& e) { | 831 | } catch (QPDFExc& e) { |
| 834 | okay = false; | 832 | okay = false; |
| 835 | - *this->m->log->getError() | 833 | + *m->log->getError() |
| 836 | << "ERROR: page " << pageno << ": " << e.what() << "\n"; | 834 | << "ERROR: page " << pageno << ": " << e.what() << "\n"; |
| 837 | } | 835 | } |
| 838 | } | 836 | } |
| 839 | } catch (std::exception& e) { | 837 | } catch (std::exception& e) { |
| 840 | - *this->m->log->getError() << "ERROR: " << e.what() << "\n"; | 838 | + *m->log->getError() << "ERROR: " << e.what() << "\n"; |
| 841 | okay = false; | 839 | okay = false; |
| 842 | } | 840 | } |
| 843 | if (!okay) { | 841 | if (!okay) { |
| @@ -845,11 +843,11 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -845,11 +843,11 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 845 | } | 843 | } |
| 846 | 844 | ||
| 847 | if (!pdf.getWarnings().empty()) { | 845 | if (!pdf.getWarnings().empty()) { |
| 848 | - this->m->warnings = true; | 846 | + m->warnings = true; |
| 849 | } else { | 847 | } else { |
| 850 | - *this->m->log->getInfo() << "No syntax or stream encoding errors" | ||
| 851 | - << " found; the file may still contain\n" | ||
| 852 | - << "errors that qpdf cannot detect\n"; | 848 | + *m->log->getInfo() << "No syntax or stream encoding errors" |
| 849 | + << " found; the file may still contain\n" | ||
| 850 | + << "errors that qpdf cannot detect\n"; | ||
| 853 | } | 851 | } |
| 854 | } | 852 | } |
| 855 | 853 | ||
| @@ -873,18 +871,18 @@ QPDFJob::doShowObj(QPDF& pdf) | @@ -873,18 +871,18 @@ QPDFJob::doShowObj(QPDF& pdf) | ||
| 873 | } else { | 871 | } else { |
| 874 | // If anything has been written to standard output, | 872 | // If anything has been written to standard output, |
| 875 | // this will fail. | 873 | // this will fail. |
| 876 | - this->m->log->saveToStandardOutput(true); | 874 | + m->log->saveToStandardOutput(true); |
| 877 | obj.pipeStreamData( | 875 | obj.pipeStreamData( |
| 878 | - this->m->log->getSave().get(), | 876 | + m->log->getSave().get(), |
| 879 | (filter && m->normalize) ? qpdf_ef_normalize : 0, | 877 | (filter && m->normalize) ? qpdf_ef_normalize : 0, |
| 880 | filter ? qpdf_dl_all : qpdf_dl_none); | 878 | filter ? qpdf_dl_all : qpdf_dl_none); |
| 881 | } | 879 | } |
| 882 | } else { | 880 | } else { |
| 883 | - *this->m->log->getInfo() << "Object is stream. Dictionary:\n" | ||
| 884 | - << obj.getDict().unparseResolved() << "\n"; | 881 | + *m->log->getInfo() << "Object is stream. Dictionary:\n" |
| 882 | + << obj.getDict().unparseResolved() << "\n"; | ||
| 885 | } | 883 | } |
| 886 | } else { | 884 | } else { |
| 887 | - *this->m->log->getInfo() << obj.unparseResolved() << "\n"; | 885 | + *m->log->getInfo() << obj.unparseResolved() << "\n"; |
| 888 | } | 886 | } |
| 889 | if (error) { | 887 | if (error) { |
| 890 | throw std::runtime_error( | 888 | throw std::runtime_error( |
| @@ -896,7 +894,7 @@ void | @@ -896,7 +894,7 @@ void | ||
| 896 | QPDFJob::doShowPages(QPDF& pdf) | 894 | QPDFJob::doShowPages(QPDF& pdf) |
| 897 | { | 895 | { |
| 898 | int pageno = 0; | 896 | int pageno = 0; |
| 899 | - auto& cout = *this->m->log->getInfo(); | 897 | + auto& cout = *m->log->getInfo(); |
| 900 | for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) { | 898 | for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 901 | QPDFObjectHandle page = ph.getObjectHandle(); | 899 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 902 | ++pageno; | 900 | ++pageno; |
| @@ -934,7 +932,7 @@ QPDFJob::doListAttachments(QPDF& pdf) | @@ -934,7 +932,7 @@ QPDFJob::doListAttachments(QPDF& pdf) | ||
| 934 | for (auto const& i: efdh.getEmbeddedFiles()) { | 932 | for (auto const& i: efdh.getEmbeddedFiles()) { |
| 935 | std::string const& key = i.first; | 933 | std::string const& key = i.first; |
| 936 | auto efoh = i.second; | 934 | auto efoh = i.second; |
| 937 | - *this->m->log->getInfo() | 935 | + *m->log->getInfo() |
| 938 | << key << " -> " | 936 | << key << " -> " |
| 939 | << efoh->getEmbeddedFileStream().getObjGen().unparse(',') | 937 | << efoh->getEmbeddedFileStream().getObjGen().unparse(',') |
| 940 | << "\n"; | 938 | << "\n"; |
| @@ -963,8 +961,7 @@ QPDFJob::doListAttachments(QPDF& pdf) | @@ -963,8 +961,7 @@ QPDFJob::doListAttachments(QPDF& pdf) | ||
| 963 | }); | 961 | }); |
| 964 | } | 962 | } |
| 965 | } else { | 963 | } else { |
| 966 | - *this->m->log->getInfo() | ||
| 967 | - << m->infilename.get() << " has no embedded files\n"; | 964 | + *m->log->getInfo() << m->infilename.get() << " has no embedded files\n"; |
| 968 | } | 965 | } |
| 969 | } | 966 | } |
| 970 | 967 | ||
| @@ -980,8 +977,8 @@ QPDFJob::doShowAttachment(QPDF& pdf) | @@ -980,8 +977,8 @@ QPDFJob::doShowAttachment(QPDF& pdf) | ||
| 980 | auto efs = fs->getEmbeddedFileStream(); | 977 | auto efs = fs->getEmbeddedFileStream(); |
| 981 | // saveToStandardOutput has already been called, but it's harmless | 978 | // saveToStandardOutput has already been called, but it's harmless |
| 982 | // to call it again, so do as defensive coding. | 979 | // to call it again, so do as defensive coding. |
| 983 | - this->m->log->saveToStandardOutput(true); | ||
| 984 | - efs.pipeStreamData(this->m->log->getSave().get(), 0, qpdf_dl_all); | 980 | + m->log->saveToStandardOutput(true); |
| 981 | + efs.pipeStreamData(m->log->getSave().get(), 0, qpdf_dl_all); | ||
| 985 | } | 982 | } |
| 986 | 983 | ||
| 987 | void | 984 | void |
| @@ -1019,17 +1016,16 @@ void | @@ -1019,17 +1016,16 @@ void | ||
| 1019 | QPDFJob::doJSONObject( | 1016 | QPDFJob::doJSONObject( |
| 1020 | Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) | 1017 | Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) |
| 1021 | { | 1018 | { |
| 1022 | - if (this->m->json_version == 1) { | 1019 | + if (m->json_version == 1) { |
| 1023 | JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2); | 1020 | JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2); |
| 1024 | } else { | 1021 | } else { |
| 1025 | auto j = JSON::makeDictionary(); | 1022 | auto j = JSON::makeDictionary(); |
| 1026 | if (obj.isStream()) { | 1023 | if (obj.isStream()) { |
| 1027 | j.addDictionaryMember("stream", JSON::makeDictionary()) | 1024 | j.addDictionaryMember("stream", JSON::makeDictionary()) |
| 1028 | .addDictionaryMember( | 1025 | .addDictionaryMember( |
| 1029 | - "dict", obj.getDict().getJSON(this->m->json_version, true)); | 1026 | + "dict", obj.getDict().getJSON(m->json_version, true)); |
| 1030 | } else { | 1027 | } else { |
| 1031 | - j.addDictionaryMember( | ||
| 1032 | - "value", obj.getJSON(this->m->json_version, true)); | 1028 | + j.addDictionaryMember("value", obj.getJSON(m->json_version, true)); |
| 1033 | } | 1029 | } |
| 1034 | JSON::writeDictionaryItem(p, first, key, j, 2); | 1030 | JSON::writeDictionaryItem(p, first, key, j, 2); |
| 1035 | } | 1031 | } |
| @@ -1046,7 +1042,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) | @@ -1046,7 +1042,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1046 | auto wanted_og = getWantedJSONObjects(); | 1042 | auto wanted_og = getWantedJSONObjects(); |
| 1047 | for (auto& obj: pdf.getAllObjects()) { | 1043 | for (auto& obj: pdf.getAllObjects()) { |
| 1048 | std::string key = obj.unparse(); | 1044 | std::string key = obj.unparse(); |
| 1049 | - if (this->m->json_version > 1) { | 1045 | + if (m->json_version > 1) { |
| 1050 | key = "obj:" + key; | 1046 | key = "obj:" + key; |
| 1051 | } | 1047 | } |
| 1052 | if (all_objects || wanted_og.count(obj.getObjGen())) { | 1048 | if (all_objects || wanted_og.count(obj.getObjGen())) { |
| @@ -1060,20 +1056,20 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) | @@ -1060,20 +1056,20 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1060 | JSON::writeDictionaryClose(p, first_object, 1); | 1056 | JSON::writeDictionaryClose(p, first_object, 1); |
| 1061 | } else { | 1057 | } else { |
| 1062 | std::set<std::string> json_objects; | 1058 | std::set<std::string> json_objects; |
| 1063 | - if (this->m->json_objects.count("trailer")) { | 1059 | + if (m->json_objects.count("trailer")) { |
| 1064 | json_objects.insert("trailer"); | 1060 | json_objects.insert("trailer"); |
| 1065 | } | 1061 | } |
| 1066 | for (auto og: getWantedJSONObjects()) { | 1062 | for (auto og: getWantedJSONObjects()) { |
| 1067 | json_objects.emplace("obj:" + og.unparse(' ') + " R"); | 1063 | json_objects.emplace("obj:" + og.unparse(' ') + " R"); |
| 1068 | } | 1064 | } |
| 1069 | pdf.writeJSON( | 1065 | pdf.writeJSON( |
| 1070 | - this->m->json_version, | 1066 | + m->json_version, |
| 1071 | p, | 1067 | p, |
| 1072 | false, | 1068 | false, |
| 1073 | first, | 1069 | first, |
| 1074 | - this->m->decode_level, | ||
| 1075 | - this->m->json_stream_data, | ||
| 1076 | - this->m->json_stream_prefix, | 1070 | + m->decode_level, |
| 1071 | + m->json_stream_data, | ||
| 1072 | + m->json_stream_prefix, | ||
| 1077 | json_objects); | 1073 | json_objects); |
| 1078 | } | 1074 | } |
| 1079 | } | 1075 | } |
| @@ -1096,12 +1092,12 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) | @@ -1096,12 +1092,12 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1096 | j_stream.addDictionaryMember( | 1092 | j_stream.addDictionaryMember( |
| 1097 | "length", | 1093 | "length", |
| 1098 | (is_stream ? obj.getDict().getKey("/Length").getJSON( | 1094 | (is_stream ? obj.getDict().getKey("/Length").getJSON( |
| 1099 | - this->m->json_version, true) | 1095 | + m->json_version, true) |
| 1100 | : JSON::makeNull())); | 1096 | : JSON::makeNull())); |
| 1101 | j_stream.addDictionaryMember( | 1097 | j_stream.addDictionaryMember( |
| 1102 | "filter", | 1098 | "filter", |
| 1103 | (is_stream ? obj.getDict().getKey("/Filter").getJSON( | 1099 | (is_stream ? obj.getDict().getKey("/Filter").getJSON( |
| 1104 | - this->m->json_version, true) | 1100 | + m->json_version, true) |
| 1105 | : JSON::makeNull())); | 1101 | : JSON::makeNull())); |
| 1106 | JSON::writeDictionaryItem( | 1102 | JSON::writeDictionaryItem( |
| 1107 | p, first_object, obj.unparse(), j_details, 2); | 1103 | p, first_object, obj.unparse(), j_details, 2); |
| @@ -1123,8 +1119,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1123,8 +1119,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1123 | ++pageno; | 1119 | ++pageno; |
| 1124 | JSON j_page = JSON::makeDictionary(); | 1120 | JSON j_page = JSON::makeDictionary(); |
| 1125 | QPDFObjectHandle page = ph.getObjectHandle(); | 1121 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 1126 | - j_page.addDictionaryMember( | ||
| 1127 | - "object", page.getJSON(this->m->json_version)); | 1122 | + j_page.addDictionaryMember("object", page.getJSON(m->json_version)); |
| 1128 | JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray()); | 1123 | JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray()); |
| 1129 | for (auto const& iter2: ph.getImages()) { | 1124 | for (auto const& iter2: ph.getImages()) { |
| 1130 | JSON j_image = j_images.addArrayElement(JSON::makeDictionary()); | 1125 | JSON j_image = j_images.addArrayElement(JSON::makeDictionary()); |
| @@ -1132,22 +1127,20 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1132,22 +1127,20 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1132 | QPDFObjectHandle image = iter2.second; | 1127 | QPDFObjectHandle image = iter2.second; |
| 1133 | QPDFObjectHandle dict = image.getDict(); | 1128 | QPDFObjectHandle dict = image.getDict(); |
| 1134 | j_image.addDictionaryMember( | 1129 | j_image.addDictionaryMember( |
| 1135 | - "object", image.getJSON(this->m->json_version)); | 1130 | + "object", image.getJSON(m->json_version)); |
| 1136 | j_image.addDictionaryMember( | 1131 | j_image.addDictionaryMember( |
| 1137 | - "width", dict.getKey("/Width").getJSON(this->m->json_version)); | 1132 | + "width", dict.getKey("/Width").getJSON(m->json_version)); |
| 1138 | j_image.addDictionaryMember( | 1133 | j_image.addDictionaryMember( |
| 1139 | - "height", | ||
| 1140 | - dict.getKey("/Height").getJSON(this->m->json_version)); | 1134 | + "height", dict.getKey("/Height").getJSON(m->json_version)); |
| 1141 | j_image.addDictionaryMember( | 1135 | j_image.addDictionaryMember( |
| 1142 | "colorspace", | 1136 | "colorspace", |
| 1143 | - dict.getKey("/ColorSpace").getJSON(this->m->json_version)); | 1137 | + dict.getKey("/ColorSpace").getJSON(m->json_version)); |
| 1144 | j_image.addDictionaryMember( | 1138 | j_image.addDictionaryMember( |
| 1145 | "bitspercomponent", | 1139 | "bitspercomponent", |
| 1146 | - dict.getKey("/BitsPerComponent") | ||
| 1147 | - .getJSON(this->m->json_version)); | 1140 | + dict.getKey("/BitsPerComponent").getJSON(m->json_version)); |
| 1148 | QPDFObjectHandle filters = dict.getKey("/Filter").wrapInArray(); | 1141 | QPDFObjectHandle filters = dict.getKey("/Filter").wrapInArray(); |
| 1149 | j_image.addDictionaryMember( | 1142 | j_image.addDictionaryMember( |
| 1150 | - "filter", filters.getJSON(this->m->json_version)); | 1143 | + "filter", filters.getJSON(m->json_version)); |
| 1151 | QPDFObjectHandle decode_parms = dict.getKey("/DecodeParms"); | 1144 | QPDFObjectHandle decode_parms = dict.getKey("/DecodeParms"); |
| 1152 | QPDFObjectHandle dp_array; | 1145 | QPDFObjectHandle dp_array; |
| 1153 | if (decode_parms.isArray()) { | 1146 | if (decode_parms.isArray()) { |
| @@ -1159,7 +1152,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1159,7 +1152,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1159 | } | 1152 | } |
| 1160 | } | 1153 | } |
| 1161 | j_image.addDictionaryMember( | 1154 | j_image.addDictionaryMember( |
| 1162 | - "decodeparms", dp_array.getJSON(this->m->json_version)); | 1155 | + "decodeparms", dp_array.getJSON(m->json_version)); |
| 1163 | j_image.addDictionaryMember( | 1156 | j_image.addDictionaryMember( |
| 1164 | "filterable", | 1157 | "filterable", |
| 1165 | JSON::makeBool( | 1158 | JSON::makeBool( |
| @@ -1169,11 +1162,10 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1169,11 +1162,10 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1169 | JSON j_contents = | 1162 | JSON j_contents = |
| 1170 | j_page.addDictionaryMember("contents", JSON::makeArray()); | 1163 | j_page.addDictionaryMember("contents", JSON::makeArray()); |
| 1171 | for (auto& iter2: ph.getPageContents()) { | 1164 | for (auto& iter2: ph.getPageContents()) { |
| 1172 | - j_contents.addArrayElement(iter2.getJSON(this->m->json_version)); | 1165 | + j_contents.addArrayElement(iter2.getJSON(m->json_version)); |
| 1173 | } | 1166 | } |
| 1174 | j_page.addDictionaryMember( | 1167 | j_page.addDictionaryMember( |
| 1175 | - "label", | ||
| 1176 | - pldh.getLabelForPage(pageno).getJSON(this->m->json_version)); | 1168 | + "label", pldh.getLabelForPage(pageno).getJSON(m->json_version)); |
| 1177 | JSON j_outlines = | 1169 | JSON j_outlines = |
| 1178 | j_page.addDictionaryMember("outlines", JSON::makeArray()); | 1170 | j_page.addDictionaryMember("outlines", JSON::makeArray()); |
| 1179 | std::vector<QPDFOutlineObjectHelper> outlines = | 1171 | std::vector<QPDFOutlineObjectHelper> outlines = |
| @@ -1181,12 +1173,11 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1181,12 +1173,11 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1181 | for (auto& oiter: outlines) { | 1173 | for (auto& oiter: outlines) { |
| 1182 | JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary()); | 1174 | JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary()); |
| 1183 | j_outline.addDictionaryMember( | 1175 | j_outline.addDictionaryMember( |
| 1184 | - "object", | ||
| 1185 | - oiter.getObjectHandle().getJSON(this->m->json_version)); | 1176 | + "object", oiter.getObjectHandle().getJSON(m->json_version)); |
| 1186 | j_outline.addDictionaryMember( | 1177 | j_outline.addDictionaryMember( |
| 1187 | "title", JSON::makeString(oiter.getTitle())); | 1178 | "title", JSON::makeString(oiter.getTitle())); |
| 1188 | j_outline.addDictionaryMember( | 1179 | j_outline.addDictionaryMember( |
| 1189 | - "dest", oiter.getDest().getJSON(this->m->json_version, true)); | 1180 | + "dest", oiter.getDest().getJSON(m->json_version, true)); |
| 1190 | } | 1181 | } |
| 1191 | j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno)); | 1182 | j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno)); |
| 1192 | JSON::writeArrayItem(p, first_page, j_page, 2); | 1183 | JSON::writeArrayItem(p, first_page, j_page, 2); |
| @@ -1213,10 +1204,10 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | @@ -1213,10 +1204,10 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1213 | } | 1204 | } |
| 1214 | JSON j_label = j_labels.addArrayElement(JSON::makeDictionary()); | 1205 | JSON j_label = j_labels.addArrayElement(JSON::makeDictionary()); |
| 1215 | j_label.addDictionaryMember( | 1206 | j_label.addDictionaryMember( |
| 1216 | - "index", (*iter).getJSON(this->m->json_version)); | 1207 | + "index", (*iter).getJSON(m->json_version)); |
| 1217 | ++iter; | 1208 | ++iter; |
| 1218 | j_label.addDictionaryMember( | 1209 | j_label.addDictionaryMember( |
| 1219 | - "label", (*iter).getJSON(this->m->json_version)); | 1210 | + "label", (*iter).getJSON(m->json_version)); |
| 1220 | } | 1211 | } |
| 1221 | } | 1212 | } |
| 1222 | JSON::writeDictionaryItem(p, first, "pagelabels", j_labels, 1); | 1213 | JSON::writeDictionaryItem(p, first, "pagelabels", j_labels, 1); |
| @@ -1231,10 +1222,10 @@ QPDFJob::addOutlinesToJson( | @@ -1231,10 +1222,10 @@ QPDFJob::addOutlinesToJson( | ||
| 1231 | for (auto& ol: outlines) { | 1222 | for (auto& ol: outlines) { |
| 1232 | JSON jo = j.addArrayElement(JSON::makeDictionary()); | 1223 | JSON jo = j.addArrayElement(JSON::makeDictionary()); |
| 1233 | jo.addDictionaryMember( | 1224 | jo.addDictionaryMember( |
| 1234 | - "object", ol.getObjectHandle().getJSON(this->m->json_version)); | 1225 | + "object", ol.getObjectHandle().getJSON(m->json_version)); |
| 1235 | jo.addDictionaryMember("title", JSON::makeString(ol.getTitle())); | 1226 | jo.addDictionaryMember("title", JSON::makeString(ol.getTitle())); |
| 1236 | jo.addDictionaryMember( | 1227 | jo.addDictionaryMember( |
| 1237 | - "dest", ol.getDest().getJSON(this->m->json_version, true)); | 1228 | + "dest", ol.getDest().getJSON(m->json_version, true)); |
| 1238 | jo.addDictionaryMember("open", JSON::makeBool(ol.getCount() >= 0)); | 1229 | jo.addDictionaryMember("open", JSON::makeBool(ol.getCount() >= 0)); |
| 1239 | QPDFObjectHandle page = ol.getDestPage(); | 1230 | QPDFObjectHandle page = ol.getDestPage(); |
| 1240 | JSON j_destpage = JSON::makeNull(); | 1231 | JSON j_destpage = JSON::makeNull(); |
| @@ -1283,11 +1274,11 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1283,11 +1274,11 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1283 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); | 1274 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); |
| 1284 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); | 1275 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); |
| 1285 | j_field.addDictionaryMember( | 1276 | j_field.addDictionaryMember( |
| 1286 | - "object", ffh.getObjectHandle().getJSON(this->m->json_version)); | 1277 | + "object", ffh.getObjectHandle().getJSON(m->json_version)); |
| 1287 | j_field.addDictionaryMember( | 1278 | j_field.addDictionaryMember( |
| 1288 | "parent", | 1279 | "parent", |
| 1289 | ffh.getObjectHandle().getKey("/Parent").getJSON( | 1280 | ffh.getObjectHandle().getKey("/Parent").getJSON( |
| 1290 | - this->m->json_version)); | 1281 | + m->json_version)); |
| 1291 | j_field.addDictionaryMember( | 1282 | j_field.addDictionaryMember( |
| 1292 | "pageposfrom1", JSON::makeInt(pagepos1)); | 1283 | "pageposfrom1", JSON::makeInt(pagepos1)); |
| 1293 | j_field.addDictionaryMember( | 1284 | j_field.addDictionaryMember( |
| @@ -1303,10 +1294,9 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1303,10 +1294,9 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1303 | j_field.addDictionaryMember( | 1294 | j_field.addDictionaryMember( |
| 1304 | "mappingname", JSON::makeString(ffh.getMappingName())); | 1295 | "mappingname", JSON::makeString(ffh.getMappingName())); |
| 1305 | j_field.addDictionaryMember( | 1296 | j_field.addDictionaryMember( |
| 1306 | - "value", ffh.getValue().getJSON(this->m->json_version)); | 1297 | + "value", ffh.getValue().getJSON(m->json_version)); |
| 1307 | j_field.addDictionaryMember( | 1298 | j_field.addDictionaryMember( |
| 1308 | - "defaultvalue", | ||
| 1309 | - ffh.getDefaultValue().getJSON(this->m->json_version)); | 1299 | + "defaultvalue", ffh.getDefaultValue().getJSON(m->json_version)); |
| 1310 | j_field.addDictionaryMember( | 1300 | j_field.addDictionaryMember( |
| 1311 | "quadding", JSON::makeInt(ffh.getQuadding())); | 1301 | "quadding", JSON::makeInt(ffh.getQuadding())); |
| 1312 | j_field.addDictionaryMember( | 1302 | j_field.addDictionaryMember( |
| @@ -1324,7 +1314,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1324,7 +1314,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1324 | JSON j_annot = j_field.addDictionaryMember( | 1314 | JSON j_annot = j_field.addDictionaryMember( |
| 1325 | "annotation", JSON::makeDictionary()); | 1315 | "annotation", JSON::makeDictionary()); |
| 1326 | j_annot.addDictionaryMember( | 1316 | j_annot.addDictionaryMember( |
| 1327 | - "object", aoh.getObjectHandle().getJSON(this->m->json_version)); | 1317 | + "object", aoh.getObjectHandle().getJSON(m->json_version)); |
| 1328 | j_annot.addDictionaryMember( | 1318 | j_annot.addDictionaryMember( |
| 1329 | "appearancestate", JSON::makeString(aoh.getAppearanceState())); | 1319 | "appearancestate", JSON::makeString(aoh.getAppearanceState())); |
| 1330 | j_annot.addDictionaryMember( | 1320 | j_annot.addDictionaryMember( |
| @@ -1378,8 +1368,7 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf) | @@ -1378,8 +1368,7 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1378 | "modifyforms", JSON::makeBool(pdf.allowModifyForm())); | 1368 | "modifyforms", JSON::makeBool(pdf.allowModifyForm())); |
| 1379 | /* cSpell:ignore moddifyannotations */ | 1369 | /* cSpell:ignore moddifyannotations */ |
| 1380 | std::string MODIFY_ANNOTATIONS = | 1370 | std::string MODIFY_ANNOTATIONS = |
| 1381 | - (this->m->json_version == 1 ? "moddifyannotations" | ||
| 1382 | - : "modifyannotations"); | 1371 | + (m->json_version == 1 ? "moddifyannotations" : "modifyannotations"); |
| 1383 | j_capabilities.addDictionaryMember( | 1372 | j_capabilities.addDictionaryMember( |
| 1384 | MODIFY_ANNOTATIONS, JSON::makeBool(pdf.allowModifyAnnotation())); | 1373 | MODIFY_ANNOTATIONS, JSON::makeBool(pdf.allowModifyAnnotation())); |
| 1385 | j_capabilities.addDictionaryMember( | 1374 | j_capabilities.addDictionaryMember( |
| @@ -1722,7 +1711,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1722,7 +1711,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1722 | 1711 | ||
| 1723 | std::string captured_json; | 1712 | std::string captured_json; |
| 1724 | std::shared_ptr<Pl_String> pl_str; | 1713 | std::shared_ptr<Pl_String> pl_str; |
| 1725 | - if (this->m->test_json_schema) { | 1714 | + if (m->test_json_schema) { |
| 1726 | pl_str = std::make_shared<Pl_String>("capture json", p, captured_json); | 1715 | pl_str = std::make_shared<Pl_String>("capture json", p, captured_json); |
| 1727 | p = pl_str.get(); | 1716 | p = pl_str.get(); |
| 1728 | } | 1717 | } |
| @@ -1740,7 +1729,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1740,7 +1729,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1740 | // ignore unrecognized keys, so we only update the version of a | 1729 | // ignore unrecognized keys, so we only update the version of a |
| 1741 | // key disappears or if its value changes meaning. | 1730 | // key disappears or if its value changes meaning. |
| 1742 | JSON::writeDictionaryItem( | 1731 | JSON::writeDictionaryItem( |
| 1743 | - p, first, "version", JSON::makeInt(this->m->json_version), 1); | 1732 | + p, first, "version", JSON::makeInt(m->json_version), 1); |
| 1744 | JSON j_params = JSON::makeDictionary(); | 1733 | JSON j_params = JSON::makeDictionary(); |
| 1745 | std::string decode_level_str; | 1734 | std::string decode_level_str; |
| 1746 | switch (m->decode_level) { | 1735 | switch (m->decode_level) { |
| @@ -1799,7 +1788,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1799,7 +1788,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1799 | m->json_keys.count("qpdf")) { | 1788 | m->json_keys.count("qpdf")) { |
| 1800 | doJSONObjects(p, first, pdf); | 1789 | doJSONObjects(p, first, pdf); |
| 1801 | } | 1790 | } |
| 1802 | - if (this->m->json_version == 1) { | 1791 | + if (m->json_version == 1) { |
| 1803 | // "objectinfo" is not needed for version >1 since you can | 1792 | // "objectinfo" is not needed for version >1 since you can |
| 1804 | // tell streams from other objects in "objects". | 1793 | // tell streams from other objects in "objects". |
| 1805 | if (all_keys || m->json_keys.count("objectinfo")) { | 1794 | if (all_keys || m->json_keys.count("objectinfo")) { |
| @@ -1810,16 +1799,16 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1810,16 +1799,16 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1810 | JSON::writeDictionaryClose(p, first, 0); | 1799 | JSON::writeDictionaryClose(p, first, 0); |
| 1811 | *p << "\n"; | 1800 | *p << "\n"; |
| 1812 | 1801 | ||
| 1813 | - if (this->m->test_json_schema) { | 1802 | + if (m->test_json_schema) { |
| 1814 | // Check against schema | 1803 | // Check against schema |
| 1815 | - JSON schema = json_schema(this->m->json_version, &m->json_keys); | 1804 | + JSON schema = json_schema(m->json_version, &m->json_keys); |
| 1816 | std::list<std::string> errors; | 1805 | std::list<std::string> errors; |
| 1817 | JSON captured = JSON::parse(captured_json); | 1806 | JSON captured = JSON::parse(captured_json); |
| 1818 | if (!captured.checkSchema(schema, errors)) { | 1807 | if (!captured.checkSchema(schema, errors)) { |
| 1819 | - this->m->log->error("QPDFJob didn't create JSON that complies with " | ||
| 1820 | - "its own rules.\n"); | 1808 | + m->log->error("QPDFJob didn't create JSON that complies with " |
| 1809 | + "its own rules.\n"); | ||
| 1821 | for (auto const& error: errors) { | 1810 | for (auto const& error: errors) { |
| 1822 | - *this->m->log->getError() << error << "\n"; | 1811 | + *m->log->getError() << error << "\n"; |
| 1823 | } | 1812 | } |
| 1824 | } | 1813 | } |
| 1825 | } | 1814 | } |
| @@ -1828,7 +1817,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1828,7 +1817,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1828 | void | 1817 | void |
| 1829 | QPDFJob::doInspection(QPDF& pdf) | 1818 | QPDFJob::doInspection(QPDF& pdf) |
| 1830 | { | 1819 | { |
| 1831 | - auto& cout = *this->m->log->getInfo(); | 1820 | + auto& cout = *m->log->getInfo(); |
| 1832 | if (m->check) { | 1821 | if (m->check) { |
| 1833 | doCheck(pdf); | 1822 | doCheck(pdf); |
| 1834 | } | 1823 | } |
| @@ -1846,7 +1835,7 @@ QPDFJob::doInspection(QPDF& pdf) | @@ -1846,7 +1835,7 @@ QPDFJob::doInspection(QPDF& pdf) | ||
| 1846 | } else if (pdf.checkLinearization()) { | 1835 | } else if (pdf.checkLinearization()) { |
| 1847 | cout << m->infilename.get() << ": no linearization errors\n"; | 1836 | cout << m->infilename.get() << ": no linearization errors\n"; |
| 1848 | } else { | 1837 | } else { |
| 1849 | - this->m->warnings = true; | 1838 | + m->warnings = true; |
| 1850 | } | 1839 | } |
| 1851 | } | 1840 | } |
| 1852 | if (m->show_linearization) { | 1841 | if (m->show_linearization) { |
| @@ -1872,7 +1861,7 @@ QPDFJob::doInspection(QPDF& pdf) | @@ -1872,7 +1861,7 @@ QPDFJob::doInspection(QPDF& pdf) | ||
| 1872 | doShowAttachment(pdf); | 1861 | doShowAttachment(pdf); |
| 1873 | } | 1862 | } |
| 1874 | if (!pdf.getWarnings().empty()) { | 1863 | if (!pdf.getWarnings().empty()) { |
| 1875 | - this->m->warnings = true; | 1864 | + m->warnings = true; |
| 1876 | } | 1865 | } |
| 1877 | } | 1866 | } |
| 1878 | 1867 | ||
| @@ -1889,14 +1878,13 @@ QPDFJob::doProcessOnce( | @@ -1889,14 +1878,13 @@ QPDFJob::doProcessOnce( | ||
| 1889 | setQPDFOptions(*pdf); | 1878 | setQPDFOptions(*pdf); |
| 1890 | if (empty) { | 1879 | if (empty) { |
| 1891 | pdf->emptyPDF(); | 1880 | pdf->emptyPDF(); |
| 1892 | - } else if (main_input && this->m->json_input) { | ||
| 1893 | - pdf->createFromJSON(this->m->infilename.get()); | 1881 | + } else if (main_input && m->json_input) { |
| 1882 | + pdf->createFromJSON(m->infilename.get()); | ||
| 1894 | } else { | 1883 | } else { |
| 1895 | fn(pdf.get(), password); | 1884 | fn(pdf.get(), password); |
| 1896 | } | 1885 | } |
| 1897 | if (used_for_input) { | 1886 | if (used_for_input) { |
| 1898 | - this->m->max_input_version.updateIfGreater( | ||
| 1899 | - pdf->getVersionAsPDFVersion()); | 1887 | + m->max_input_version.updateIfGreater(pdf->getVersionAsPDFVersion()); |
| 1900 | } | 1888 | } |
| 1901 | } | 1889 | } |
| 1902 | 1890 | ||
| @@ -2314,7 +2302,7 @@ QPDFJob::copyAttachments(QPDF& pdf) | @@ -2314,7 +2302,7 @@ QPDFJob::copyAttachments(QPDF& pdf) | ||
| 2314 | } | 2302 | } |
| 2315 | 2303 | ||
| 2316 | if (other->anyWarnings()) { | 2304 | if (other->anyWarnings()) { |
| 2317 | - this->m->warnings = true; | 2305 | + m->warnings = true; |
| 2318 | } | 2306 | } |
| 2319 | } | 2307 | } |
| 2320 | 2308 | ||
| @@ -2917,8 +2905,8 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | @@ -2917,8 +2905,8 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | ||
| 2917 | password = encoded; | 2905 | password = encoded; |
| 2918 | } else { | 2906 | } else { |
| 2919 | QTC::TC("qpdf", "QPDFJob bytes fallback warning"); | 2907 | QTC::TC("qpdf", "QPDFJob bytes fallback warning"); |
| 2920 | - *this->m->log->getError() | ||
| 2921 | - << this->m->message_prefix << ": WARNING: " | 2908 | + *m->log->getError() |
| 2909 | + << m->message_prefix << ": WARNING: " | ||
| 2922 | << "supplied password looks like a Unicode" | 2910 | << "supplied password looks like a Unicode" |
| 2923 | << " password with characters not allowed in" | 2911 | << " password with characters not allowed in" |
| 2924 | << " passwords for 40-bit and 128-bit " | 2912 | << " passwords for 40-bit and 128-bit " |
| @@ -2965,17 +2953,17 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | @@ -2965,17 +2953,17 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | ||
| 2965 | throw std::logic_error("bad encryption keylen"); | 2953 | throw std::logic_error("bad encryption keylen"); |
| 2966 | } | 2954 | } |
| 2967 | if ((R > 3) && (m->r3_accessibility == false)) { | 2955 | if ((R > 3) && (m->r3_accessibility == false)) { |
| 2968 | - *this->m->log->getError() << this->m->message_prefix | ||
| 2969 | - << ": -accessibility=n is ignored for modern" | ||
| 2970 | - << " encryption formats\n"; | 2956 | + *m->log->getError() |
| 2957 | + << m->message_prefix << ": -accessibility=n is ignored for modern" | ||
| 2958 | + << " encryption formats\n"; | ||
| 2971 | } | 2959 | } |
| 2972 | maybeFixWritePassword(R, m->user_password); | 2960 | maybeFixWritePassword(R, m->user_password); |
| 2973 | maybeFixWritePassword(R, m->owner_password); | 2961 | maybeFixWritePassword(R, m->owner_password); |
| 2974 | if ((R < 4) || ((R == 4) && (!m->use_aes))) { | 2962 | if ((R < 4) || ((R == 4) && (!m->use_aes))) { |
| 2975 | if (!m->allow_weak_crypto) { | 2963 | if (!m->allow_weak_crypto) { |
| 2976 | QTC::TC("qpdf", "QPDFJob weak crypto error"); | 2964 | QTC::TC("qpdf", "QPDFJob weak crypto error"); |
| 2977 | - *this->m->log->getError() | ||
| 2978 | - << this->m->message_prefix | 2965 | + *m->log->getError() |
| 2966 | + << m->message_prefix | ||
| 2979 | << ": refusing to write a file with RC4, a weak " | 2967 | << ": refusing to write a file with RC4, a weak " |
| 2980 | "cryptographic " | 2968 | "cryptographic " |
| 2981 | "algorithm\n" | 2969 | "algorithm\n" |
| @@ -3141,7 +3129,7 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | @@ -3141,7 +3129,7 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | ||
| 3141 | if (m->object_stream_set) { | 3129 | if (m->object_stream_set) { |
| 3142 | w.setObjectStreamMode(m->object_stream_mode); | 3130 | w.setObjectStreamMode(m->object_stream_mode); |
| 3143 | } | 3131 | } |
| 3144 | - w.setMinimumPDFVersion(this->m->max_input_version); | 3132 | + w.setMinimumPDFVersion(m->max_input_version); |
| 3145 | if (!m->min_version.empty()) { | 3133 | if (!m->min_version.empty()) { |
| 3146 | std::string version; | 3134 | std::string version; |
| 3147 | int extension_level = 0; | 3135 | int extension_level = 0; |
| @@ -3155,22 +3143,19 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | @@ -3155,22 +3143,19 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | ||
| 3155 | w.forcePDFVersion(version, extension_level); | 3143 | w.forcePDFVersion(version, extension_level); |
| 3156 | } | 3144 | } |
| 3157 | if (m->progress) { | 3145 | if (m->progress) { |
| 3158 | - if (this->m->progress_handler) { | 3146 | + if (m->progress_handler) { |
| 3159 | w.registerProgressReporter( | 3147 | w.registerProgressReporter( |
| 3160 | std::shared_ptr<QPDFWriter::ProgressReporter>( | 3148 | std::shared_ptr<QPDFWriter::ProgressReporter>( |
| 3161 | new QPDFWriter::FunctionProgressReporter( | 3149 | new QPDFWriter::FunctionProgressReporter( |
| 3162 | - this->m->progress_handler))); | 3150 | + m->progress_handler))); |
| 3163 | } else { | 3151 | } else { |
| 3164 | - char const* outfilename = this->m->outfilename | ||
| 3165 | - ? this->m->outfilename.get() | ||
| 3166 | - : "standard output"; | 3152 | + char const* outfilename = |
| 3153 | + m->outfilename ? m->outfilename.get() : "standard output"; | ||
| 3167 | w.registerProgressReporter( | 3154 | w.registerProgressReporter( |
| 3168 | std::shared_ptr<QPDFWriter::ProgressReporter>( | 3155 | std::shared_ptr<QPDFWriter::ProgressReporter>( |
| 3169 | // line-break | 3156 | // line-break |
| 3170 | new ProgressReporter( | 3157 | new ProgressReporter( |
| 3171 | - *this->m->log->getInfo(), | ||
| 3172 | - this->m->message_prefix, | ||
| 3173 | - outfilename))); | 3158 | + *m->log->getInfo(), m->message_prefix, outfilename))); |
| 3174 | } | 3159 | } |
| 3175 | } | 3160 | } |
| 3176 | } | 3161 | } |
| @@ -3291,19 +3276,19 @@ QPDFJob::writeOutfile(QPDF& pdf) | @@ -3291,19 +3276,19 @@ QPDFJob::writeOutfile(QPDF& pdf) | ||
| 3291 | } else if (strcmp(m->outfilename.get(), "-") == 0) { | 3276 | } else if (strcmp(m->outfilename.get(), "-") == 0) { |
| 3292 | m->outfilename = nullptr; | 3277 | m->outfilename = nullptr; |
| 3293 | } | 3278 | } |
| 3294 | - if (this->m->json_version) { | 3279 | + if (m->json_version) { |
| 3295 | writeJSON(pdf); | 3280 | writeJSON(pdf); |
| 3296 | } else { | 3281 | } else { |
| 3297 | // QPDFWriter must have block scope so the output file will be | 3282 | // QPDFWriter must have block scope so the output file will be |
| 3298 | // closed after write() finishes. | 3283 | // closed after write() finishes. |
| 3299 | QPDFWriter w(pdf); | 3284 | QPDFWriter w(pdf); |
| 3300 | - if (this->m->outfilename) { | 3285 | + if (m->outfilename) { |
| 3301 | w.setOutputFilename(m->outfilename.get()); | 3286 | w.setOutputFilename(m->outfilename.get()); |
| 3302 | } else { | 3287 | } else { |
| 3303 | // saveToStandardOutput has already been called, but | 3288 | // saveToStandardOutput has already been called, but |
| 3304 | // calling it again is defensive and harmless. | 3289 | // calling it again is defensive and harmless. |
| 3305 | - this->m->log->saveToStandardOutput(true); | ||
| 3306 | - w.setOutputPipeline(this->m->log->getSave().get()); | 3290 | + m->log->saveToStandardOutput(true); |
| 3291 | + w.setOutputPipeline(m->log->getSave().get()); | ||
| 3307 | } | 3292 | } |
| 3308 | setWriterOptions(pdf, w); | 3293 | setWriterOptions(pdf, w); |
| 3309 | w.write(); | 3294 | w.write(); |
| @@ -3327,17 +3312,17 @@ QPDFJob::writeOutfile(QPDF& pdf) | @@ -3327,17 +3312,17 @@ QPDFJob::writeOutfile(QPDF& pdf) | ||
| 3327 | QUtil::rename_file(m->infilename.get(), backup.c_str()); | 3312 | QUtil::rename_file(m->infilename.get(), backup.c_str()); |
| 3328 | QUtil::rename_file(temp_out.get(), m->infilename.get()); | 3313 | QUtil::rename_file(temp_out.get(), m->infilename.get()); |
| 3329 | if (warnings) { | 3314 | if (warnings) { |
| 3330 | - *this->m->log->getError() | ||
| 3331 | - << this->m->message_prefix | 3315 | + *m->log->getError() |
| 3316 | + << m->message_prefix | ||
| 3332 | << ": there are warnings; original file kept in " << backup | 3317 | << ": there are warnings; original file kept in " << backup |
| 3333 | << "\n"; | 3318 | << "\n"; |
| 3334 | } else { | 3319 | } else { |
| 3335 | try { | 3320 | try { |
| 3336 | QUtil::remove_file(backup.c_str()); | 3321 | QUtil::remove_file(backup.c_str()); |
| 3337 | } catch (QPDFSystemError& e) { | 3322 | } catch (QPDFSystemError& e) { |
| 3338 | - *this->m->log->getError() | ||
| 3339 | - << this->m->message_prefix | ||
| 3340 | - << ": unable to delete original file (" << e.what() << ");" | 3323 | + *m->log->getError() |
| 3324 | + << m->message_prefix << ": unable to delete original file (" | ||
| 3325 | + << e.what() << ");" | ||
| 3341 | << " original file left in " << backup | 3326 | << " original file left in " << backup |
| 3342 | << ", but the input was successfully replaced\n"; | 3327 | << ", but the input was successfully replaced\n"; |
| 3343 | } | 3328 | } |
| @@ -3354,22 +3339,22 @@ QPDFJob::writeJSON(QPDF& pdf) | @@ -3354,22 +3339,22 @@ QPDFJob::writeJSON(QPDF& pdf) | ||
| 3354 | std::shared_ptr<Pipeline> fp; | 3339 | std::shared_ptr<Pipeline> fp; |
| 3355 | if (m->outfilename.get()) { | 3340 | if (m->outfilename.get()) { |
| 3356 | QTC::TC("qpdf", "QPDFJob write json to file"); | 3341 | QTC::TC("qpdf", "QPDFJob write json to file"); |
| 3357 | - if (this->m->json_stream_prefix.empty()) { | ||
| 3358 | - this->m->json_stream_prefix = this->m->outfilename.get(); | 3342 | + if (m->json_stream_prefix.empty()) { |
| 3343 | + m->json_stream_prefix = m->outfilename.get(); | ||
| 3359 | } | 3344 | } |
| 3360 | fc = std::make_shared<QUtil::FileCloser>( | 3345 | fc = std::make_shared<QUtil::FileCloser>( |
| 3361 | - QUtil::safe_fopen(this->m->outfilename.get(), "w")); | 3346 | + QUtil::safe_fopen(m->outfilename.get(), "w")); |
| 3362 | fp = std::make_shared<Pl_StdioFile>("json output", fc->f); | 3347 | fp = std::make_shared<Pl_StdioFile>("json output", fc->f); |
| 3363 | } else if ( | 3348 | } else if ( |
| 3364 | - (this->m->json_stream_data == qpdf_sj_file) && | ||
| 3365 | - this->m->json_stream_prefix.empty()) { | 3349 | + (m->json_stream_data == qpdf_sj_file) && |
| 3350 | + m->json_stream_prefix.empty()) { | ||
| 3366 | QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout"); | 3351 | QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout"); |
| 3367 | usage("please specify --json-stream-prefix since the input file " | 3352 | usage("please specify --json-stream-prefix since the input file " |
| 3368 | "name is unknown"); | 3353 | "name is unknown"); |
| 3369 | } else { | 3354 | } else { |
| 3370 | QTC::TC("qpdf", "QPDFJob write json to stdout"); | 3355 | QTC::TC("qpdf", "QPDFJob write json to stdout"); |
| 3371 | - this->m->log->saveToStandardOutput(true); | ||
| 3372 | - fp = this->m->log->getSave(); | 3356 | + m->log->saveToStandardOutput(true); |
| 3357 | + fp = m->log->getSave(); | ||
| 3373 | } | 3358 | } |
| 3374 | doJSON(pdf, fp.get()); | 3359 | doJSON(pdf, fp.get()); |
| 3375 | } | 3360 | } |
libqpdf/QPDFJob_json.cc
| @@ -582,7 +582,7 @@ QPDFJob::initializeFromJson(std::string const& json, bool partial) | @@ -582,7 +582,7 @@ QPDFJob::initializeFromJson(std::string const& json, bool partial) | ||
| 582 | JSON j = JSON::parse(json); | 582 | JSON j = JSON::parse(json); |
| 583 | if (!j.checkSchema(JOB_SCHEMA, JSON::f_optional, errors)) { | 583 | if (!j.checkSchema(JOB_SCHEMA, JSON::f_optional, errors)) { |
| 584 | std::ostringstream msg; | 584 | std::ostringstream msg; |
| 585 | - msg << this->m->message_prefix << ": job json has errors:"; | 585 | + msg << m->message_prefix << ": job json has errors:"; |
| 586 | for (auto const& error: errors) { | 586 | for (auto const& error: errors) { |
| 587 | msg << std::endl << " " << error; | 587 | msg << std::endl << " " << error; |
| 588 | } | 588 | } |
libqpdf/QPDFLogger.cc
| @@ -92,7 +92,7 @@ QPDFLogger::info(std::string const& s) | @@ -92,7 +92,7 @@ QPDFLogger::info(std::string const& s) | ||
| 92 | std::shared_ptr<Pipeline> | 92 | std::shared_ptr<Pipeline> |
| 93 | QPDFLogger::getInfo(bool null_okay) | 93 | QPDFLogger::getInfo(bool null_okay) |
| 94 | { | 94 | { |
| 95 | - return throwIfNull(this->m->p_info, null_okay); | 95 | + return throwIfNull(m->p_info, null_okay); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | void | 98 | void |
| @@ -110,8 +110,8 @@ QPDFLogger::warn(std::string const& s) | @@ -110,8 +110,8 @@ QPDFLogger::warn(std::string const& s) | ||
| 110 | std::shared_ptr<Pipeline> | 110 | std::shared_ptr<Pipeline> |
| 111 | QPDFLogger::getWarn(bool null_okay) | 111 | QPDFLogger::getWarn(bool null_okay) |
| 112 | { | 112 | { |
| 113 | - if (this->m->p_warn) { | ||
| 114 | - return this->m->p_warn; | 113 | + if (m->p_warn) { |
| 114 | + return m->p_warn; | ||
| 115 | } | 115 | } |
| 116 | return getError(null_okay); | 116 | return getError(null_okay); |
| 117 | } | 117 | } |
| @@ -131,83 +131,83 @@ QPDFLogger::error(std::string const& s) | @@ -131,83 +131,83 @@ QPDFLogger::error(std::string const& s) | ||
| 131 | std::shared_ptr<Pipeline> | 131 | std::shared_ptr<Pipeline> |
| 132 | QPDFLogger::getError(bool null_okay) | 132 | QPDFLogger::getError(bool null_okay) |
| 133 | { | 133 | { |
| 134 | - return throwIfNull(this->m->p_error, null_okay); | 134 | + return throwIfNull(m->p_error, null_okay); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | std::shared_ptr<Pipeline> | 137 | std::shared_ptr<Pipeline> |
| 138 | QPDFLogger::getSave(bool null_okay) | 138 | QPDFLogger::getSave(bool null_okay) |
| 139 | { | 139 | { |
| 140 | - return throwIfNull(this->m->p_save, null_okay); | 140 | + return throwIfNull(m->p_save, null_okay); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | std::shared_ptr<Pipeline> | 143 | std::shared_ptr<Pipeline> |
| 144 | QPDFLogger::standardOutput() | 144 | QPDFLogger::standardOutput() |
| 145 | { | 145 | { |
| 146 | - return this->m->p_stdout; | 146 | + return m->p_stdout; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | std::shared_ptr<Pipeline> | 149 | std::shared_ptr<Pipeline> |
| 150 | QPDFLogger::standardError() | 150 | QPDFLogger::standardError() |
| 151 | { | 151 | { |
| 152 | - return this->m->p_stderr; | 152 | + return m->p_stderr; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | std::shared_ptr<Pipeline> | 155 | std::shared_ptr<Pipeline> |
| 156 | QPDFLogger::discard() | 156 | QPDFLogger::discard() |
| 157 | { | 157 | { |
| 158 | - return this->m->p_discard; | 158 | + return m->p_discard; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | void | 161 | void |
| 162 | QPDFLogger::setInfo(std::shared_ptr<Pipeline> p) | 162 | QPDFLogger::setInfo(std::shared_ptr<Pipeline> p) |
| 163 | { | 163 | { |
| 164 | if (p == nullptr) { | 164 | if (p == nullptr) { |
| 165 | - if (this->m->p_save == this->m->p_stdout) { | ||
| 166 | - p = this->m->p_stderr; | 165 | + if (m->p_save == m->p_stdout) { |
| 166 | + p = m->p_stderr; | ||
| 167 | } else { | 167 | } else { |
| 168 | - p = this->m->p_stdout; | 168 | + p = m->p_stdout; |
| 169 | } | 169 | } |
| 170 | } | 170 | } |
| 171 | - this->m->p_info = p; | 171 | + m->p_info = p; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | void | 174 | void |
| 175 | QPDFLogger::setWarn(std::shared_ptr<Pipeline> p) | 175 | QPDFLogger::setWarn(std::shared_ptr<Pipeline> p) |
| 176 | { | 176 | { |
| 177 | - this->m->p_warn = p; | 177 | + m->p_warn = p; |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | void | 180 | void |
| 181 | QPDFLogger::setError(std::shared_ptr<Pipeline> p) | 181 | QPDFLogger::setError(std::shared_ptr<Pipeline> p) |
| 182 | { | 182 | { |
| 183 | if (p == nullptr) { | 183 | if (p == nullptr) { |
| 184 | - p = this->m->p_stderr; | 184 | + p = m->p_stderr; |
| 185 | } | 185 | } |
| 186 | - this->m->p_error = p; | 186 | + m->p_error = p; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | void | 189 | void |
| 190 | QPDFLogger::setSave(std::shared_ptr<Pipeline> p, bool only_if_not_set) | 190 | QPDFLogger::setSave(std::shared_ptr<Pipeline> p, bool only_if_not_set) |
| 191 | { | 191 | { |
| 192 | - if (only_if_not_set && (this->m->p_save != nullptr)) { | 192 | + if (only_if_not_set && (m->p_save != nullptr)) { |
| 193 | return; | 193 | return; |
| 194 | } | 194 | } |
| 195 | - if (this->m->p_save == p) { | 195 | + if (m->p_save == p) { |
| 196 | return; | 196 | return; |
| 197 | } | 197 | } |
| 198 | - if (p == this->m->p_stdout) { | 198 | + if (p == m->p_stdout) { |
| 199 | auto pt = dynamic_cast<Pl_Track*>(p.get()); | 199 | auto pt = dynamic_cast<Pl_Track*>(p.get()); |
| 200 | if (pt->getUsed()) { | 200 | if (pt->getUsed()) { |
| 201 | throw std::logic_error( | 201 | throw std::logic_error( |
| 202 | "QPDFLogger: called setSave on standard output after standard" | 202 | "QPDFLogger: called setSave on standard output after standard" |
| 203 | " output has already been used"); | 203 | " output has already been used"); |
| 204 | } | 204 | } |
| 205 | - if (this->m->p_info == this->m->p_stdout) { | ||
| 206 | - this->m->p_info = this->m->p_stderr; | 205 | + if (m->p_info == m->p_stdout) { |
| 206 | + m->p_info = m->p_stderr; | ||
| 207 | } | 207 | } |
| 208 | QUtil::binary_stdout(); | 208 | QUtil::binary_stdout(); |
| 209 | } | 209 | } |
| 210 | - this->m->p_save = p; | 210 | + m->p_save = p; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | void | 213 | void |
| @@ -229,22 +229,22 @@ QPDFLogger::setOutputStreams(std::ostream* out_stream, std::ostream* err_stream) | @@ -229,22 +229,22 @@ QPDFLogger::setOutputStreams(std::ostream* out_stream, std::ostream* err_stream) | ||
| 229 | std::shared_ptr<Pipeline> new_err; | 229 | std::shared_ptr<Pipeline> new_err; |
| 230 | 230 | ||
| 231 | if (out_stream == nullptr) { | 231 | if (out_stream == nullptr) { |
| 232 | - if (this->m->p_save == this->m->p_stdout) { | ||
| 233 | - new_out = this->m->p_stderr; | 232 | + if (m->p_save == m->p_stdout) { |
| 233 | + new_out = m->p_stderr; | ||
| 234 | } else { | 234 | } else { |
| 235 | - new_out = this->m->p_stdout; | 235 | + new_out = m->p_stdout; |
| 236 | } | 236 | } |
| 237 | } else { | 237 | } else { |
| 238 | new_out = std::make_shared<Pl_OStream>("output", *out_stream); | 238 | new_out = std::make_shared<Pl_OStream>("output", *out_stream); |
| 239 | } | 239 | } |
| 240 | if (err_stream == nullptr) { | 240 | if (err_stream == nullptr) { |
| 241 | - new_err = this->m->p_stderr; | 241 | + new_err = m->p_stderr; |
| 242 | } else { | 242 | } else { |
| 243 | new_err = std::make_shared<Pl_OStream>("error output", *err_stream); | 243 | new_err = std::make_shared<Pl_OStream>("error output", *err_stream); |
| 244 | } | 244 | } |
| 245 | - this->m->p_info = new_out; | ||
| 246 | - this->m->p_warn = nullptr; | ||
| 247 | - this->m->p_error = new_err; | 245 | + m->p_info = new_out; |
| 246 | + m->p_warn = nullptr; | ||
| 247 | + m->p_error = new_err; | ||
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | std::shared_ptr<Pipeline> | 250 | std::shared_ptr<Pipeline> |
libqpdf/QPDFNameTreeObjectHelper.cc
| @@ -140,26 +140,26 @@ QPDFNameTreeObjectHelper::iterator::remove() | @@ -140,26 +140,26 @@ QPDFNameTreeObjectHelper::iterator::remove() | ||
| 140 | QPDFNameTreeObjectHelper::iterator | 140 | QPDFNameTreeObjectHelper::iterator |
| 141 | QPDFNameTreeObjectHelper::begin() const | 141 | QPDFNameTreeObjectHelper::begin() const |
| 142 | { | 142 | { |
| 143 | - return iterator(std::make_shared<NNTreeIterator>(this->m->impl->begin())); | 143 | + return iterator(std::make_shared<NNTreeIterator>(m->impl->begin())); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | QPDFNameTreeObjectHelper::iterator | 146 | QPDFNameTreeObjectHelper::iterator |
| 147 | QPDFNameTreeObjectHelper::end() const | 147 | QPDFNameTreeObjectHelper::end() const |
| 148 | { | 148 | { |
| 149 | - return iterator(std::make_shared<NNTreeIterator>(this->m->impl->end())); | 149 | + return iterator(std::make_shared<NNTreeIterator>(m->impl->end())); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | QPDFNameTreeObjectHelper::iterator | 152 | QPDFNameTreeObjectHelper::iterator |
| 153 | QPDFNameTreeObjectHelper::last() const | 153 | QPDFNameTreeObjectHelper::last() const |
| 154 | { | 154 | { |
| 155 | - return iterator(std::make_shared<NNTreeIterator>(this->m->impl->last())); | 155 | + return iterator(std::make_shared<NNTreeIterator>(m->impl->last())); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | QPDFNameTreeObjectHelper::iterator | 158 | QPDFNameTreeObjectHelper::iterator |
| 159 | QPDFNameTreeObjectHelper::find( | 159 | QPDFNameTreeObjectHelper::find( |
| 160 | std::string const& key, bool return_prev_if_not_found) | 160 | std::string const& key, bool return_prev_if_not_found) |
| 161 | { | 161 | { |
| 162 | - auto i = this->m->impl->find( | 162 | + auto i = m->impl->find( |
| 163 | QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found); | 163 | QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found); |
| 164 | return iterator(std::make_shared<NNTreeIterator>(i)); | 164 | return iterator(std::make_shared<NNTreeIterator>(i)); |
| 165 | } | 165 | } |
| @@ -167,8 +167,7 @@ QPDFNameTreeObjectHelper::find( | @@ -167,8 +167,7 @@ QPDFNameTreeObjectHelper::find( | ||
| 167 | QPDFNameTreeObjectHelper::iterator | 167 | QPDFNameTreeObjectHelper::iterator |
| 168 | QPDFNameTreeObjectHelper::insert(std::string const& key, QPDFObjectHandle value) | 168 | QPDFNameTreeObjectHelper::insert(std::string const& key, QPDFObjectHandle value) |
| 169 | { | 169 | { |
| 170 | - auto i = | ||
| 171 | - this->m->impl->insert(QPDFObjectHandle::newUnicodeString(key), value); | 170 | + auto i = m->impl->insert(QPDFObjectHandle::newUnicodeString(key), value); |
| 172 | return iterator(std::make_shared<NNTreeIterator>(i)); | 171 | return iterator(std::make_shared<NNTreeIterator>(i)); |
| 173 | } | 172 | } |
| 174 | 173 | ||
| @@ -176,8 +175,7 @@ bool | @@ -176,8 +175,7 @@ bool | ||
| 176 | QPDFNameTreeObjectHelper::remove( | 175 | QPDFNameTreeObjectHelper::remove( |
| 177 | std::string const& key, QPDFObjectHandle* value) | 176 | std::string const& key, QPDFObjectHandle* value) |
| 178 | { | 177 | { |
| 179 | - return this->m->impl->remove( | ||
| 180 | - QPDFObjectHandle::newUnicodeString(key), value); | 178 | + return m->impl->remove(QPDFObjectHandle::newUnicodeString(key), value); |
| 181 | } | 179 | } |
| 182 | 180 | ||
| 183 | bool | 181 | bool |
| @@ -202,7 +200,7 @@ QPDFNameTreeObjectHelper::findObject( | @@ -202,7 +200,7 @@ QPDFNameTreeObjectHelper::findObject( | ||
| 202 | void | 200 | void |
| 203 | QPDFNameTreeObjectHelper::setSplitThreshold(int t) | 201 | QPDFNameTreeObjectHelper::setSplitThreshold(int t) |
| 204 | { | 202 | { |
| 205 | - this->m->impl->setSplitThreshold(t); | 203 | + m->impl->setSplitThreshold(t); |
| 206 | } | 204 | } |
| 207 | 205 | ||
| 208 | std::map<std::string, QPDFObjectHandle> | 206 | std::map<std::string, QPDFObjectHandle> |
libqpdf/QPDFNumberTreeObjectHelper.cc
| @@ -141,26 +141,26 @@ QPDFNumberTreeObjectHelper::iterator::remove() | @@ -141,26 +141,26 @@ QPDFNumberTreeObjectHelper::iterator::remove() | ||
| 141 | QPDFNumberTreeObjectHelper::iterator | 141 | QPDFNumberTreeObjectHelper::iterator |
| 142 | QPDFNumberTreeObjectHelper::begin() const | 142 | QPDFNumberTreeObjectHelper::begin() const |
| 143 | { | 143 | { |
| 144 | - return iterator(std::make_shared<NNTreeIterator>(this->m->impl->begin())); | 144 | + return iterator(std::make_shared<NNTreeIterator>(m->impl->begin())); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | QPDFNumberTreeObjectHelper::iterator | 147 | QPDFNumberTreeObjectHelper::iterator |
| 148 | QPDFNumberTreeObjectHelper::end() const | 148 | QPDFNumberTreeObjectHelper::end() const |
| 149 | { | 149 | { |
| 150 | - return iterator(std::make_shared<NNTreeIterator>(this->m->impl->end())); | 150 | + return iterator(std::make_shared<NNTreeIterator>(m->impl->end())); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | QPDFNumberTreeObjectHelper::iterator | 153 | QPDFNumberTreeObjectHelper::iterator |
| 154 | QPDFNumberTreeObjectHelper::last() const | 154 | QPDFNumberTreeObjectHelper::last() const |
| 155 | { | 155 | { |
| 156 | - return iterator(std::make_shared<NNTreeIterator>(this->m->impl->last())); | 156 | + return iterator(std::make_shared<NNTreeIterator>(m->impl->last())); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | QPDFNumberTreeObjectHelper::iterator | 159 | QPDFNumberTreeObjectHelper::iterator |
| 160 | QPDFNumberTreeObjectHelper::find( | 160 | QPDFNumberTreeObjectHelper::find( |
| 161 | numtree_number key, bool return_prev_if_not_found) | 161 | numtree_number key, bool return_prev_if_not_found) |
| 162 | { | 162 | { |
| 163 | - auto i = this->m->impl->find( | 163 | + auto i = m->impl->find( |
| 164 | QPDFObjectHandle::newInteger(key), return_prev_if_not_found); | 164 | QPDFObjectHandle::newInteger(key), return_prev_if_not_found); |
| 165 | return iterator(std::make_shared<NNTreeIterator>(i)); | 165 | return iterator(std::make_shared<NNTreeIterator>(i)); |
| 166 | } | 166 | } |
| @@ -168,14 +168,14 @@ QPDFNumberTreeObjectHelper::find( | @@ -168,14 +168,14 @@ QPDFNumberTreeObjectHelper::find( | ||
| 168 | QPDFNumberTreeObjectHelper::iterator | 168 | QPDFNumberTreeObjectHelper::iterator |
| 169 | QPDFNumberTreeObjectHelper::insert(numtree_number key, QPDFObjectHandle value) | 169 | QPDFNumberTreeObjectHelper::insert(numtree_number key, QPDFObjectHandle value) |
| 170 | { | 170 | { |
| 171 | - auto i = this->m->impl->insert(QPDFObjectHandle::newInteger(key), value); | 171 | + auto i = m->impl->insert(QPDFObjectHandle::newInteger(key), value); |
| 172 | return iterator(std::make_shared<NNTreeIterator>(i)); | 172 | return iterator(std::make_shared<NNTreeIterator>(i)); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | bool | 175 | bool |
| 176 | QPDFNumberTreeObjectHelper::remove(numtree_number key, QPDFObjectHandle* value) | 176 | QPDFNumberTreeObjectHelper::remove(numtree_number key, QPDFObjectHandle* value) |
| 177 | { | 177 | { |
| 178 | - return this->m->impl->remove(QPDFObjectHandle::newInteger(key), value); | 178 | + return m->impl->remove(QPDFObjectHandle::newInteger(key), value); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | QPDFNumberTreeObjectHelper::numtree_number | 181 | QPDFNumberTreeObjectHelper::numtree_number |
| @@ -233,7 +233,7 @@ QPDFNumberTreeObjectHelper::findObjectAtOrBelow( | @@ -233,7 +233,7 @@ QPDFNumberTreeObjectHelper::findObjectAtOrBelow( | ||
| 233 | void | 233 | void |
| 234 | QPDFNumberTreeObjectHelper::setSplitThreshold(int t) | 234 | QPDFNumberTreeObjectHelper::setSplitThreshold(int t) |
| 235 | { | 235 | { |
| 236 | - this->m->impl->setSplitThreshold(t); | 236 | + m->impl->setSplitThreshold(t); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | std::map<QPDFNumberTreeObjectHelper::numtree_number, QPDFObjectHandle> | 239 | std::map<QPDFNumberTreeObjectHelper::numtree_number, QPDFObjectHandle> |
libqpdf/QPDFObjectHandle.cc
| @@ -2517,7 +2517,7 @@ QPDFObjectHandle::QPDFDictItems::QPDFDictItems(QPDFObjectHandle const& oh) : | @@ -2517,7 +2517,7 @@ QPDFObjectHandle::QPDFDictItems::QPDFDictItems(QPDFObjectHandle const& oh) : | ||
| 2517 | QPDFObjectHandle::QPDFDictItems::iterator& | 2517 | QPDFObjectHandle::QPDFDictItems::iterator& |
| 2518 | QPDFObjectHandle::QPDFDictItems::iterator::operator++() | 2518 | QPDFObjectHandle::QPDFDictItems::iterator::operator++() |
| 2519 | { | 2519 | { |
| 2520 | - ++this->m->iter; | 2520 | + ++m->iter; |
| 2521 | updateIValue(); | 2521 | updateIValue(); |
| 2522 | return *this; | 2522 | return *this; |
| 2523 | } | 2523 | } |
| @@ -2525,7 +2525,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator++() | @@ -2525,7 +2525,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator++() | ||
| 2525 | QPDFObjectHandle::QPDFDictItems::iterator& | 2525 | QPDFObjectHandle::QPDFDictItems::iterator& |
| 2526 | QPDFObjectHandle::QPDFDictItems::iterator::operator--() | 2526 | QPDFObjectHandle::QPDFDictItems::iterator::operator--() |
| 2527 | { | 2527 | { |
| 2528 | - --this->m->iter; | 2528 | + --m->iter; |
| 2529 | updateIValue(); | 2529 | updateIValue(); |
| 2530 | return *this; | 2530 | return *this; |
| 2531 | } | 2531 | } |
| @@ -2548,10 +2548,10 @@ bool | @@ -2548,10 +2548,10 @@ bool | ||
| 2548 | QPDFObjectHandle::QPDFDictItems::iterator::operator==( | 2548 | QPDFObjectHandle::QPDFDictItems::iterator::operator==( |
| 2549 | iterator const& other) const | 2549 | iterator const& other) const |
| 2550 | { | 2550 | { |
| 2551 | - if (this->m->is_end && other.m->is_end) { | 2551 | + if (m->is_end && other.m->is_end) { |
| 2552 | return true; | 2552 | return true; |
| 2553 | } | 2553 | } |
| 2554 | - if (this->m->is_end || other.m->is_end) { | 2554 | + if (m->is_end || other.m->is_end) { |
| 2555 | return false; | 2555 | return false; |
| 2556 | } | 2556 | } |
| 2557 | return (this->ivalue.first == other.ivalue.first); | 2557 | return (this->ivalue.first == other.ivalue.first); |
| @@ -2567,13 +2567,13 @@ QPDFObjectHandle::QPDFDictItems::iterator::iterator( | @@ -2567,13 +2567,13 @@ QPDFObjectHandle::QPDFDictItems::iterator::iterator( | ||
| 2567 | void | 2567 | void |
| 2568 | QPDFObjectHandle::QPDFDictItems::iterator::updateIValue() | 2568 | QPDFObjectHandle::QPDFDictItems::iterator::updateIValue() |
| 2569 | { | 2569 | { |
| 2570 | - this->m->is_end = (this->m->iter == this->m->keys.end()); | ||
| 2571 | - if (this->m->is_end) { | 2570 | + m->is_end = (m->iter == m->keys.end()); |
| 2571 | + if (m->is_end) { | ||
| 2572 | this->ivalue.first = ""; | 2572 | this->ivalue.first = ""; |
| 2573 | this->ivalue.second = QPDFObjectHandle(); | 2573 | this->ivalue.second = QPDFObjectHandle(); |
| 2574 | } else { | 2574 | } else { |
| 2575 | - this->ivalue.first = *(this->m->iter); | ||
| 2576 | - this->ivalue.second = this->m->oh.getKey(this->ivalue.first); | 2575 | + this->ivalue.first = *(m->iter); |
| 2576 | + this->ivalue.second = m->oh.getKey(this->ivalue.first); | ||
| 2577 | } | 2577 | } |
| 2578 | } | 2578 | } |
| 2579 | 2579 | ||
| @@ -2605,8 +2605,8 @@ QPDFObjectHandle::QPDFArrayItems::QPDFArrayItems(QPDFObjectHandle const& oh) : | @@ -2605,8 +2605,8 @@ QPDFObjectHandle::QPDFArrayItems::QPDFArrayItems(QPDFObjectHandle const& oh) : | ||
| 2605 | QPDFObjectHandle::QPDFArrayItems::iterator& | 2605 | QPDFObjectHandle::QPDFArrayItems::iterator& |
| 2606 | QPDFObjectHandle::QPDFArrayItems::iterator::operator++() | 2606 | QPDFObjectHandle::QPDFArrayItems::iterator::operator++() |
| 2607 | { | 2607 | { |
| 2608 | - if (!this->m->is_end) { | ||
| 2609 | - ++this->m->item_number; | 2608 | + if (!m->is_end) { |
| 2609 | + ++m->item_number; | ||
| 2610 | updateIValue(); | 2610 | updateIValue(); |
| 2611 | } | 2611 | } |
| 2612 | return *this; | 2612 | return *this; |
| @@ -2615,8 +2615,8 @@ QPDFObjectHandle::QPDFArrayItems::iterator::operator++() | @@ -2615,8 +2615,8 @@ QPDFObjectHandle::QPDFArrayItems::iterator::operator++() | ||
| 2615 | QPDFObjectHandle::QPDFArrayItems::iterator& | 2615 | QPDFObjectHandle::QPDFArrayItems::iterator& |
| 2616 | QPDFObjectHandle::QPDFArrayItems::iterator::operator--() | 2616 | QPDFObjectHandle::QPDFArrayItems::iterator::operator--() |
| 2617 | { | 2617 | { |
| 2618 | - if (this->m->item_number > 0) { | ||
| 2619 | - --this->m->item_number; | 2618 | + if (m->item_number > 0) { |
| 2619 | + --m->item_number; | ||
| 2620 | updateIValue(); | 2620 | updateIValue(); |
| 2621 | } | 2621 | } |
| 2622 | return *this; | 2622 | return *this; |
| @@ -2640,7 +2640,7 @@ bool | @@ -2640,7 +2640,7 @@ bool | ||
| 2640 | QPDFObjectHandle::QPDFArrayItems::iterator::operator==( | 2640 | QPDFObjectHandle::QPDFArrayItems::iterator::operator==( |
| 2641 | iterator const& other) const | 2641 | iterator const& other) const |
| 2642 | { | 2642 | { |
| 2643 | - return (this->m->item_number == other.m->item_number); | 2643 | + return (m->item_number == other.m->item_number); |
| 2644 | } | 2644 | } |
| 2645 | 2645 | ||
| 2646 | QPDFObjectHandle::QPDFArrayItems::iterator::iterator( | 2646 | QPDFObjectHandle::QPDFArrayItems::iterator::iterator( |
| @@ -2653,11 +2653,11 @@ QPDFObjectHandle::QPDFArrayItems::iterator::iterator( | @@ -2653,11 +2653,11 @@ QPDFObjectHandle::QPDFArrayItems::iterator::iterator( | ||
| 2653 | void | 2653 | void |
| 2654 | QPDFObjectHandle::QPDFArrayItems::iterator::updateIValue() | 2654 | QPDFObjectHandle::QPDFArrayItems::iterator::updateIValue() |
| 2655 | { | 2655 | { |
| 2656 | - this->m->is_end = (this->m->item_number >= this->m->oh.getArrayNItems()); | ||
| 2657 | - if (this->m->is_end) { | 2656 | + m->is_end = (m->item_number >= m->oh.getArrayNItems()); |
| 2657 | + if (m->is_end) { | ||
| 2658 | this->ivalue = QPDFObjectHandle(); | 2658 | this->ivalue = QPDFObjectHandle(); |
| 2659 | } else { | 2659 | } else { |
| 2660 | - this->ivalue = this->m->oh.getArrayItem(this->m->item_number); | 2660 | + this->ivalue = m->oh.getArrayItem(m->item_number); |
| 2661 | } | 2661 | } |
| 2662 | } | 2662 | } |
| 2663 | 2663 |
libqpdf/QPDFOutlineDocumentHelper.cc
| @@ -17,7 +17,7 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) : | @@ -17,7 +17,7 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) : | ||
| 17 | QPDFObjectHandle cur = outlines.getKey("/First"); | 17 | QPDFObjectHandle cur = outlines.getKey("/First"); |
| 18 | QPDFObjGen::set seen; | 18 | QPDFObjGen::set seen; |
| 19 | while (!cur.isNull() && seen.add(cur)) { | 19 | while (!cur.isNull() && seen.add(cur)) { |
| 20 | - this->m->outlines.push_back( | 20 | + m->outlines.push_back( |
| 21 | QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1)); | 21 | QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1)); |
| 22 | cur = cur.getKey("/Next"); | 22 | cur = cur.getKey("/Next"); |
| 23 | } | 23 | } |
| @@ -26,26 +26,25 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) : | @@ -26,26 +26,25 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) : | ||
| 26 | bool | 26 | bool |
| 27 | QPDFOutlineDocumentHelper::hasOutlines() | 27 | QPDFOutlineDocumentHelper::hasOutlines() |
| 28 | { | 28 | { |
| 29 | - return !this->m->outlines.empty(); | 29 | + return !m->outlines.empty(); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | std::vector<QPDFOutlineObjectHelper> | 32 | std::vector<QPDFOutlineObjectHelper> |
| 33 | QPDFOutlineDocumentHelper::getTopLevelOutlines() | 33 | QPDFOutlineDocumentHelper::getTopLevelOutlines() |
| 34 | { | 34 | { |
| 35 | - return this->m->outlines; | 35 | + return m->outlines; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | void | 38 | void |
| 39 | QPDFOutlineDocumentHelper::initializeByPage() | 39 | QPDFOutlineDocumentHelper::initializeByPage() |
| 40 | { | 40 | { |
| 41 | std::list<QPDFOutlineObjectHelper> queue; | 41 | std::list<QPDFOutlineObjectHelper> queue; |
| 42 | - queue.insert( | ||
| 43 | - queue.end(), this->m->outlines.begin(), this->m->outlines.end()); | 42 | + queue.insert(queue.end(), m->outlines.begin(), m->outlines.end()); |
| 44 | 43 | ||
| 45 | while (!queue.empty()) { | 44 | while (!queue.empty()) { |
| 46 | QPDFOutlineObjectHelper oh = queue.front(); | 45 | QPDFOutlineObjectHelper oh = queue.front(); |
| 47 | queue.pop_front(); | 46 | queue.pop_front(); |
| 48 | - this->m->by_page[oh.getDestPage().getObjGen()].push_back(oh); | 47 | + m->by_page[oh.getDestPage().getObjGen()].push_back(oh); |
| 49 | std::vector<QPDFOutlineObjectHelper> kids = oh.getKids(); | 48 | std::vector<QPDFOutlineObjectHelper> kids = oh.getKids(); |
| 50 | queue.insert(queue.end(), kids.begin(), kids.end()); | 49 | queue.insert(queue.end(), kids.begin(), kids.end()); |
| 51 | } | 50 | } |
| @@ -54,12 +53,12 @@ QPDFOutlineDocumentHelper::initializeByPage() | @@ -54,12 +53,12 @@ QPDFOutlineDocumentHelper::initializeByPage() | ||
| 54 | std::vector<QPDFOutlineObjectHelper> | 53 | std::vector<QPDFOutlineObjectHelper> |
| 55 | QPDFOutlineDocumentHelper::getOutlinesForPage(QPDFObjGen const& og) | 54 | QPDFOutlineDocumentHelper::getOutlinesForPage(QPDFObjGen const& og) |
| 56 | { | 55 | { |
| 57 | - if (this->m->by_page.empty()) { | 56 | + if (m->by_page.empty()) { |
| 58 | initializeByPage(); | 57 | initializeByPage(); |
| 59 | } | 58 | } |
| 60 | std::vector<QPDFOutlineObjectHelper> result; | 59 | std::vector<QPDFOutlineObjectHelper> result; |
| 61 | - if (this->m->by_page.count(og)) { | ||
| 62 | - result = this->m->by_page[og]; | 60 | + if (m->by_page.count(og)) { |
| 61 | + result = m->by_page[og]; | ||
| 63 | } | 62 | } |
| 64 | return result; | 63 | return result; |
| 65 | } | 64 | } |
| @@ -69,27 +68,26 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name) | @@ -69,27 +68,26 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name) | ||
| 69 | { | 68 | { |
| 70 | QPDFObjectHandle result; | 69 | QPDFObjectHandle result; |
| 71 | if (name.isName()) { | 70 | if (name.isName()) { |
| 72 | - if (!this->m->dest_dict.isInitialized()) { | ||
| 73 | - this->m->dest_dict = this->qpdf.getRoot().getKey("/Dests"); | 71 | + if (!m->dest_dict.isInitialized()) { |
| 72 | + m->dest_dict = this->qpdf.getRoot().getKey("/Dests"); | ||
| 74 | } | 73 | } |
| 75 | - if (this->m->dest_dict.isDictionary()) { | 74 | + if (m->dest_dict.isDictionary()) { |
| 76 | QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest"); | 75 | QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest"); |
| 77 | - result = this->m->dest_dict.getKey(name.getName()); | 76 | + result = m->dest_dict.getKey(name.getName()); |
| 78 | } | 77 | } |
| 79 | } else if (name.isString()) { | 78 | } else if (name.isString()) { |
| 80 | - if (nullptr == this->m->names_dest) { | 79 | + if (nullptr == m->names_dest) { |
| 81 | QPDFObjectHandle names = this->qpdf.getRoot().getKey("/Names"); | 80 | QPDFObjectHandle names = this->qpdf.getRoot().getKey("/Names"); |
| 82 | if (names.isDictionary()) { | 81 | if (names.isDictionary()) { |
| 83 | QPDFObjectHandle dests = names.getKey("/Dests"); | 82 | QPDFObjectHandle dests = names.getKey("/Dests"); |
| 84 | if (dests.isDictionary()) { | 83 | if (dests.isDictionary()) { |
| 85 | - this->m->names_dest = | ||
| 86 | - std::make_shared<QPDFNameTreeObjectHelper>( | ||
| 87 | - dests, this->qpdf); | 84 | + m->names_dest = std::make_shared<QPDFNameTreeObjectHelper>( |
| 85 | + dests, this->qpdf); | ||
| 88 | } | 86 | } |
| 89 | } | 87 | } |
| 90 | } | 88 | } |
| 91 | - if (this->m->names_dest.get()) { | ||
| 92 | - if (this->m->names_dest->findObject(name.getUTF8Value(), result)) { | 89 | + if (m->names_dest.get()) { |
| 90 | + if (m->names_dest->findObject(name.getUTF8Value(), result)) { | ||
| 93 | QTC::TC("qpdf", "QPDFOutlineDocumentHelper string named dest"); | 91 | QTC::TC("qpdf", "QPDFOutlineDocumentHelper string named dest"); |
| 94 | } | 92 | } |
| 95 | } | 93 | } |
libqpdf/QPDFOutlineObjectHelper.cc
| @@ -19,7 +19,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | @@ -19,7 +19,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | ||
| 19 | return; | 19 | return; |
| 20 | } | 20 | } |
| 21 | if (QPDFOutlineDocumentHelper::Accessor::checkSeen( | 21 | if (QPDFOutlineDocumentHelper::Accessor::checkSeen( |
| 22 | - this->m->dh, this->oh.getObjGen())) { | 22 | + m->dh, this->oh.getObjGen())) { |
| 23 | QTC::TC("qpdf", "QPDFOutlineObjectHelper loop"); | 23 | QTC::TC("qpdf", "QPDFOutlineObjectHelper loop"); |
| 24 | return; | 24 | return; |
| 25 | } | 25 | } |
| @@ -28,7 +28,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | @@ -28,7 +28,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | ||
| 28 | while (!cur.isNull()) { | 28 | while (!cur.isNull()) { |
| 29 | QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth); | 29 | QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth); |
| 30 | new_ooh.m->parent = std::make_shared<QPDFOutlineObjectHelper>(*this); | 30 | new_ooh.m->parent = std::make_shared<QPDFOutlineObjectHelper>(*this); |
| 31 | - this->m->kids.push_back(new_ooh); | 31 | + m->kids.push_back(new_ooh); |
| 32 | cur = cur.getKey("/Next"); | 32 | cur = cur.getKey("/Next"); |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| @@ -36,13 +36,13 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | @@ -36,13 +36,13 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | ||
| 36 | std::shared_ptr<QPDFOutlineObjectHelper> | 36 | std::shared_ptr<QPDFOutlineObjectHelper> |
| 37 | QPDFOutlineObjectHelper::getParent() | 37 | QPDFOutlineObjectHelper::getParent() |
| 38 | { | 38 | { |
| 39 | - return this->m->parent; | 39 | + return m->parent; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | std::vector<QPDFOutlineObjectHelper> | 42 | std::vector<QPDFOutlineObjectHelper> |
| 43 | QPDFOutlineObjectHelper::getKids() | 43 | QPDFOutlineObjectHelper::getKids() |
| 44 | { | 44 | { |
| 45 | - return this->m->kids; | 45 | + return m->kids; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | QPDFObjectHandle | 48 | QPDFObjectHandle |
| @@ -65,7 +65,7 @@ QPDFOutlineObjectHelper::getDest() | @@ -65,7 +65,7 @@ QPDFOutlineObjectHelper::getDest() | ||
| 65 | 65 | ||
| 66 | if (dest.isName() || dest.isString()) { | 66 | if (dest.isName() || dest.isString()) { |
| 67 | QTC::TC("qpdf", "QPDFOutlineObjectHelper named dest"); | 67 | QTC::TC("qpdf", "QPDFOutlineObjectHelper named dest"); |
| 68 | - dest = this->m->dh.resolveNamedDest(dest); | 68 | + dest = m->dh.resolveNamedDest(dest); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | return dest; | 71 | return dest; |
libqpdf/QPDFPageLabelDocumentHelper.cc
| @@ -8,7 +8,7 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : | @@ -8,7 +8,7 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : | ||
| 8 | { | 8 | { |
| 9 | QPDFObjectHandle root = qpdf.getRoot(); | 9 | QPDFObjectHandle root = qpdf.getRoot(); |
| 10 | if (root.hasKey("/PageLabels")) { | 10 | if (root.hasKey("/PageLabels")) { |
| 11 | - this->m->labels = std::make_shared<QPDFNumberTreeObjectHelper>( | 11 | + m->labels = std::make_shared<QPDFNumberTreeObjectHelper>( |
| 12 | root.getKey("/PageLabels"), this->qpdf); | 12 | root.getKey("/PageLabels"), this->qpdf); |
| 13 | } | 13 | } |
| 14 | } | 14 | } |
| @@ -16,7 +16,7 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : | @@ -16,7 +16,7 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : | ||
| 16 | bool | 16 | bool |
| 17 | QPDFPageLabelDocumentHelper::hasPageLabels() | 17 | QPDFPageLabelDocumentHelper::hasPageLabels() |
| 18 | { | 18 | { |
| 19 | - return nullptr != this->m->labels; | 19 | + return nullptr != m->labels; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | QPDFObjectHandle | 22 | QPDFObjectHandle |
| @@ -28,7 +28,7 @@ QPDFPageLabelDocumentHelper::getLabelForPage(long long page_idx) | @@ -28,7 +28,7 @@ QPDFPageLabelDocumentHelper::getLabelForPage(long long page_idx) | ||
| 28 | } | 28 | } |
| 29 | QPDFNumberTreeObjectHelper::numtree_number offset = 0; | 29 | QPDFNumberTreeObjectHelper::numtree_number offset = 0; |
| 30 | QPDFObjectHandle label; | 30 | QPDFObjectHandle label; |
| 31 | - if (!this->m->labels->findObjectAtOrBelow(page_idx, label, offset)) { | 31 | + if (!m->labels->findObjectAtOrBelow(page_idx, label, offset)) { |
| 32 | return result; | 32 | return result; |
| 33 | } | 33 | } |
| 34 | if (!label.isDictionary()) { | 34 | if (!label.isDictionary()) { |
| @@ -96,7 +96,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | @@ -96,7 +96,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | ||
| 96 | 96 | ||
| 97 | long long int idx_offset = new_start_idx - start_idx; | 97 | long long int idx_offset = new_start_idx - start_idx; |
| 98 | for (long long i = start_idx + 1; i <= end_idx; ++i) { | 98 | for (long long i = start_idx + 1; i <= end_idx; ++i) { |
| 99 | - if (this->m->labels->hasIndex(i) && | 99 | + if (m->labels->hasIndex(i) && |
| 100 | (label = getLabelForPage(i)).isDictionary()) { | 100 | (label = getLabelForPage(i)).isDictionary()) { |
| 101 | new_labels.push_back(QPDFObjectHandle::newInteger(i + idx_offset)); | 101 | new_labels.push_back(QPDFObjectHandle::newInteger(i + idx_offset)); |
| 102 | new_labels.push_back(label); | 102 | new_labels.push_back(label); |
libqpdf/QPDFWriter.cc
| @@ -106,30 +106,29 @@ QPDFWriter::setOutputFilename(char const* filename) | @@ -106,30 +106,29 @@ QPDFWriter::setOutputFilename(char const* filename) | ||
| 106 | void | 106 | void |
| 107 | QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file) | 107 | QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file) |
| 108 | { | 108 | { |
| 109 | - this->m->filename = description; | ||
| 110 | - this->m->file = file; | ||
| 111 | - this->m->close_file = close_file; | 109 | + m->filename = description; |
| 110 | + m->file = file; | ||
| 111 | + m->close_file = close_file; | ||
| 112 | std::shared_ptr<Pipeline> p = | 112 | std::shared_ptr<Pipeline> p = |
| 113 | std::make_shared<Pl_StdioFile>("qpdf output", file); | 113 | std::make_shared<Pl_StdioFile>("qpdf output", file); |
| 114 | - this->m->to_delete.push_back(p); | 114 | + m->to_delete.push_back(p); |
| 115 | initializePipelineStack(p.get()); | 115 | initializePipelineStack(p.get()); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | void | 118 | void |
| 119 | QPDFWriter::setOutputMemory() | 119 | QPDFWriter::setOutputMemory() |
| 120 | { | 120 | { |
| 121 | - this->m->filename = "memory buffer"; | ||
| 122 | - this->m->buffer_pipeline = new Pl_Buffer("qpdf output"); | ||
| 123 | - this->m->to_delete.push_back( | ||
| 124 | - std::shared_ptr<Pipeline>(this->m->buffer_pipeline)); | ||
| 125 | - initializePipelineStack(this->m->buffer_pipeline); | 121 | + m->filename = "memory buffer"; |
| 122 | + m->buffer_pipeline = new Pl_Buffer("qpdf output"); | ||
| 123 | + m->to_delete.push_back(std::shared_ptr<Pipeline>(m->buffer_pipeline)); | ||
| 124 | + initializePipelineStack(m->buffer_pipeline); | ||
| 126 | } | 125 | } |
| 127 | 126 | ||
| 128 | Buffer* | 127 | Buffer* |
| 129 | QPDFWriter::getBuffer() | 128 | QPDFWriter::getBuffer() |
| 130 | { | 129 | { |
| 131 | - Buffer* result = this->m->output_buffer; | ||
| 132 | - this->m->output_buffer = nullptr; | 130 | + Buffer* result = m->output_buffer; |
| 131 | + m->output_buffer = nullptr; | ||
| 133 | return result; | 132 | return result; |
| 134 | } | 133 | } |
| 135 | 134 | ||
| @@ -142,14 +141,14 @@ QPDFWriter::getBufferSharedPointer() | @@ -142,14 +141,14 @@ QPDFWriter::getBufferSharedPointer() | ||
| 142 | void | 141 | void |
| 143 | QPDFWriter::setOutputPipeline(Pipeline* p) | 142 | QPDFWriter::setOutputPipeline(Pipeline* p) |
| 144 | { | 143 | { |
| 145 | - this->m->filename = "custom pipeline"; | 144 | + m->filename = "custom pipeline"; |
| 146 | initializePipelineStack(p); | 145 | initializePipelineStack(p); |
| 147 | } | 146 | } |
| 148 | 147 | ||
| 149 | void | 148 | void |
| 150 | QPDFWriter::setObjectStreamMode(qpdf_object_stream_e mode) | 149 | QPDFWriter::setObjectStreamMode(qpdf_object_stream_e mode) |
| 151 | { | 150 | { |
| 152 | - this->m->object_stream_mode = mode; | 151 | + m->object_stream_mode = mode; |
| 153 | } | 152 | } |
| 154 | 153 | ||
| 155 | void | 154 | void |
| @@ -157,69 +156,69 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode) | @@ -157,69 +156,69 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode) | ||
| 157 | { | 156 | { |
| 158 | switch (mode) { | 157 | switch (mode) { |
| 159 | case qpdf_s_uncompress: | 158 | case qpdf_s_uncompress: |
| 160 | - this->m->stream_decode_level = | ||
| 161 | - std::max(qpdf_dl_generalized, this->m->stream_decode_level); | ||
| 162 | - this->m->compress_streams = false; | 159 | + m->stream_decode_level = |
| 160 | + std::max(qpdf_dl_generalized, m->stream_decode_level); | ||
| 161 | + m->compress_streams = false; | ||
| 163 | break; | 162 | break; |
| 164 | 163 | ||
| 165 | case qpdf_s_preserve: | 164 | case qpdf_s_preserve: |
| 166 | - this->m->stream_decode_level = qpdf_dl_none; | ||
| 167 | - this->m->compress_streams = false; | 165 | + m->stream_decode_level = qpdf_dl_none; |
| 166 | + m->compress_streams = false; | ||
| 168 | break; | 167 | break; |
| 169 | 168 | ||
| 170 | case qpdf_s_compress: | 169 | case qpdf_s_compress: |
| 171 | - this->m->stream_decode_level = | ||
| 172 | - std::max(qpdf_dl_generalized, this->m->stream_decode_level); | ||
| 173 | - this->m->compress_streams = true; | 170 | + m->stream_decode_level = |
| 171 | + std::max(qpdf_dl_generalized, m->stream_decode_level); | ||
| 172 | + m->compress_streams = true; | ||
| 174 | break; | 173 | break; |
| 175 | } | 174 | } |
| 176 | - this->m->stream_decode_level_set = true; | ||
| 177 | - this->m->compress_streams_set = true; | 175 | + m->stream_decode_level_set = true; |
| 176 | + m->compress_streams_set = true; | ||
| 178 | } | 177 | } |
| 179 | 178 | ||
| 180 | void | 179 | void |
| 181 | QPDFWriter::setCompressStreams(bool val) | 180 | QPDFWriter::setCompressStreams(bool val) |
| 182 | { | 181 | { |
| 183 | - this->m->compress_streams = val; | ||
| 184 | - this->m->compress_streams_set = true; | 182 | + m->compress_streams = val; |
| 183 | + m->compress_streams_set = true; | ||
| 185 | } | 184 | } |
| 186 | 185 | ||
| 187 | void | 186 | void |
| 188 | QPDFWriter::setDecodeLevel(qpdf_stream_decode_level_e val) | 187 | QPDFWriter::setDecodeLevel(qpdf_stream_decode_level_e val) |
| 189 | { | 188 | { |
| 190 | - this->m->stream_decode_level = val; | ||
| 191 | - this->m->stream_decode_level_set = true; | 189 | + m->stream_decode_level = val; |
| 190 | + m->stream_decode_level_set = true; | ||
| 192 | } | 191 | } |
| 193 | 192 | ||
| 194 | void | 193 | void |
| 195 | QPDFWriter::setRecompressFlate(bool val) | 194 | QPDFWriter::setRecompressFlate(bool val) |
| 196 | { | 195 | { |
| 197 | - this->m->recompress_flate = val; | 196 | + m->recompress_flate = val; |
| 198 | } | 197 | } |
| 199 | 198 | ||
| 200 | void | 199 | void |
| 201 | QPDFWriter::setContentNormalization(bool val) | 200 | QPDFWriter::setContentNormalization(bool val) |
| 202 | { | 201 | { |
| 203 | - this->m->normalize_content_set = true; | ||
| 204 | - this->m->normalize_content = val; | 202 | + m->normalize_content_set = true; |
| 203 | + m->normalize_content = val; | ||
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | void | 206 | void |
| 208 | QPDFWriter::setQDFMode(bool val) | 207 | QPDFWriter::setQDFMode(bool val) |
| 209 | { | 208 | { |
| 210 | - this->m->qdf_mode = val; | 209 | + m->qdf_mode = val; |
| 211 | } | 210 | } |
| 212 | 211 | ||
| 213 | void | 212 | void |
| 214 | QPDFWriter::setPreserveUnreferencedObjects(bool val) | 213 | QPDFWriter::setPreserveUnreferencedObjects(bool val) |
| 215 | { | 214 | { |
| 216 | - this->m->preserve_unreferenced_objects = val; | 215 | + m->preserve_unreferenced_objects = val; |
| 217 | } | 216 | } |
| 218 | 217 | ||
| 219 | void | 218 | void |
| 220 | QPDFWriter::setNewlineBeforeEndstream(bool val) | 219 | QPDFWriter::setNewlineBeforeEndstream(bool val) |
| 221 | { | 220 | { |
| 222 | - this->m->newline_before_endstream = val; | 221 | + m->newline_before_endstream = val; |
| 223 | } | 222 | } |
| 224 | 223 | ||
| 225 | void | 224 | void |
| @@ -228,7 +227,7 @@ QPDFWriter::setMinimumPDFVersion( | @@ -228,7 +227,7 @@ QPDFWriter::setMinimumPDFVersion( | ||
| 228 | { | 227 | { |
| 229 | bool set_version = false; | 228 | bool set_version = false; |
| 230 | bool set_extension_level = false; | 229 | bool set_extension_level = false; |
| 231 | - if (this->m->min_pdf_version.empty()) { | 230 | + if (m->min_pdf_version.empty()) { |
| 232 | set_version = true; | 231 | set_version = true; |
| 233 | set_extension_level = true; | 232 | set_extension_level = true; |
| 234 | } else { | 233 | } else { |
| @@ -237,7 +236,7 @@ QPDFWriter::setMinimumPDFVersion( | @@ -237,7 +236,7 @@ QPDFWriter::setMinimumPDFVersion( | ||
| 237 | int min_major = 0; | 236 | int min_major = 0; |
| 238 | int min_minor = 0; | 237 | int min_minor = 0; |
| 239 | parseVersion(version, old_major, old_minor); | 238 | parseVersion(version, old_major, old_minor); |
| 240 | - parseVersion(this->m->min_pdf_version, min_major, min_minor); | 239 | + parseVersion(m->min_pdf_version, min_major, min_minor); |
| 241 | int compare = | 240 | int compare = |
| 242 | compareVersions(old_major, old_minor, min_major, min_minor); | 241 | compareVersions(old_major, old_minor, min_major, min_minor); |
| 243 | if (compare > 0) { | 242 | if (compare > 0) { |
| @@ -248,7 +247,7 @@ QPDFWriter::setMinimumPDFVersion( | @@ -248,7 +247,7 @@ QPDFWriter::setMinimumPDFVersion( | ||
| 248 | set_version = true; | 247 | set_version = true; |
| 249 | set_extension_level = true; | 248 | set_extension_level = true; |
| 250 | } else if (compare == 0) { | 249 | } else if (compare == 0) { |
| 251 | - if (extension_level > this->m->min_extension_level) { | 250 | + if (extension_level > m->min_extension_level) { |
| 252 | QTC::TC("qpdf", "QPDFWriter increasing extension level"); | 251 | QTC::TC("qpdf", "QPDFWriter increasing extension level"); |
| 253 | set_extension_level = true; | 252 | set_extension_level = true; |
| 254 | } | 253 | } |
| @@ -256,10 +255,10 @@ QPDFWriter::setMinimumPDFVersion( | @@ -256,10 +255,10 @@ QPDFWriter::setMinimumPDFVersion( | ||
| 256 | } | 255 | } |
| 257 | 256 | ||
| 258 | if (set_version) { | 257 | if (set_version) { |
| 259 | - this->m->min_pdf_version = version; | 258 | + m->min_pdf_version = version; |
| 260 | } | 259 | } |
| 261 | if (set_extension_level) { | 260 | if (set_extension_level) { |
| 262 | - this->m->min_extension_level = extension_level; | 261 | + m->min_extension_level = extension_level; |
| 263 | } | 262 | } |
| 264 | } | 263 | } |
| 265 | 264 | ||
| @@ -275,18 +274,18 @@ QPDFWriter::setMinimumPDFVersion(PDFVersion const& v) | @@ -275,18 +274,18 @@ QPDFWriter::setMinimumPDFVersion(PDFVersion const& v) | ||
| 275 | void | 274 | void |
| 276 | QPDFWriter::forcePDFVersion(std::string const& version, int extension_level) | 275 | QPDFWriter::forcePDFVersion(std::string const& version, int extension_level) |
| 277 | { | 276 | { |
| 278 | - this->m->forced_pdf_version = version; | ||
| 279 | - this->m->forced_extension_level = extension_level; | 277 | + m->forced_pdf_version = version; |
| 278 | + m->forced_extension_level = extension_level; | ||
| 280 | } | 279 | } |
| 281 | 280 | ||
| 282 | void | 281 | void |
| 283 | QPDFWriter::setExtraHeaderText(std::string const& text) | 282 | QPDFWriter::setExtraHeaderText(std::string const& text) |
| 284 | { | 283 | { |
| 285 | - this->m->extra_header_text = text; | ||
| 286 | - if ((this->m->extra_header_text.length() > 0) && | ||
| 287 | - (*(this->m->extra_header_text.rbegin()) != '\n')) { | 284 | + m->extra_header_text = text; |
| 285 | + if ((m->extra_header_text.length() > 0) && | ||
| 286 | + (*(m->extra_header_text.rbegin()) != '\n')) { | ||
| 288 | QTC::TC("qpdf", "QPDFWriter extra header text add newline"); | 287 | QTC::TC("qpdf", "QPDFWriter extra header text add newline"); |
| 289 | - this->m->extra_header_text += "\n"; | 288 | + m->extra_header_text += "\n"; |
| 290 | } else { | 289 | } else { |
| 291 | QTC::TC("qpdf", "QPDFWriter extra header text no newline"); | 290 | QTC::TC("qpdf", "QPDFWriter extra header text no newline"); |
| 292 | } | 291 | } |
| @@ -295,13 +294,13 @@ QPDFWriter::setExtraHeaderText(std::string const& text) | @@ -295,13 +294,13 @@ QPDFWriter::setExtraHeaderText(std::string const& text) | ||
| 295 | void | 294 | void |
| 296 | QPDFWriter::setStaticID(bool val) | 295 | QPDFWriter::setStaticID(bool val) |
| 297 | { | 296 | { |
| 298 | - this->m->static_id = val; | 297 | + m->static_id = val; |
| 299 | } | 298 | } |
| 300 | 299 | ||
| 301 | void | 300 | void |
| 302 | QPDFWriter::setDeterministicID(bool val) | 301 | QPDFWriter::setDeterministicID(bool val) |
| 303 | { | 302 | { |
| 304 | - this->m->deterministic_id = val; | 303 | + m->deterministic_id = val; |
| 305 | } | 304 | } |
| 306 | 305 | ||
| 307 | void | 306 | void |
| @@ -315,36 +314,36 @@ QPDFWriter::setStaticAesIV(bool val) | @@ -315,36 +314,36 @@ QPDFWriter::setStaticAesIV(bool val) | ||
| 315 | void | 314 | void |
| 316 | QPDFWriter::setSuppressOriginalObjectIDs(bool val) | 315 | QPDFWriter::setSuppressOriginalObjectIDs(bool val) |
| 317 | { | 316 | { |
| 318 | - this->m->suppress_original_object_ids = val; | 317 | + m->suppress_original_object_ids = val; |
| 319 | } | 318 | } |
| 320 | 319 | ||
| 321 | void | 320 | void |
| 322 | QPDFWriter::setPreserveEncryption(bool val) | 321 | QPDFWriter::setPreserveEncryption(bool val) |
| 323 | { | 322 | { |
| 324 | - this->m->preserve_encryption = val; | 323 | + m->preserve_encryption = val; |
| 325 | } | 324 | } |
| 326 | 325 | ||
| 327 | void | 326 | void |
| 328 | QPDFWriter::setLinearization(bool val) | 327 | QPDFWriter::setLinearization(bool val) |
| 329 | { | 328 | { |
| 330 | - this->m->linearized = val; | 329 | + m->linearized = val; |
| 331 | if (val) { | 330 | if (val) { |
| 332 | - this->m->pclm = false; | 331 | + m->pclm = false; |
| 333 | } | 332 | } |
| 334 | } | 333 | } |
| 335 | 334 | ||
| 336 | void | 335 | void |
| 337 | QPDFWriter::setLinearizationPass1Filename(std::string const& filename) | 336 | QPDFWriter::setLinearizationPass1Filename(std::string const& filename) |
| 338 | { | 337 | { |
| 339 | - this->m->lin_pass1_filename = filename; | 338 | + m->lin_pass1_filename = filename; |
| 340 | } | 339 | } |
| 341 | 340 | ||
| 342 | void | 341 | void |
| 343 | QPDFWriter::setPCLm(bool val) | 342 | QPDFWriter::setPCLm(bool val) |
| 344 | { | 343 | { |
| 345 | - this->m->pclm = val; | 344 | + m->pclm = val; |
| 346 | if (val) { | 345 | if (val) { |
| 347 | - this->m->linearized = false; | 346 | + m->linearized = false; |
| 348 | } | 347 | } |
| 349 | } | 348 | } |
| 350 | 349 | ||
| @@ -429,8 +428,8 @@ QPDFWriter::setR4EncryptionParametersInsecure( | @@ -429,8 +428,8 @@ QPDFWriter::setR4EncryptionParametersInsecure( | ||
| 429 | allow_modify_other, | 428 | allow_modify_other, |
| 430 | print, | 429 | print, |
| 431 | qpdf_r3m_all); | 430 | qpdf_r3m_all); |
| 432 | - this->m->encrypt_use_aes = use_aes; | ||
| 433 | - this->m->encrypt_metadata = encrypt_metadata; | 431 | + m->encrypt_use_aes = use_aes; |
| 432 | + m->encrypt_metadata = encrypt_metadata; | ||
| 434 | setEncryptionParameters(user_password, owner_password, 4, 4, 16, clear); | 433 | setEncryptionParameters(user_password, owner_password, 4, 4, 16, clear); |
| 435 | } | 434 | } |
| 436 | 435 | ||
| @@ -460,8 +459,8 @@ QPDFWriter::setR5EncryptionParameters( | @@ -460,8 +459,8 @@ QPDFWriter::setR5EncryptionParameters( | ||
| 460 | allow_modify_other, | 459 | allow_modify_other, |
| 461 | print, | 460 | print, |
| 462 | qpdf_r3m_all); | 461 | qpdf_r3m_all); |
| 463 | - this->m->encrypt_use_aes = true; | ||
| 464 | - this->m->encrypt_metadata = encrypt_metadata; | 462 | + m->encrypt_use_aes = true; |
| 463 | + m->encrypt_metadata = encrypt_metadata; | ||
| 465 | setEncryptionParameters(user_password, owner_password, 5, 5, 32, clear); | 464 | setEncryptionParameters(user_password, owner_password, 5, 5, 32, clear); |
| 466 | } | 465 | } |
| 467 | 466 | ||
| @@ -491,8 +490,8 @@ QPDFWriter::setR6EncryptionParameters( | @@ -491,8 +490,8 @@ QPDFWriter::setR6EncryptionParameters( | ||
| 491 | allow_modify_other, | 490 | allow_modify_other, |
| 492 | print, | 491 | print, |
| 493 | qpdf_r3m_all); | 492 | qpdf_r3m_all); |
| 494 | - this->m->encrypt_use_aes = true; | ||
| 495 | - this->m->encrypt_metadata = encrypt_metadata; | 493 | + m->encrypt_use_aes = true; |
| 494 | + m->encrypt_metadata = encrypt_metadata; | ||
| 496 | setEncryptionParameters(user_password, owner_password, 5, 6, 32, clear); | 495 | setEncryptionParameters(user_password, owner_password, 5, 6, 32, clear); |
| 497 | } | 496 | } |
| 498 | 497 | ||
| @@ -649,8 +648,8 @@ QPDFWriter::setEncryptionParameters( | @@ -649,8 +648,8 @@ QPDFWriter::setEncryptionParameters( | ||
| 649 | R, | 648 | R, |
| 650 | key_len, | 649 | key_len, |
| 651 | P, | 650 | P, |
| 652 | - this->m->encrypt_metadata, | ||
| 653 | - this->m->id1, | 651 | + m->encrypt_metadata, |
| 652 | + m->id1, | ||
| 654 | O, | 653 | O, |
| 655 | U); | 654 | U); |
| 656 | } else { | 655 | } else { |
| @@ -661,8 +660,8 @@ QPDFWriter::setEncryptionParameters( | @@ -661,8 +660,8 @@ QPDFWriter::setEncryptionParameters( | ||
| 661 | R, | 660 | R, |
| 662 | key_len, | 661 | key_len, |
| 663 | P, | 662 | P, |
| 664 | - this->m->encrypt_metadata, | ||
| 665 | - this->m->id1, | 663 | + m->encrypt_metadata, |
| 664 | + m->id1, | ||
| 666 | encryption_key, | 665 | encryption_key, |
| 667 | O, | 666 | O, |
| 668 | U, | 667 | U, |
| @@ -680,7 +679,7 @@ QPDFWriter::setEncryptionParameters( | @@ -680,7 +679,7 @@ QPDFWriter::setEncryptionParameters( | ||
| 680 | OE, | 679 | OE, |
| 681 | UE, | 680 | UE, |
| 682 | Perms, | 681 | Perms, |
| 683 | - this->m->id1, | 682 | + m->id1, |
| 684 | user_password, | 683 | user_password, |
| 685 | encryption_key); | 684 | encryption_key); |
| 686 | } | 685 | } |
| @@ -688,11 +687,11 @@ QPDFWriter::setEncryptionParameters( | @@ -688,11 +687,11 @@ QPDFWriter::setEncryptionParameters( | ||
| 688 | void | 687 | void |
| 689 | QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | 688 | QPDFWriter::copyEncryptionParameters(QPDF& qpdf) |
| 690 | { | 689 | { |
| 691 | - this->m->preserve_encryption = false; | 690 | + m->preserve_encryption = false; |
| 692 | QPDFObjectHandle trailer = qpdf.getTrailer(); | 691 | QPDFObjectHandle trailer = qpdf.getTrailer(); |
| 693 | if (trailer.hasKey("/Encrypt")) { | 692 | if (trailer.hasKey("/Encrypt")) { |
| 694 | generateID(); | 693 | generateID(); |
| 695 | - this->m->id1 = trailer.getKey("/ID").getArrayItem(0).getStringValue(); | 694 | + m->id1 = trailer.getKey("/ID").getArrayItem(0).getStringValue(); |
| 696 | QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); | 695 | QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); |
| 697 | int V = encrypt.getKey("/V").getIntValueAsInt(); | 696 | int V = encrypt.getKey("/V").getIntValueAsInt(); |
| 698 | int key_len = 5; | 697 | int key_len = 5; |
| @@ -701,7 +700,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -701,7 +700,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 701 | } | 700 | } |
| 702 | if (encrypt.hasKey("/EncryptMetadata") && | 701 | if (encrypt.hasKey("/EncryptMetadata") && |
| 703 | encrypt.getKey("/EncryptMetadata").isBool()) { | 702 | encrypt.getKey("/EncryptMetadata").isBool()) { |
| 704 | - this->m->encrypt_metadata = | 703 | + m->encrypt_metadata = |
| 705 | encrypt.getKey("/EncryptMetadata").getBoolValue(); | 704 | encrypt.getKey("/EncryptMetadata").getBoolValue(); |
| 706 | } | 705 | } |
| 707 | if (V >= 4) { | 706 | if (V >= 4) { |
| @@ -711,16 +710,13 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -711,16 +710,13 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 711 | // figuring out whether AES is used or not is complicated | 710 | // figuring out whether AES is used or not is complicated |
| 712 | // with /StmF, /StrF, and /EFF all potentially having | 711 | // with /StmF, /StrF, and /EFF all potentially having |
| 713 | // different values. | 712 | // different values. |
| 714 | - this->m->encrypt_use_aes = true; | 713 | + m->encrypt_use_aes = true; |
| 715 | } | 714 | } |
| 716 | QTC::TC( | 715 | QTC::TC( |
| 717 | "qpdf", | 716 | "qpdf", |
| 718 | "QPDFWriter copy encrypt metadata", | 717 | "QPDFWriter copy encrypt metadata", |
| 719 | - this->m->encrypt_metadata ? 0 : 1); | ||
| 720 | - QTC::TC( | ||
| 721 | - "qpdf", | ||
| 722 | - "QPDFWriter copy use_aes", | ||
| 723 | - this->m->encrypt_use_aes ? 0 : 1); | 718 | + m->encrypt_metadata ? 0 : 1); |
| 719 | + QTC::TC("qpdf", "QPDFWriter copy use_aes", m->encrypt_use_aes ? 0 : 1); | ||
| 724 | std::string OE; | 720 | std::string OE; |
| 725 | std::string UE; | 721 | std::string UE; |
| 726 | std::string Perms; | 722 | std::string Perms; |
| @@ -743,7 +739,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -743,7 +739,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 743 | OE, | 739 | OE, |
| 744 | UE, | 740 | UE, |
| 745 | Perms, | 741 | Perms, |
| 746 | - this->m->id1, // this->m->id1 == the other file's id1 | 742 | + m->id1, // m->id1 == the other file's id1 |
| 747 | qpdf.getPaddedUserPassword(), | 743 | qpdf.getPaddedUserPassword(), |
| 748 | encryption_key); | 744 | encryption_key); |
| 749 | } | 745 | } |
| @@ -753,7 +749,7 @@ void | @@ -753,7 +749,7 @@ void | ||
| 753 | QPDFWriter::disableIncompatibleEncryption( | 749 | QPDFWriter::disableIncompatibleEncryption( |
| 754 | int major, int minor, int extension_level) | 750 | int major, int minor, int extension_level) |
| 755 | { | 751 | { |
| 756 | - if (!this->m->encrypted) { | 752 | + if (!m->encrypted) { |
| 757 | return; | 753 | return; |
| 758 | } | 754 | } |
| 759 | 755 | ||
| @@ -761,10 +757,8 @@ QPDFWriter::disableIncompatibleEncryption( | @@ -761,10 +757,8 @@ QPDFWriter::disableIncompatibleEncryption( | ||
| 761 | if (compareVersions(major, minor, 1, 3) < 0) { | 757 | if (compareVersions(major, minor, 1, 3) < 0) { |
| 762 | disable = true; | 758 | disable = true; |
| 763 | } else { | 759 | } else { |
| 764 | - int V = | ||
| 765 | - QUtil::string_to_int(this->m->encryption_dictionary["/V"].c_str()); | ||
| 766 | - int R = | ||
| 767 | - QUtil::string_to_int(this->m->encryption_dictionary["/R"].c_str()); | 760 | + int V = QUtil::string_to_int(m->encryption_dictionary["/V"].c_str()); |
| 761 | + int R = QUtil::string_to_int(m->encryption_dictionary["/R"].c_str()); | ||
| 768 | if (compareVersions(major, minor, 1, 4) < 0) { | 762 | if (compareVersions(major, minor, 1, 4) < 0) { |
| 769 | if ((V > 1) || (R > 2)) { | 763 | if ((V > 1) || (R > 2)) { |
| 770 | disable = true; | 764 | disable = true; |
| @@ -774,7 +768,7 @@ QPDFWriter::disableIncompatibleEncryption( | @@ -774,7 +768,7 @@ QPDFWriter::disableIncompatibleEncryption( | ||
| 774 | disable = true; | 768 | disable = true; |
| 775 | } | 769 | } |
| 776 | } else if (compareVersions(major, minor, 1, 6) < 0) { | 770 | } else if (compareVersions(major, minor, 1, 6) < 0) { |
| 777 | - if (this->m->encrypt_use_aes) { | 771 | + if (m->encrypt_use_aes) { |
| 778 | disable = true; | 772 | disable = true; |
| 779 | } | 773 | } |
| 780 | } else if ( | 774 | } else if ( |
| @@ -788,7 +782,7 @@ QPDFWriter::disableIncompatibleEncryption( | @@ -788,7 +782,7 @@ QPDFWriter::disableIncompatibleEncryption( | ||
| 788 | } | 782 | } |
| 789 | if (disable) { | 783 | if (disable) { |
| 790 | QTC::TC("qpdf", "QPDFWriter forced version disabled encryption"); | 784 | QTC::TC("qpdf", "QPDFWriter forced version disabled encryption"); |
| 791 | - this->m->encrypted = false; | 785 | + m->encrypted = false; |
| 792 | } | 786 | } |
| 793 | } | 787 | } |
| 794 | 788 | ||
| @@ -844,74 +838,72 @@ QPDFWriter::setEncryptionParametersInternal( | @@ -844,74 +838,72 @@ QPDFWriter::setEncryptionParametersInternal( | ||
| 844 | std::string const& user_password, | 838 | std::string const& user_password, |
| 845 | std::string const& encryption_key) | 839 | std::string const& encryption_key) |
| 846 | { | 840 | { |
| 847 | - this->m->encryption_V = V; | ||
| 848 | - this->m->encryption_R = R; | ||
| 849 | - this->m->encryption_dictionary["/Filter"] = "/Standard"; | ||
| 850 | - this->m->encryption_dictionary["/V"] = std::to_string(V); | ||
| 851 | - this->m->encryption_dictionary["/Length"] = std::to_string(key_len * 8); | ||
| 852 | - this->m->encryption_dictionary["/R"] = std::to_string(R); | ||
| 853 | - this->m->encryption_dictionary["/P"] = std::to_string(P); | ||
| 854 | - this->m->encryption_dictionary["/O"] = QPDF_String(O).unparse(true); | ||
| 855 | - this->m->encryption_dictionary["/U"] = QPDF_String(U).unparse(true); | 841 | + m->encryption_V = V; |
| 842 | + m->encryption_R = R; | ||
| 843 | + m->encryption_dictionary["/Filter"] = "/Standard"; | ||
| 844 | + m->encryption_dictionary["/V"] = std::to_string(V); | ||
| 845 | + m->encryption_dictionary["/Length"] = std::to_string(key_len * 8); | ||
| 846 | + m->encryption_dictionary["/R"] = std::to_string(R); | ||
| 847 | + m->encryption_dictionary["/P"] = std::to_string(P); | ||
| 848 | + m->encryption_dictionary["/O"] = QPDF_String(O).unparse(true); | ||
| 849 | + m->encryption_dictionary["/U"] = QPDF_String(U).unparse(true); | ||
| 856 | if (V >= 5) { | 850 | if (V >= 5) { |
| 857 | - this->m->encryption_dictionary["/OE"] = QPDF_String(OE).unparse(true); | ||
| 858 | - this->m->encryption_dictionary["/UE"] = QPDF_String(UE).unparse(true); | ||
| 859 | - this->m->encryption_dictionary["/Perms"] = | ||
| 860 | - QPDF_String(Perms).unparse(true); | 851 | + m->encryption_dictionary["/OE"] = QPDF_String(OE).unparse(true); |
| 852 | + m->encryption_dictionary["/UE"] = QPDF_String(UE).unparse(true); | ||
| 853 | + m->encryption_dictionary["/Perms"] = QPDF_String(Perms).unparse(true); | ||
| 861 | } | 854 | } |
| 862 | if (R >= 6) { | 855 | if (R >= 6) { |
| 863 | setMinimumPDFVersion("1.7", 8); | 856 | setMinimumPDFVersion("1.7", 8); |
| 864 | } else if (R == 5) { | 857 | } else if (R == 5) { |
| 865 | setMinimumPDFVersion("1.7", 3); | 858 | setMinimumPDFVersion("1.7", 3); |
| 866 | } else if (R == 4) { | 859 | } else if (R == 4) { |
| 867 | - setMinimumPDFVersion(this->m->encrypt_use_aes ? "1.6" : "1.5"); | 860 | + setMinimumPDFVersion(m->encrypt_use_aes ? "1.6" : "1.5"); |
| 868 | } else if (R == 3) { | 861 | } else if (R == 3) { |
| 869 | setMinimumPDFVersion("1.4"); | 862 | setMinimumPDFVersion("1.4"); |
| 870 | } else { | 863 | } else { |
| 871 | setMinimumPDFVersion("1.3"); | 864 | setMinimumPDFVersion("1.3"); |
| 872 | } | 865 | } |
| 873 | 866 | ||
| 874 | - if ((R >= 4) && (!this->m->encrypt_metadata)) { | ||
| 875 | - this->m->encryption_dictionary["/EncryptMetadata"] = "false"; | 867 | + if ((R >= 4) && (!m->encrypt_metadata)) { |
| 868 | + m->encryption_dictionary["/EncryptMetadata"] = "false"; | ||
| 876 | } | 869 | } |
| 877 | if ((V == 4) || (V == 5)) { | 870 | if ((V == 4) || (V == 5)) { |
| 878 | // The spec says the value for the crypt filter key can be | 871 | // The spec says the value for the crypt filter key can be |
| 879 | // anything, and xpdf seems to agree. However, Adobe Reader | 872 | // anything, and xpdf seems to agree. However, Adobe Reader |
| 880 | // won't open our files unless we use /StdCF. | 873 | // won't open our files unless we use /StdCF. |
| 881 | - this->m->encryption_dictionary["/StmF"] = "/StdCF"; | ||
| 882 | - this->m->encryption_dictionary["/StrF"] = "/StdCF"; | 874 | + m->encryption_dictionary["/StmF"] = "/StdCF"; |
| 875 | + m->encryption_dictionary["/StrF"] = "/StdCF"; | ||
| 883 | std::string method = | 876 | std::string method = |
| 884 | - (this->m->encrypt_use_aes ? ((V < 5) ? "/AESV2" : "/AESV3") | ||
| 885 | - : "/V2"); | 877 | + (m->encrypt_use_aes ? ((V < 5) ? "/AESV2" : "/AESV3") : "/V2"); |
| 886 | // The PDF spec says the /Length key is optional, but the PDF | 878 | // The PDF spec says the /Length key is optional, but the PDF |
| 887 | // previewer on some versions of MacOS won't open encrypted | 879 | // previewer on some versions of MacOS won't open encrypted |
| 888 | // files without it. | 880 | // files without it. |
| 889 | - this->m->encryption_dictionary["/CF"] = | 881 | + m->encryption_dictionary["/CF"] = |
| 890 | "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + " /Length " + | 882 | "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + " /Length " + |
| 891 | std::string((V < 5) ? "16" : "32") + " >> >>"; | 883 | std::string((V < 5) ? "16" : "32") + " >> >>"; |
| 892 | } | 884 | } |
| 893 | 885 | ||
| 894 | - this->m->encrypted = true; | 886 | + m->encrypted = true; |
| 895 | QPDF::EncryptionData encryption_data( | 887 | QPDF::EncryptionData encryption_data( |
| 896 | - V, R, key_len, P, O, U, OE, UE, Perms, id1, this->m->encrypt_metadata); | 888 | + V, R, key_len, P, O, U, OE, UE, Perms, id1, m->encrypt_metadata); |
| 897 | if (V < 5) { | 889 | if (V < 5) { |
| 898 | - this->m->encryption_key = | 890 | + m->encryption_key = |
| 899 | QPDF::compute_encryption_key(user_password, encryption_data); | 891 | QPDF::compute_encryption_key(user_password, encryption_data); |
| 900 | } else { | 892 | } else { |
| 901 | - this->m->encryption_key = encryption_key; | 893 | + m->encryption_key = encryption_key; |
| 902 | } | 894 | } |
| 903 | } | 895 | } |
| 904 | 896 | ||
| 905 | void | 897 | void |
| 906 | QPDFWriter::setDataKey(int objid) | 898 | QPDFWriter::setDataKey(int objid) |
| 907 | { | 899 | { |
| 908 | - this->m->cur_data_key = QPDF::compute_data_key( | ||
| 909 | - this->m->encryption_key, | 900 | + m->cur_data_key = QPDF::compute_data_key( |
| 901 | + m->encryption_key, | ||
| 910 | objid, | 902 | objid, |
| 911 | 0, | 903 | 0, |
| 912 | - this->m->encrypt_use_aes, | ||
| 913 | - this->m->encryption_V, | ||
| 914 | - this->m->encryption_R); | 904 | + m->encrypt_use_aes, |
| 905 | + m->encryption_V, | ||
| 906 | + m->encryption_R); | ||
| 915 | } | 907 | } |
| 916 | 908 | ||
| 917 | unsigned int | 909 | unsigned int |
| @@ -937,7 +929,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | @@ -937,7 +929,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | ||
| 937 | data[bytes - i - 1] = static_cast<unsigned char>(val & 0xff); | 929 | data[bytes - i - 1] = static_cast<unsigned char>(val & 0xff); |
| 938 | val >>= 8; | 930 | val >>= 8; |
| 939 | } | 931 | } |
| 940 | - this->m->pipeline->write(data, bytes); | 932 | + m->pipeline->write(data, bytes); |
| 941 | } | 933 | } |
| 942 | 934 | ||
| 943 | void | 935 | void |
| @@ -950,7 +942,7 @@ QPDFWriter::writeString(std::string_view str) | @@ -950,7 +942,7 @@ QPDFWriter::writeString(std::string_view str) | ||
| 950 | void | 942 | void |
| 951 | QPDFWriter::writeBuffer(std::shared_ptr<Buffer>& b) | 943 | QPDFWriter::writeBuffer(std::shared_ptr<Buffer>& b) |
| 952 | { | 944 | { |
| 953 | - this->m->pipeline->write(b->getBuffer(), b->getSize()); | 945 | + m->pipeline->write(b->getBuffer(), b->getSize()); |
| 954 | } | 946 | } |
| 955 | 947 | ||
| 956 | void | 948 | void |
| @@ -981,26 +973,26 @@ Pipeline* | @@ -981,26 +973,26 @@ Pipeline* | ||
| 981 | QPDFWriter::pushPipeline(Pipeline* p) | 973 | QPDFWriter::pushPipeline(Pipeline* p) |
| 982 | { | 974 | { |
| 983 | qpdf_assert_debug(dynamic_cast<Pl_Count*>(p) == nullptr); | 975 | qpdf_assert_debug(dynamic_cast<Pl_Count*>(p) == nullptr); |
| 984 | - this->m->pipeline_stack.push_back(p); | 976 | + m->pipeline_stack.push_back(p); |
| 985 | return p; | 977 | return p; |
| 986 | } | 978 | } |
| 987 | 979 | ||
| 988 | void | 980 | void |
| 989 | QPDFWriter::initializePipelineStack(Pipeline* p) | 981 | QPDFWriter::initializePipelineStack(Pipeline* p) |
| 990 | { | 982 | { |
| 991 | - this->m->pipeline = new Pl_Count("pipeline stack base", p); | ||
| 992 | - this->m->to_delete.push_back(std::shared_ptr<Pipeline>(this->m->pipeline)); | ||
| 993 | - this->m->pipeline_stack.push_back(this->m->pipeline); | 983 | + m->pipeline = new Pl_Count("pipeline stack base", p); |
| 984 | + m->to_delete.push_back(std::shared_ptr<Pipeline>(m->pipeline)); | ||
| 985 | + m->pipeline_stack.push_back(m->pipeline); | ||
| 994 | } | 986 | } |
| 995 | 987 | ||
| 996 | void | 988 | void |
| 997 | QPDFWriter::activatePipelineStack(PipelinePopper& pp) | 989 | QPDFWriter::activatePipelineStack(PipelinePopper& pp) |
| 998 | { | 990 | { |
| 999 | - std::string stack_id("stack " + std::to_string(this->m->next_stack_id)); | ||
| 1000 | - auto* c = new Pl_Count(stack_id.c_str(), this->m->pipeline_stack.back()); | ||
| 1001 | - ++this->m->next_stack_id; | ||
| 1002 | - this->m->pipeline_stack.push_back(c); | ||
| 1003 | - this->m->pipeline = c; | 991 | + std::string stack_id("stack " + std::to_string(m->next_stack_id)); |
| 992 | + auto* c = new Pl_Count(stack_id.c_str(), m->pipeline_stack.back()); | ||
| 993 | + ++m->next_stack_id; | ||
| 994 | + m->pipeline_stack.push_back(c); | ||
| 995 | + m->pipeline = c; | ||
| 1004 | pp.stack_id = stack_id; | 996 | pp.stack_id = stack_id; |
| 1005 | } | 997 | } |
| 1006 | 998 | ||
| @@ -1041,8 +1033,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper() | @@ -1041,8 +1033,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper() | ||
| 1041 | void | 1033 | void |
| 1042 | QPDFWriter::adjustAESStreamLength(size_t& length) | 1034 | QPDFWriter::adjustAESStreamLength(size_t& length) |
| 1043 | { | 1035 | { |
| 1044 | - if (this->m->encrypted && (!this->m->cur_data_key.empty()) && | ||
| 1045 | - this->m->encrypt_use_aes) { | 1036 | + if (m->encrypted && (!m->cur_data_key.empty()) && m->encrypt_use_aes) { |
| 1046 | // Stream length will be padded with 1 to 16 bytes to end up | 1037 | // Stream length will be padded with 1 to 16 bytes to end up |
| 1047 | // as a multiple of 16. It will also be prepended by 16 bits | 1038 | // as a multiple of 16. It will also be prepended by 16 bits |
| 1048 | // of random data. | 1039 | // of random data. |
| @@ -1053,21 +1044,21 @@ QPDFWriter::adjustAESStreamLength(size_t& length) | @@ -1053,21 +1044,21 @@ QPDFWriter::adjustAESStreamLength(size_t& length) | ||
| 1053 | void | 1044 | void |
| 1054 | QPDFWriter::pushEncryptionFilter(PipelinePopper& pp) | 1045 | QPDFWriter::pushEncryptionFilter(PipelinePopper& pp) |
| 1055 | { | 1046 | { |
| 1056 | - if (this->m->encrypted && (!this->m->cur_data_key.empty())) { | 1047 | + if (m->encrypted && (!m->cur_data_key.empty())) { |
| 1057 | Pipeline* p = nullptr; | 1048 | Pipeline* p = nullptr; |
| 1058 | - if (this->m->encrypt_use_aes) { | 1049 | + if (m->encrypt_use_aes) { |
| 1059 | p = new Pl_AES_PDF( | 1050 | p = new Pl_AES_PDF( |
| 1060 | "aes stream encryption", | 1051 | "aes stream encryption", |
| 1061 | - this->m->pipeline, | 1052 | + m->pipeline, |
| 1062 | true, | 1053 | true, |
| 1063 | - QUtil::unsigned_char_pointer(this->m->cur_data_key), | ||
| 1064 | - this->m->cur_data_key.length()); | 1054 | + QUtil::unsigned_char_pointer(m->cur_data_key), |
| 1055 | + m->cur_data_key.length()); | ||
| 1065 | } else { | 1056 | } else { |
| 1066 | p = new Pl_RC4( | 1057 | p = new Pl_RC4( |
| 1067 | "rc4 stream encryption", | 1058 | "rc4 stream encryption", |
| 1068 | - this->m->pipeline, | ||
| 1069 | - QUtil::unsigned_char_pointer(this->m->cur_data_key), | ||
| 1070 | - QIntC::to_int(this->m->cur_data_key.length())); | 1059 | + m->pipeline, |
| 1060 | + QUtil::unsigned_char_pointer(m->cur_data_key), | ||
| 1061 | + QIntC::to_int(m->cur_data_key.length())); | ||
| 1071 | } | 1062 | } |
| 1072 | pushPipeline(p); | 1063 | pushPipeline(p); |
| 1073 | } | 1064 | } |
| @@ -1086,38 +1077,38 @@ QPDFWriter::pushDiscardFilter(PipelinePopper& pp) | @@ -1086,38 +1077,38 @@ QPDFWriter::pushDiscardFilter(PipelinePopper& pp) | ||
| 1086 | void | 1077 | void |
| 1087 | QPDFWriter::pushMD5Pipeline(PipelinePopper& pp) | 1078 | QPDFWriter::pushMD5Pipeline(PipelinePopper& pp) |
| 1088 | { | 1079 | { |
| 1089 | - if (!this->m->id2.empty()) { | 1080 | + if (!m->id2.empty()) { |
| 1090 | // Can't happen in the code | 1081 | // Can't happen in the code |
| 1091 | throw std::logic_error("Deterministic ID computation enabled after ID" | 1082 | throw std::logic_error("Deterministic ID computation enabled after ID" |
| 1092 | " generation has already occurred."); | 1083 | " generation has already occurred."); |
| 1093 | } | 1084 | } |
| 1094 | - qpdf_assert_debug(this->m->deterministic_id); | ||
| 1095 | - qpdf_assert_debug(this->m->md5_pipeline == nullptr); | ||
| 1096 | - qpdf_assert_debug(this->m->pipeline->getCount() == 0); | ||
| 1097 | - this->m->md5_pipeline = new Pl_MD5("qpdf md5", this->m->pipeline); | ||
| 1098 | - this->m->md5_pipeline->persistAcrossFinish(true); | ||
| 1099 | - // Special case code in popPipelineStack clears this->m->md5_pipeline | 1085 | + qpdf_assert_debug(m->deterministic_id); |
| 1086 | + qpdf_assert_debug(m->md5_pipeline == nullptr); | ||
| 1087 | + qpdf_assert_debug(m->pipeline->getCount() == 0); | ||
| 1088 | + m->md5_pipeline = new Pl_MD5("qpdf md5", m->pipeline); | ||
| 1089 | + m->md5_pipeline->persistAcrossFinish(true); | ||
| 1090 | + // Special case code in popPipelineStack clears m->md5_pipeline | ||
| 1100 | // upon deletion. | 1091 | // upon deletion. |
| 1101 | - pushPipeline(this->m->md5_pipeline); | 1092 | + pushPipeline(m->md5_pipeline); |
| 1102 | activatePipelineStack(pp); | 1093 | activatePipelineStack(pp); |
| 1103 | } | 1094 | } |
| 1104 | 1095 | ||
| 1105 | void | 1096 | void |
| 1106 | QPDFWriter::computeDeterministicIDData() | 1097 | QPDFWriter::computeDeterministicIDData() |
| 1107 | { | 1098 | { |
| 1108 | - qpdf_assert_debug(this->m->md5_pipeline != nullptr); | ||
| 1109 | - qpdf_assert_debug(this->m->deterministic_id_data.empty()); | ||
| 1110 | - this->m->deterministic_id_data = this->m->md5_pipeline->getHexDigest(); | ||
| 1111 | - this->m->md5_pipeline->enable(false); | 1099 | + qpdf_assert_debug(m->md5_pipeline != nullptr); |
| 1100 | + qpdf_assert_debug(m->deterministic_id_data.empty()); | ||
| 1101 | + m->deterministic_id_data = m->md5_pipeline->getHexDigest(); | ||
| 1102 | + m->md5_pipeline->enable(false); | ||
| 1112 | } | 1103 | } |
| 1113 | 1104 | ||
| 1114 | int | 1105 | int |
| 1115 | QPDFWriter::openObject(int objid) | 1106 | QPDFWriter::openObject(int objid) |
| 1116 | { | 1107 | { |
| 1117 | if (objid == 0) { | 1108 | if (objid == 0) { |
| 1118 | - objid = this->m->next_objid++; | 1109 | + objid = m->next_objid++; |
| 1119 | } | 1110 | } |
| 1120 | - this->m->xref[objid] = QPDFXRefEntry(m->pipeline->getCount()); | 1111 | + m->xref[objid] = QPDFXRefEntry(m->pipeline->getCount()); |
| 1121 | writeString(std::to_string(objid)); | 1112 | writeString(std::to_string(objid)); |
| 1122 | writeString(" 0 obj\n"); | 1113 | writeString(" 0 obj\n"); |
| 1123 | return objid; | 1114 | return objid; |
| @@ -1130,24 +1121,22 @@ QPDFWriter::closeObject(int objid) | @@ -1130,24 +1121,22 @@ QPDFWriter::closeObject(int objid) | ||
| 1130 | // repair. | 1121 | // repair. |
| 1131 | writeString("\nendobj\n"); | 1122 | writeString("\nendobj\n"); |
| 1132 | writeStringQDF("\n"); | 1123 | writeStringQDF("\n"); |
| 1133 | - this->m->lengths[objid] = | ||
| 1134 | - this->m->pipeline->getCount() - this->m->xref[objid].getOffset(); | 1124 | + m->lengths[objid] = m->pipeline->getCount() - m->xref[objid].getOffset(); |
| 1135 | } | 1125 | } |
| 1136 | 1126 | ||
| 1137 | void | 1127 | void |
| 1138 | QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const& og) | 1128 | QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const& og) |
| 1139 | { | 1129 | { |
| 1140 | int objid = og.getObj(); | 1130 | int objid = og.getObj(); |
| 1141 | - if ((og.getGen() != 0) || | ||
| 1142 | - (this->m->object_stream_to_objects.count(objid) == 0)) { | 1131 | + if ((og.getGen() != 0) || (m->object_stream_to_objects.count(objid) == 0)) { |
| 1143 | // This is not an object stream. | 1132 | // This is not an object stream. |
| 1144 | return; | 1133 | return; |
| 1145 | } | 1134 | } |
| 1146 | 1135 | ||
| 1147 | // Reserve numbers for the objects that belong to this object | 1136 | // Reserve numbers for the objects that belong to this object |
| 1148 | // stream. | 1137 | // stream. |
| 1149 | - for (auto const& iter: this->m->object_stream_to_objects[objid]) { | ||
| 1150 | - this->m->obj_renumber[iter] = this->m->next_objid++; | 1138 | + for (auto const& iter: m->object_stream_to_objects[objid]) { |
| 1139 | + m->obj_renumber[iter] = m->next_objid++; | ||
| 1151 | } | 1140 | } |
| 1152 | } | 1141 | } |
| 1153 | 1142 | ||
| @@ -1161,7 +1150,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1161,7 +1150,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1161 | // file was insert into another file without copying. Doing | 1150 | // file was insert into another file without copying. Doing |
| 1162 | // that is safe even if the original QPDF gets destroyed, | 1151 | // that is safe even if the original QPDF gets destroyed, |
| 1163 | // which just disconnects the QPDFObjectHandle from its owner. | 1152 | // which just disconnects the QPDFObjectHandle from its owner. |
| 1164 | - if (object.getOwningQPDF() != &(this->m->pdf)) { | 1153 | + if (object.getOwningQPDF() != &(m->pdf)) { |
| 1165 | QTC::TC("qpdf", "QPDFWriter foreign object"); | 1154 | QTC::TC("qpdf", "QPDFWriter foreign object"); |
| 1166 | throw std::logic_error( | 1155 | throw std::logic_error( |
| 1167 | "QPDFObjectHandle from different QPDF found while writing." | 1156 | "QPDFObjectHandle from different QPDF found while writing." |
| @@ -1169,7 +1158,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1169,7 +1158,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1169 | " another file."); | 1158 | " another file."); |
| 1170 | } | 1159 | } |
| 1171 | 1160 | ||
| 1172 | - if (this->m->qdf_mode && object.isStreamOfType("/XRef")) { | 1161 | + if (m->qdf_mode && object.isStreamOfType("/XRef")) { |
| 1173 | // As a special case, do not output any extraneous XRef | 1162 | // As a special case, do not output any extraneous XRef |
| 1174 | // streams in QDF mode. Doing so will confuse fix-qdf, | 1163 | // streams in QDF mode. Doing so will confuse fix-qdf, |
| 1175 | // which expects to see only one XRef stream at the end of | 1164 | // which expects to see only one XRef stream at the end of |
| @@ -1183,41 +1172,40 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1183,41 +1172,40 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1183 | 1172 | ||
| 1184 | QPDFObjGen og = object.getObjGen(); | 1173 | QPDFObjGen og = object.getObjGen(); |
| 1185 | 1174 | ||
| 1186 | - if (this->m->obj_renumber.count(og) == 0) { | ||
| 1187 | - if (this->m->object_to_object_stream.count(og)) { | 1175 | + if (m->obj_renumber.count(og) == 0) { |
| 1176 | + if (m->object_to_object_stream.count(og)) { | ||
| 1188 | // This is in an object stream. Don't process it | 1177 | // This is in an object stream. Don't process it |
| 1189 | // here. Instead, enqueue the object stream. Object | 1178 | // here. Instead, enqueue the object stream. Object |
| 1190 | // streams always have generation 0. | 1179 | // streams always have generation 0. |
| 1191 | - int stream_id = this->m->object_to_object_stream[og]; | 1180 | + int stream_id = m->object_to_object_stream[og]; |
| 1192 | // Detect loops by storing invalid object ID 0, which | 1181 | // Detect loops by storing invalid object ID 0, which |
| 1193 | // will get overwritten later. | 1182 | // will get overwritten later. |
| 1194 | - this->m->obj_renumber[og] = 0; | ||
| 1195 | - enqueueObject(this->m->pdf.getObjectByID(stream_id, 0)); | 1183 | + m->obj_renumber[og] = 0; |
| 1184 | + enqueueObject(m->pdf.getObjectByID(stream_id, 0)); | ||
| 1196 | } else { | 1185 | } else { |
| 1197 | - this->m->object_queue.push_back(object); | ||
| 1198 | - this->m->obj_renumber[og] = this->m->next_objid++; | 1186 | + m->object_queue.push_back(object); |
| 1187 | + m->obj_renumber[og] = m->next_objid++; | ||
| 1199 | 1188 | ||
| 1200 | if ((og.getGen() == 0) && | 1189 | if ((og.getGen() == 0) && |
| 1201 | - this->m->object_stream_to_objects.count(og.getObj())) { | 1190 | + m->object_stream_to_objects.count(og.getObj())) { |
| 1202 | // For linearized files, uncompressed objects go | 1191 | // For linearized files, uncompressed objects go |
| 1203 | // at end, and we take care of assigning numbers | 1192 | // at end, and we take care of assigning numbers |
| 1204 | // to them elsewhere. | 1193 | // to them elsewhere. |
| 1205 | - if (!this->m->linearized) { | 1194 | + if (!m->linearized) { |
| 1206 | assignCompressedObjectNumbers(og); | 1195 | assignCompressedObjectNumbers(og); |
| 1207 | } | 1196 | } |
| 1208 | - } else if ( | ||
| 1209 | - (!this->m->direct_stream_lengths) && object.isStream()) { | 1197 | + } else if ((!m->direct_stream_lengths) && object.isStream()) { |
| 1210 | // reserve next object ID for length | 1198 | // reserve next object ID for length |
| 1211 | - ++this->m->next_objid; | 1199 | + ++m->next_objid; |
| 1212 | } | 1200 | } |
| 1213 | } | 1201 | } |
| 1214 | - } else if (this->m->obj_renumber[og] == 0) { | 1202 | + } else if (m->obj_renumber[og] == 0) { |
| 1215 | // This can happen if a specially constructed file | 1203 | // This can happen if a specially constructed file |
| 1216 | // indicates that an object stream is inside itself. | 1204 | // indicates that an object stream is inside itself. |
| 1217 | QTC::TC("qpdf", "QPDFWriter ignore self-referential object stream"); | 1205 | QTC::TC("qpdf", "QPDFWriter ignore self-referential object stream"); |
| 1218 | } | 1206 | } |
| 1219 | return; | 1207 | return; |
| 1220 | - } else if (!this->m->linearized) { | 1208 | + } else if (!m->linearized) { |
| 1221 | if (object.isArray()) { | 1209 | if (object.isArray()) { |
| 1222 | for (auto& item: object.getArrayAsVector()) { | 1210 | for (auto& item: object.getArrayAsVector()) { |
| 1223 | enqueueObject(item); | 1211 | enqueueObject(item); |
| @@ -1237,12 +1225,12 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1237,12 +1225,12 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1237 | void | 1225 | void |
| 1238 | QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) | 1226 | QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) |
| 1239 | { | 1227 | { |
| 1240 | - if (!this->m->linearized) { | 1228 | + if (!m->linearized) { |
| 1241 | enqueueObject(child); | 1229 | enqueueObject(child); |
| 1242 | } | 1230 | } |
| 1243 | if (child.isIndirect()) { | 1231 | if (child.isIndirect()) { |
| 1244 | QPDFObjGen old_og = child.getObjGen(); | 1232 | QPDFObjGen old_og = child.getObjGen(); |
| 1245 | - int new_id = this->m->obj_renumber[old_og]; | 1233 | + int new_id = m->obj_renumber[old_og]; |
| 1246 | writeString(std::to_string(new_id)); | 1234 | writeString(std::to_string(new_id)); |
| 1247 | writeString(" 0 R"); | 1235 | writeString(" 0 R"); |
| 1248 | } else { | 1236 | } else { |
| @@ -1260,7 +1248,7 @@ QPDFWriter::writeTrailer( | @@ -1260,7 +1248,7 @@ QPDFWriter::writeTrailer( | ||
| 1260 | { | 1248 | { |
| 1261 | QPDFObjectHandle trailer = getTrimmedTrailer(); | 1249 | QPDFObjectHandle trailer = getTrimmedTrailer(); |
| 1262 | if (xref_stream) { | 1250 | if (xref_stream) { |
| 1263 | - this->m->cur_data_key.clear(); | 1251 | + m->cur_data_key.clear(); |
| 1264 | } else { | 1252 | } else { |
| 1265 | writeString("trailer <<"); | 1253 | writeString("trailer <<"); |
| 1266 | } | 1254 | } |
| @@ -1278,10 +1266,10 @@ QPDFWriter::writeTrailer( | @@ -1278,10 +1266,10 @@ QPDFWriter::writeTrailer( | ||
| 1278 | writeString(std::to_string(size)); | 1266 | writeString(std::to_string(size)); |
| 1279 | if (which == t_lin_first) { | 1267 | if (which == t_lin_first) { |
| 1280 | writeString(" /Prev "); | 1268 | writeString(" /Prev "); |
| 1281 | - qpdf_offset_t pos = this->m->pipeline->getCount(); | 1269 | + qpdf_offset_t pos = m->pipeline->getCount(); |
| 1282 | writeString(std::to_string(prev)); | 1270 | writeString(std::to_string(prev)); |
| 1283 | - writePad(QIntC::to_size( | ||
| 1284 | - pos - this->m->pipeline->getCount() + 21)); | 1271 | + writePad( |
| 1272 | + QIntC::to_size(pos - m->pipeline->getCount() + 21)); | ||
| 1285 | } | 1273 | } |
| 1286 | } else { | 1274 | } else { |
| 1287 | unparseChild(trailer.getKey(key), 1, 0); | 1275 | unparseChild(trailer.getKey(key), 1, 0); |
| @@ -1313,20 +1301,20 @@ QPDFWriter::writeTrailer( | @@ -1313,20 +1301,20 @@ QPDFWriter::writeTrailer( | ||
| 1313 | } | 1301 | } |
| 1314 | writeString("<00000000000000000000000000000000>"); | 1302 | writeString("<00000000000000000000000000000000>"); |
| 1315 | } else { | 1303 | } else { |
| 1316 | - if ((linearization_pass == 0) && (this->m->deterministic_id)) { | 1304 | + if ((linearization_pass == 0) && (m->deterministic_id)) { |
| 1317 | computeDeterministicIDData(); | 1305 | computeDeterministicIDData(); |
| 1318 | } | 1306 | } |
| 1319 | generateID(); | 1307 | generateID(); |
| 1320 | - writeString(QPDF_String(this->m->id1).unparse(true)); | ||
| 1321 | - writeString(QPDF_String(this->m->id2).unparse(true)); | 1308 | + writeString(QPDF_String(m->id1).unparse(true)); |
| 1309 | + writeString(QPDF_String(m->id2).unparse(true)); | ||
| 1322 | } | 1310 | } |
| 1323 | writeString("]"); | 1311 | writeString("]"); |
| 1324 | 1312 | ||
| 1325 | if (which != t_lin_second) { | 1313 | if (which != t_lin_second) { |
| 1326 | // Write reference to encryption dictionary | 1314 | // Write reference to encryption dictionary |
| 1327 | - if (this->m->encrypted) { | 1315 | + if (m->encrypted) { |
| 1328 | writeString(" /Encrypt "); | 1316 | writeString(" /Encrypt "); |
| 1329 | - writeString(std::to_string(this->m->encryption_dict_objid)); | 1317 | + writeString(std::to_string(m->encryption_dict_objid)); |
| 1330 | writeString(" 0 R"); | 1318 | writeString(" 0 R"); |
| 1331 | } | 1319 | } |
| 1332 | } | 1320 | } |
| @@ -1353,14 +1341,14 @@ QPDFWriter::willFilterStream( | @@ -1353,14 +1341,14 @@ QPDFWriter::willFilterStream( | ||
| 1353 | is_metadata = true; | 1341 | is_metadata = true; |
| 1354 | } | 1342 | } |
| 1355 | bool filter = | 1343 | bool filter = |
| 1356 | - (stream.isDataModified() || this->m->compress_streams || | ||
| 1357 | - this->m->stream_decode_level); | 1344 | + (stream.isDataModified() || m->compress_streams || |
| 1345 | + m->stream_decode_level); | ||
| 1358 | bool filter_on_write = stream.getFilterOnWrite(); | 1346 | bool filter_on_write = stream.getFilterOnWrite(); |
| 1359 | if (!filter_on_write) { | 1347 | if (!filter_on_write) { |
| 1360 | QTC::TC("qpdf", "QPDFWriter getFilterOnWrite false"); | 1348 | QTC::TC("qpdf", "QPDFWriter getFilterOnWrite false"); |
| 1361 | filter = false; | 1349 | filter = false; |
| 1362 | } | 1350 | } |
| 1363 | - if (filter_on_write && this->m->compress_streams) { | 1351 | + if (filter_on_write && m->compress_streams) { |
| 1364 | // Don't filter if the stream is already compressed with | 1352 | // Don't filter if the stream is already compressed with |
| 1365 | // FlateDecode. This way we don't make it worse if the | 1353 | // FlateDecode. This way we don't make it worse if the |
| 1366 | // original file used a better Flate algorithm, and we | 1354 | // original file used a better Flate algorithm, and we |
| @@ -1368,7 +1356,7 @@ QPDFWriter::willFilterStream( | @@ -1368,7 +1356,7 @@ QPDFWriter::willFilterStream( | ||
| 1368 | // recompressing stuff. This can be overridden with | 1356 | // recompressing stuff. This can be overridden with |
| 1369 | // setRecompressFlate(true). | 1357 | // setRecompressFlate(true). |
| 1370 | QPDFObjectHandle filter_obj = stream_dict.getKey("/Filter"); | 1358 | QPDFObjectHandle filter_obj = stream_dict.getKey("/Filter"); |
| 1371 | - if ((!this->m->recompress_flate) && (!stream.isDataModified()) && | 1359 | + if ((!m->recompress_flate) && (!stream.isDataModified()) && |
| 1372 | filter_obj.isName() && | 1360 | filter_obj.isName() && |
| 1373 | ((filter_obj.getName() == "/FlateDecode") || | 1361 | ((filter_obj.getName() == "/FlateDecode") || |
| 1374 | (filter_obj.getName() == "/Fl"))) { | 1362 | (filter_obj.getName() == "/Fl"))) { |
| @@ -1379,17 +1367,17 @@ QPDFWriter::willFilterStream( | @@ -1379,17 +1367,17 @@ QPDFWriter::willFilterStream( | ||
| 1379 | bool normalize = false; | 1367 | bool normalize = false; |
| 1380 | bool uncompress = false; | 1368 | bool uncompress = false; |
| 1381 | if (filter_on_write && is_metadata && | 1369 | if (filter_on_write && is_metadata && |
| 1382 | - ((!this->m->encrypted) || (this->m->encrypt_metadata == false))) { | 1370 | + ((!m->encrypted) || (m->encrypt_metadata == false))) { |
| 1383 | QTC::TC("qpdf", "QPDFWriter not compressing metadata"); | 1371 | QTC::TC("qpdf", "QPDFWriter not compressing metadata"); |
| 1384 | filter = true; | 1372 | filter = true; |
| 1385 | compress_stream = false; | 1373 | compress_stream = false; |
| 1386 | uncompress = true; | 1374 | uncompress = true; |
| 1387 | } else if ( | 1375 | } else if ( |
| 1388 | - filter_on_write && this->m->normalize_content && | ||
| 1389 | - this->m->normalized_streams.count(old_og)) { | 1376 | + filter_on_write && m->normalize_content && |
| 1377 | + m->normalized_streams.count(old_og)) { | ||
| 1390 | normalize = true; | 1378 | normalize = true; |
| 1391 | filter = true; | 1379 | filter = true; |
| 1392 | - } else if (filter_on_write && filter && this->m->compress_streams) { | 1380 | + } else if (filter_on_write && filter && m->compress_streams) { |
| 1393 | compress_stream = true; | 1381 | compress_stream = true; |
| 1394 | QTC::TC("qpdf", "QPDFWriter compressing uncompressed stream"); | 1382 | QTC::TC("qpdf", "QPDFWriter compressing uncompressed stream"); |
| 1395 | } | 1383 | } |
| @@ -1401,12 +1389,11 @@ QPDFWriter::willFilterStream( | @@ -1401,12 +1389,11 @@ QPDFWriter::willFilterStream( | ||
| 1401 | activatePipelineStack(pp_stream_data); | 1389 | activatePipelineStack(pp_stream_data); |
| 1402 | try { | 1390 | try { |
| 1403 | filtered = stream.pipeStreamData( | 1391 | filtered = stream.pipeStreamData( |
| 1404 | - this->m->pipeline, | 1392 | + m->pipeline, |
| 1405 | (((filter && normalize) ? qpdf_ef_normalize : 0) | | 1393 | (((filter && normalize) ? qpdf_ef_normalize : 0) | |
| 1406 | ((filter && compress_stream) ? qpdf_ef_compress : 0)), | 1394 | ((filter && compress_stream) ? qpdf_ef_compress : 0)), |
| 1407 | - (filter | ||
| 1408 | - ? (uncompress ? qpdf_dl_all : this->m->stream_decode_level) | ||
| 1409 | - : qpdf_dl_none), | 1395 | + (filter ? (uncompress ? qpdf_dl_all : m->stream_decode_level) |
| 1396 | + : qpdf_dl_none), | ||
| 1410 | false, | 1397 | false, |
| 1411 | (attempt == 1)); | 1398 | (attempt == 1)); |
| 1412 | } catch (std::runtime_error& e) { | 1399 | } catch (std::runtime_error& e) { |
| @@ -1516,7 +1503,7 @@ QPDFWriter::unparseObject( | @@ -1516,7 +1503,7 @@ QPDFWriter::unparseObject( | ||
| 1516 | } | 1503 | } |
| 1517 | } | 1504 | } |
| 1518 | 1505 | ||
| 1519 | - bool need_extensions_adbe = (this->m->final_extension_level > 0); | 1506 | + bool need_extensions_adbe = (m->final_extension_level > 0); |
| 1520 | 1507 | ||
| 1521 | if (is_root) { | 1508 | if (is_root) { |
| 1522 | if (need_extensions_adbe) { | 1509 | if (need_extensions_adbe) { |
| @@ -1526,7 +1513,7 @@ QPDFWriter::unparseObject( | @@ -1526,7 +1513,7 @@ QPDFWriter::unparseObject( | ||
| 1526 | QTC::TC( | 1513 | QTC::TC( |
| 1527 | "qpdf", | 1514 | "qpdf", |
| 1528 | "QPDFWriter create Extensions", | 1515 | "QPDFWriter create Extensions", |
| 1529 | - this->m->qdf_mode ? 0 : 1); | 1516 | + m->qdf_mode ? 0 : 1); |
| 1530 | extensions = object.replaceKeyAndGetNew( | 1517 | extensions = object.replaceKeyAndGetNew( |
| 1531 | "/Extensions", QPDFObjectHandle::newDictionary()); | 1518 | "/Extensions", QPDFObjectHandle::newDictionary()); |
| 1532 | } | 1519 | } |
| @@ -1545,20 +1532,19 @@ QPDFWriter::unparseObject( | @@ -1545,20 +1532,19 @@ QPDFWriter::unparseObject( | ||
| 1545 | QPDFObjectHandle adbe = extensions.getKey("/ADBE"); | 1532 | QPDFObjectHandle adbe = extensions.getKey("/ADBE"); |
| 1546 | if (adbe.isDictionary() && | 1533 | if (adbe.isDictionary() && |
| 1547 | adbe.getKey("/BaseVersion") | 1534 | adbe.getKey("/BaseVersion") |
| 1548 | - .isNameAndEquals("/" + this->m->final_pdf_version) && | 1535 | + .isNameAndEquals("/" + m->final_pdf_version) && |
| 1549 | adbe.getKey("/ExtensionLevel").isInteger() && | 1536 | adbe.getKey("/ExtensionLevel").isInteger() && |
| 1550 | (adbe.getKey("/ExtensionLevel").getIntValue() == | 1537 | (adbe.getKey("/ExtensionLevel").getIntValue() == |
| 1551 | - this->m->final_extension_level)) { | 1538 | + m->final_extension_level)) { |
| 1552 | QTC::TC("qpdf", "QPDFWriter preserve ADBE"); | 1539 | QTC::TC("qpdf", "QPDFWriter preserve ADBE"); |
| 1553 | } else { | 1540 | } else { |
| 1554 | if (need_extensions_adbe) { | 1541 | if (need_extensions_adbe) { |
| 1555 | extensions.replaceKey( | 1542 | extensions.replaceKey( |
| 1556 | "/ADBE", | 1543 | "/ADBE", |
| 1557 | QPDFObjectHandle::parse( | 1544 | QPDFObjectHandle::parse( |
| 1558 | - "<< /BaseVersion /" + this->m->final_pdf_version + | 1545 | + "<< /BaseVersion /" + m->final_pdf_version + |
| 1559 | " /ExtensionLevel " + | 1546 | " /ExtensionLevel " + |
| 1560 | - std::to_string(this->m->final_extension_level) + | ||
| 1561 | - " >>")); | 1547 | + std::to_string(m->final_extension_level) + " >>")); |
| 1562 | } else { | 1548 | } else { |
| 1563 | QTC::TC("qpdf", "QPDFWriter remove ADBE"); | 1549 | QTC::TC("qpdf", "QPDFWriter remove ADBE"); |
| 1564 | extensions.removeKey("/ADBE"); | 1550 | extensions.removeKey("/ADBE"); |
| @@ -1645,10 +1631,10 @@ QPDFWriter::unparseObject( | @@ -1645,10 +1631,10 @@ QPDFWriter::unparseObject( | ||
| 1645 | writeStringQDF(" "); | 1631 | writeStringQDF(" "); |
| 1646 | writeString("/Length "); | 1632 | writeString("/Length "); |
| 1647 | 1633 | ||
| 1648 | - if (this->m->direct_stream_lengths) { | 1634 | + if (m->direct_stream_lengths) { |
| 1649 | writeString(std::to_string(stream_length)); | 1635 | writeString(std::to_string(stream_length)); |
| 1650 | } else { | 1636 | } else { |
| 1651 | - writeString(std::to_string(this->m->cur_stream_length_id)); | 1637 | + writeString(std::to_string(m->cur_stream_length_id)); |
| 1652 | writeString(" 0 R"); | 1638 | writeString(" 0 R"); |
| 1653 | } | 1639 | } |
| 1654 | if (compress && (flags & f_filtered)) { | 1640 | if (compress && (flags & f_filtered)) { |
| @@ -1662,9 +1648,9 @@ QPDFWriter::unparseObject( | @@ -1662,9 +1648,9 @@ QPDFWriter::unparseObject( | ||
| 1662 | writeString(">>"); | 1648 | writeString(">>"); |
| 1663 | } else if (tc == ::ot_stream) { | 1649 | } else if (tc == ::ot_stream) { |
| 1664 | // Write stream data to a buffer. | 1650 | // Write stream data to a buffer. |
| 1665 | - int new_id = this->m->obj_renumber[old_og]; | ||
| 1666 | - if (!this->m->direct_stream_lengths) { | ||
| 1667 | - this->m->cur_stream_length_id = new_id + 1; | 1651 | + int new_id = m->obj_renumber[old_og]; |
| 1652 | + if (!m->direct_stream_lengths) { | ||
| 1653 | + m->cur_stream_length_id = new_id + 1; | ||
| 1668 | } | 1654 | } |
| 1669 | 1655 | ||
| 1670 | flags |= f_stream; | 1656 | flags |= f_stream; |
| @@ -1677,44 +1663,44 @@ QPDFWriter::unparseObject( | @@ -1677,44 +1663,44 @@ QPDFWriter::unparseObject( | ||
| 1677 | } | 1663 | } |
| 1678 | QPDFObjectHandle stream_dict = object.getDict(); | 1664 | QPDFObjectHandle stream_dict = object.getDict(); |
| 1679 | 1665 | ||
| 1680 | - this->m->cur_stream_length = stream_data->getSize(); | ||
| 1681 | - if (is_metadata && this->m->encrypted && (!this->m->encrypt_metadata)) { | 1666 | + m->cur_stream_length = stream_data->getSize(); |
| 1667 | + if (is_metadata && m->encrypted && (!m->encrypt_metadata)) { | ||
| 1682 | // Don't encrypt stream data for the metadata stream | 1668 | // Don't encrypt stream data for the metadata stream |
| 1683 | - this->m->cur_data_key.clear(); | 1669 | + m->cur_data_key.clear(); |
| 1684 | } | 1670 | } |
| 1685 | - adjustAESStreamLength(this->m->cur_stream_length); | 1671 | + adjustAESStreamLength(m->cur_stream_length); |
| 1686 | unparseObject( | 1672 | unparseObject( |
| 1687 | - stream_dict, 0, flags, this->m->cur_stream_length, compress_stream); | 1673 | + stream_dict, 0, flags, m->cur_stream_length, compress_stream); |
| 1688 | unsigned char last_char = '\0'; | 1674 | unsigned char last_char = '\0'; |
| 1689 | writeString("\nstream\n"); | 1675 | writeString("\nstream\n"); |
| 1690 | { | 1676 | { |
| 1691 | PipelinePopper pp_enc(this); | 1677 | PipelinePopper pp_enc(this); |
| 1692 | pushEncryptionFilter(pp_enc); | 1678 | pushEncryptionFilter(pp_enc); |
| 1693 | writeBuffer(stream_data); | 1679 | writeBuffer(stream_data); |
| 1694 | - last_char = this->m->pipeline->getLastChar(); | 1680 | + last_char = m->pipeline->getLastChar(); |
| 1695 | } | 1681 | } |
| 1696 | 1682 | ||
| 1697 | - if (this->m->newline_before_endstream || | ||
| 1698 | - (this->m->qdf_mode && (last_char != '\n'))) { | 1683 | + if (m->newline_before_endstream || |
| 1684 | + (m->qdf_mode && (last_char != '\n'))) { | ||
| 1699 | writeString("\n"); | 1685 | writeString("\n"); |
| 1700 | - this->m->added_newline = true; | 1686 | + m->added_newline = true; |
| 1701 | } else { | 1687 | } else { |
| 1702 | - this->m->added_newline = false; | 1688 | + m->added_newline = false; |
| 1703 | } | 1689 | } |
| 1704 | writeString("endstream"); | 1690 | writeString("endstream"); |
| 1705 | } else if (tc == ::ot_string) { | 1691 | } else if (tc == ::ot_string) { |
| 1706 | std::string val; | 1692 | std::string val; |
| 1707 | - if (this->m->encrypted && (!(flags & f_in_ostream)) && | ||
| 1708 | - (!(flags & f_no_encryption)) && (!this->m->cur_data_key.empty())) { | 1693 | + if (m->encrypted && (!(flags & f_in_ostream)) && |
| 1694 | + (!(flags & f_no_encryption)) && (!m->cur_data_key.empty())) { | ||
| 1709 | val = object.getStringValue(); | 1695 | val = object.getStringValue(); |
| 1710 | - if (this->m->encrypt_use_aes) { | 1696 | + if (m->encrypt_use_aes) { |
| 1711 | Pl_Buffer bufpl("encrypted string"); | 1697 | Pl_Buffer bufpl("encrypted string"); |
| 1712 | Pl_AES_PDF pl( | 1698 | Pl_AES_PDF pl( |
| 1713 | "aes encrypt string", | 1699 | "aes encrypt string", |
| 1714 | &bufpl, | 1700 | &bufpl, |
| 1715 | true, | 1701 | true, |
| 1716 | - QUtil::unsigned_char_pointer(this->m->cur_data_key), | ||
| 1717 | - this->m->cur_data_key.length()); | 1702 | + QUtil::unsigned_char_pointer(m->cur_data_key), |
| 1703 | + m->cur_data_key.length()); | ||
| 1718 | pl.writeString(val); | 1704 | pl.writeString(val); |
| 1719 | pl.finish(); | 1705 | pl.finish(); |
| 1720 | auto buf = bufpl.getBufferSharedPointer(); | 1706 | auto buf = bufpl.getBufferSharedPointer(); |
| @@ -1727,8 +1713,8 @@ QPDFWriter::unparseObject( | @@ -1727,8 +1713,8 @@ QPDFWriter::unparseObject( | ||
| 1727 | char* tmp = tmp_ph.get(); | 1713 | char* tmp = tmp_ph.get(); |
| 1728 | size_t vlen = val.length(); | 1714 | size_t vlen = val.length(); |
| 1729 | RC4 rc4( | 1715 | RC4 rc4( |
| 1730 | - QUtil::unsigned_char_pointer(this->m->cur_data_key), | ||
| 1731 | - QIntC::to_int(this->m->cur_data_key.length())); | 1716 | + QUtil::unsigned_char_pointer(m->cur_data_key), |
| 1717 | + QIntC::to_int(m->cur_data_key.length())); | ||
| 1732 | auto data = QUtil::unsigned_char_pointer(tmp); | 1718 | auto data = QUtil::unsigned_char_pointer(tmp); |
| 1733 | rc4.process(data, vlen, data); | 1719 | rc4.process(data, vlen, data); |
| 1734 | val = QPDF_String(std::string(tmp, vlen)).unparse(); | 1720 | val = QPDF_String(std::string(tmp, vlen)).unparse(); |
| @@ -1769,7 +1755,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1769,7 +1755,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1769 | QPDFObjGen old_og = object.getObjGen(); | 1755 | QPDFObjGen old_og = object.getObjGen(); |
| 1770 | qpdf_assert_debug(old_og.getGen() == 0); | 1756 | qpdf_assert_debug(old_og.getGen() == 0); |
| 1771 | int old_id = old_og.getObj(); | 1757 | int old_id = old_og.getObj(); |
| 1772 | - int new_id = this->m->obj_renumber[old_og]; | 1758 | + int new_id = m->obj_renumber[old_og]; |
| 1773 | 1759 | ||
| 1774 | std::vector<qpdf_offset_t> offsets; | 1760 | std::vector<qpdf_offset_t> offsets; |
| 1775 | qpdf_offset_t first = 0; | 1761 | qpdf_offset_t first = 0; |
| @@ -1797,14 +1783,14 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1797,14 +1783,14 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1797 | PipelinePopper pp_discard(this); | 1783 | PipelinePopper pp_discard(this); |
| 1798 | pushDiscardFilter(pp_discard); | 1784 | pushDiscardFilter(pp_discard); |
| 1799 | writeObjectStreamOffsets(offsets, first_obj); | 1785 | writeObjectStreamOffsets(offsets, first_obj); |
| 1800 | - first += this->m->pipeline->getCount(); | 1786 | + first += m->pipeline->getCount(); |
| 1801 | } | 1787 | } |
| 1802 | 1788 | ||
| 1803 | // Set up a stream to write the stream data into a buffer. | 1789 | // Set up a stream to write the stream data into a buffer. |
| 1804 | Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); | 1790 | Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); |
| 1805 | - if ((this->m->compress_streams || | ||
| 1806 | - (this->m->stream_decode_level == qpdf_dl_none)) && | ||
| 1807 | - (!this->m->qdf_mode)) { | 1791 | + if ((m->compress_streams || |
| 1792 | + (m->stream_decode_level == qpdf_dl_none)) && | ||
| 1793 | + (!m->qdf_mode)) { | ||
| 1808 | compressed = true; | 1794 | compressed = true; |
| 1809 | next = pushPipeline(new Pl_Flate( | 1795 | next = pushPipeline(new Pl_Flate( |
| 1810 | "compress object stream", next, Pl_Flate::a_deflate)); | 1796 | "compress object stream", next, Pl_Flate::a_deflate)); |
| @@ -1814,17 +1800,17 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1814,17 +1800,17 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1814 | } | 1800 | } |
| 1815 | 1801 | ||
| 1816 | int count = -1; | 1802 | int count = -1; |
| 1817 | - for (auto const& obj: this->m->object_stream_to_objects[old_id]) { | 1803 | + for (auto const& obj: m->object_stream_to_objects[old_id]) { |
| 1818 | ++count; | 1804 | ++count; |
| 1819 | - int new_obj = this->m->obj_renumber[obj]; | 1805 | + int new_obj = m->obj_renumber[obj]; |
| 1820 | if (first_obj == -1) { | 1806 | if (first_obj == -1) { |
| 1821 | first_obj = new_obj; | 1807 | first_obj = new_obj; |
| 1822 | } | 1808 | } |
| 1823 | - if (this->m->qdf_mode) { | 1809 | + if (m->qdf_mode) { |
| 1824 | writeString( | 1810 | writeString( |
| 1825 | "%% Object stream: object " + std::to_string(new_obj) + | 1811 | "%% Object stream: object " + std::to_string(new_obj) + |
| 1826 | ", index " + std::to_string(count)); | 1812 | ", index " + std::to_string(count)); |
| 1827 | - if (!this->m->suppress_original_object_ids) { | 1813 | + if (!m->suppress_original_object_ids) { |
| 1828 | writeString( | 1814 | writeString( |
| 1829 | "; original object ID: " + | 1815 | "; original object ID: " + |
| 1830 | std::to_string(obj.getObj())); | 1816 | std::to_string(obj.getObj())); |
| @@ -1841,13 +1827,13 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1841,13 +1827,13 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1841 | writeString("\n"); | 1827 | writeString("\n"); |
| 1842 | } | 1828 | } |
| 1843 | if (pass == 1) { | 1829 | if (pass == 1) { |
| 1844 | - offsets.push_back(this->m->pipeline->getCount()); | 1830 | + offsets.push_back(m->pipeline->getCount()); |
| 1845 | // To avoid double-counting objects being written in | 1831 | // To avoid double-counting objects being written in |
| 1846 | // object streams for progress reporting, decrement in | 1832 | // object streams for progress reporting, decrement in |
| 1847 | // pass 1. | 1833 | // pass 1. |
| 1848 | indicateProgress(true, false); | 1834 | indicateProgress(true, false); |
| 1849 | } | 1835 | } |
| 1850 | - QPDFObjectHandle obj_to_write = this->m->pdf.getObject(obj); | 1836 | + QPDFObjectHandle obj_to_write = m->pdf.getObject(obj); |
| 1851 | if (obj_to_write.isStream()) { | 1837 | if (obj_to_write.isStream()) { |
| 1852 | // This condition occurred in a fuzz input. Ideally we | 1838 | // This condition occurred in a fuzz input. Ideally we |
| 1853 | // should block it at at parse time, but it's not | 1839 | // should block it at at parse time, but it's not |
| @@ -1859,7 +1845,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1859,7 +1845,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1859 | } | 1845 | } |
| 1860 | writeObject(obj_to_write, count); | 1846 | writeObject(obj_to_write, count); |
| 1861 | 1847 | ||
| 1862 | - this->m->xref[new_obj] = QPDFXRefEntry(new_id, count); | 1848 | + m->xref[new_obj] = QPDFXRefEntry(new_id, count); |
| 1863 | } | 1849 | } |
| 1864 | } | 1850 | } |
| 1865 | 1851 | ||
| @@ -1894,7 +1880,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1894,7 +1880,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1894 | writeStringQDF("\n"); | 1880 | writeStringQDF("\n"); |
| 1895 | writeStringNoQDF(" "); | 1881 | writeStringNoQDF(" "); |
| 1896 | writeString(">>\nstream\n"); | 1882 | writeString(">>\nstream\n"); |
| 1897 | - if (this->m->encrypted) { | 1883 | + if (m->encrypted) { |
| 1898 | QTC::TC("qpdf", "QPDFWriter encrypt object stream"); | 1884 | QTC::TC("qpdf", "QPDFWriter encrypt object stream"); |
| 1899 | } | 1885 | } |
| 1900 | { | 1886 | { |
| @@ -1902,11 +1888,11 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1902,11 +1888,11 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1902 | pushEncryptionFilter(pp_enc); | 1888 | pushEncryptionFilter(pp_enc); |
| 1903 | writeBuffer(stream_buffer); | 1889 | writeBuffer(stream_buffer); |
| 1904 | } | 1890 | } |
| 1905 | - if (this->m->newline_before_endstream) { | 1891 | + if (m->newline_before_endstream) { |
| 1906 | writeString("\n"); | 1892 | writeString("\n"); |
| 1907 | } | 1893 | } |
| 1908 | writeString("endstream"); | 1894 | writeString("endstream"); |
| 1909 | - this->m->cur_data_key.clear(); | 1895 | + m->cur_data_key.clear(); |
| 1910 | closeObject(new_id); | 1896 | closeObject(new_id); |
| 1911 | } | 1897 | } |
| 1912 | 1898 | ||
| @@ -1916,27 +1902,27 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | @@ -1916,27 +1902,27 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | ||
| 1916 | QPDFObjGen old_og = object.getObjGen(); | 1902 | QPDFObjGen old_og = object.getObjGen(); |
| 1917 | 1903 | ||
| 1918 | if ((object_stream_index == -1) && (old_og.getGen() == 0) && | 1904 | if ((object_stream_index == -1) && (old_og.getGen() == 0) && |
| 1919 | - (this->m->object_stream_to_objects.count(old_og.getObj()))) { | 1905 | + (m->object_stream_to_objects.count(old_og.getObj()))) { |
| 1920 | writeObjectStream(object); | 1906 | writeObjectStream(object); |
| 1921 | return; | 1907 | return; |
| 1922 | } | 1908 | } |
| 1923 | 1909 | ||
| 1924 | indicateProgress(false, false); | 1910 | indicateProgress(false, false); |
| 1925 | - int new_id = this->m->obj_renumber[old_og]; | ||
| 1926 | - if (this->m->qdf_mode) { | ||
| 1927 | - if (this->m->page_object_to_seq.count(old_og)) { | 1911 | + int new_id = m->obj_renumber[old_og]; |
| 1912 | + if (m->qdf_mode) { | ||
| 1913 | + if (m->page_object_to_seq.count(old_og)) { | ||
| 1928 | writeString("%% Page "); | 1914 | writeString("%% Page "); |
| 1929 | - writeString(std::to_string(this->m->page_object_to_seq[old_og])); | 1915 | + writeString(std::to_string(m->page_object_to_seq[old_og])); |
| 1930 | writeString("\n"); | 1916 | writeString("\n"); |
| 1931 | } | 1917 | } |
| 1932 | - if (this->m->contents_to_page_seq.count(old_og)) { | 1918 | + if (m->contents_to_page_seq.count(old_og)) { |
| 1933 | writeString("%% Contents for page "); | 1919 | writeString("%% Contents for page "); |
| 1934 | - writeString(std::to_string(this->m->contents_to_page_seq[old_og])); | 1920 | + writeString(std::to_string(m->contents_to_page_seq[old_og])); |
| 1935 | writeString("\n"); | 1921 | writeString("\n"); |
| 1936 | } | 1922 | } |
| 1937 | } | 1923 | } |
| 1938 | if (object_stream_index == -1) { | 1924 | if (object_stream_index == -1) { |
| 1939 | - if (this->m->qdf_mode && (!this->m->suppress_original_object_ids)) { | 1925 | + if (m->qdf_mode && (!m->suppress_original_object_ids)) { |
| 1940 | writeString( | 1926 | writeString( |
| 1941 | "%% Original object ID: " + object.getObjGen().unparse(' ') + | 1927 | "%% Original object ID: " + object.getObjGen().unparse(' ') + |
| 1942 | "\n"); | 1928 | "\n"); |
| @@ -1944,21 +1930,21 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | @@ -1944,21 +1930,21 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | ||
| 1944 | openObject(new_id); | 1930 | openObject(new_id); |
| 1945 | setDataKey(new_id); | 1931 | setDataKey(new_id); |
| 1946 | unparseObject(object, 0, 0); | 1932 | unparseObject(object, 0, 0); |
| 1947 | - this->m->cur_data_key.clear(); | 1933 | + m->cur_data_key.clear(); |
| 1948 | closeObject(new_id); | 1934 | closeObject(new_id); |
| 1949 | } else { | 1935 | } else { |
| 1950 | unparseObject(object, 0, f_in_ostream); | 1936 | unparseObject(object, 0, f_in_ostream); |
| 1951 | writeString("\n"); | 1937 | writeString("\n"); |
| 1952 | } | 1938 | } |
| 1953 | 1939 | ||
| 1954 | - if ((!this->m->direct_stream_lengths) && object.isStream()) { | ||
| 1955 | - if (this->m->qdf_mode) { | ||
| 1956 | - if (this->m->added_newline) { | 1940 | + if ((!m->direct_stream_lengths) && object.isStream()) { |
| 1941 | + if (m->qdf_mode) { | ||
| 1942 | + if (m->added_newline) { | ||
| 1957 | writeString("%QDF: ignore_newline\n"); | 1943 | writeString("%QDF: ignore_newline\n"); |
| 1958 | } | 1944 | } |
| 1959 | } | 1945 | } |
| 1960 | openObject(new_id + 1); | 1946 | openObject(new_id + 1); |
| 1961 | - writeString(std::to_string(this->m->cur_stream_length)); | 1947 | + writeString(std::to_string(m->cur_stream_length)); |
| 1962 | closeObject(new_id + 1); | 1948 | closeObject(new_id + 1); |
| 1963 | } | 1949 | } |
| 1964 | } | 1950 | } |
| @@ -1966,7 +1952,7 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | @@ -1966,7 +1952,7 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | ||
| 1966 | std::string | 1952 | std::string |
| 1967 | QPDFWriter::getOriginalID1() | 1953 | QPDFWriter::getOriginalID1() |
| 1968 | { | 1954 | { |
| 1969 | - QPDFObjectHandle trailer = this->m->pdf.getTrailer(); | 1955 | + QPDFObjectHandle trailer = m->pdf.getTrailer(); |
| 1970 | if (trailer.hasKey("/ID")) { | 1956 | if (trailer.hasKey("/ID")) { |
| 1971 | return trailer.getKey("/ID").getArrayItem(0).getStringValue(); | 1957 | return trailer.getKey("/ID").getArrayItem(0).getStringValue(); |
| 1972 | } else { | 1958 | } else { |
| @@ -1980,15 +1966,15 @@ QPDFWriter::generateID() | @@ -1980,15 +1966,15 @@ QPDFWriter::generateID() | ||
| 1980 | // Generate the ID lazily so that we can handle the user's | 1966 | // Generate the ID lazily so that we can handle the user's |
| 1981 | // preference to use static or deterministic ID generation. | 1967 | // preference to use static or deterministic ID generation. |
| 1982 | 1968 | ||
| 1983 | - if (!this->m->id2.empty()) { | 1969 | + if (!m->id2.empty()) { |
| 1984 | return; | 1970 | return; |
| 1985 | } | 1971 | } |
| 1986 | 1972 | ||
| 1987 | - QPDFObjectHandle trailer = this->m->pdf.getTrailer(); | 1973 | + QPDFObjectHandle trailer = m->pdf.getTrailer(); |
| 1988 | 1974 | ||
| 1989 | std::string result; | 1975 | std::string result; |
| 1990 | 1976 | ||
| 1991 | - if (this->m->static_id) { | 1977 | + if (m->static_id) { |
| 1992 | // For test suite use only... | 1978 | // For test suite use only... |
| 1993 | static unsigned char tmp[] = { | 1979 | static unsigned char tmp[] = { |
| 1994 | 0x31, | 1980 | 0x31, |
| @@ -2024,8 +2010,8 @@ QPDFWriter::generateID() | @@ -2024,8 +2010,8 @@ QPDFWriter::generateID() | ||
| 2024 | // ID regardless of the output file's name. | 2010 | // ID regardless of the output file's name. |
| 2025 | 2011 | ||
| 2026 | std::string seed; | 2012 | std::string seed; |
| 2027 | - if (this->m->deterministic_id) { | ||
| 2028 | - if (this->m->deterministic_id_data.empty()) { | 2013 | + if (m->deterministic_id) { |
| 2014 | + if (m->deterministic_id_data.empty()) { | ||
| 2029 | QTC::TC("qpdf", "QPDFWriter deterministic with no data"); | 2015 | QTC::TC("qpdf", "QPDFWriter deterministic with no data"); |
| 2030 | throw std::logic_error( | 2016 | throw std::logic_error( |
| 2031 | "INTERNAL ERROR: QPDFWriter::generateID has no" | 2017 | "INTERNAL ERROR: QPDFWriter::generateID has no" |
| @@ -2033,10 +2019,10 @@ QPDFWriter::generateID() | @@ -2033,10 +2019,10 @@ QPDFWriter::generateID() | ||
| 2033 | " deterministic ID and file encryption are requested" | 2019 | " deterministic ID and file encryption are requested" |
| 2034 | " together."); | 2020 | " together."); |
| 2035 | } | 2021 | } |
| 2036 | - seed += this->m->deterministic_id_data; | 2022 | + seed += m->deterministic_id_data; |
| 2037 | } else { | 2023 | } else { |
| 2038 | seed += std::to_string(QUtil::get_current_time()); | 2024 | seed += std::to_string(QUtil::get_current_time()); |
| 2039 | - seed += this->m->filename; | 2025 | + seed += m->filename; |
| 2040 | seed += " "; | 2026 | seed += " "; |
| 2041 | } | 2027 | } |
| 2042 | seed += " QPDF "; | 2028 | seed += " QPDF "; |
| @@ -2063,11 +2049,11 @@ QPDFWriter::generateID() | @@ -2063,11 +2049,11 @@ QPDFWriter::generateID() | ||
| 2063 | // word and generate a new second word. Otherwise, we'll use the | 2049 | // word and generate a new second word. Otherwise, we'll use the |
| 2064 | // generated ID for both. | 2050 | // generated ID for both. |
| 2065 | 2051 | ||
| 2066 | - this->m->id2 = result; | 2052 | + m->id2 = result; |
| 2067 | // Note: keep /ID from old file even if --static-id was given. | 2053 | // Note: keep /ID from old file even if --static-id was given. |
| 2068 | - this->m->id1 = getOriginalID1(); | ||
| 2069 | - if (this->m->id1.empty()) { | ||
| 2070 | - this->m->id1 = this->m->id2; | 2054 | + m->id1 = getOriginalID1(); |
| 2055 | + if (m->id1.empty()) { | ||
| 2056 | + m->id1 = m->id2; | ||
| 2071 | } | 2057 | } |
| 2072 | } | 2058 | } |
| 2073 | 2059 | ||
| @@ -2076,10 +2062,10 @@ QPDFWriter::initializeSpecialStreams() | @@ -2076,10 +2062,10 @@ QPDFWriter::initializeSpecialStreams() | ||
| 2076 | { | 2062 | { |
| 2077 | // Mark all page content streams in case we are filtering or | 2063 | // Mark all page content streams in case we are filtering or |
| 2078 | // normalizing. | 2064 | // normalizing. |
| 2079 | - std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); | 2065 | + std::vector<QPDFObjectHandle> pages = m->pdf.getAllPages(); |
| 2080 | int num = 0; | 2066 | int num = 0; |
| 2081 | for (auto& page: pages) { | 2067 | for (auto& page: pages) { |
| 2082 | - this->m->page_object_to_seq[page.getObjGen()] = ++num; | 2068 | + m->page_object_to_seq[page.getObjGen()] = ++num; |
| 2083 | QPDFObjectHandle contents = page.getKey("/Contents"); | 2069 | QPDFObjectHandle contents = page.getKey("/Contents"); |
| 2084 | std::vector<QPDFObjGen> contents_objects; | 2070 | std::vector<QPDFObjGen> contents_objects; |
| 2085 | if (contents.isArray()) { | 2071 | if (contents.isArray()) { |
| @@ -2093,8 +2079,8 @@ QPDFWriter::initializeSpecialStreams() | @@ -2093,8 +2079,8 @@ QPDFWriter::initializeSpecialStreams() | ||
| 2093 | } | 2079 | } |
| 2094 | 2080 | ||
| 2095 | for (auto const& c: contents_objects) { | 2081 | for (auto const& c: contents_objects) { |
| 2096 | - this->m->contents_to_page_seq[c] = num; | ||
| 2097 | - this->m->normalized_streams.insert(c); | 2082 | + m->contents_to_page_seq[c] = num; |
| 2083 | + m->normalized_streams.insert(c); | ||
| 2098 | } | 2084 | } |
| 2099 | } | 2085 | } |
| 2100 | } | 2086 | } |
| @@ -2103,7 +2089,7 @@ void | @@ -2103,7 +2089,7 @@ void | ||
| 2103 | QPDFWriter::preserveObjectStreams() | 2089 | QPDFWriter::preserveObjectStreams() |
| 2104 | { | 2090 | { |
| 2105 | std::map<int, int> omap; | 2091 | std::map<int, int> omap; |
| 2106 | - QPDF::Writer::getObjectStreamData(this->m->pdf, omap); | 2092 | + QPDF::Writer::getObjectStreamData(m->pdf, omap); |
| 2107 | if (omap.empty()) { | 2093 | if (omap.empty()) { |
| 2108 | return; | 2094 | return; |
| 2109 | } | 2095 | } |
| @@ -2118,19 +2104,19 @@ QPDFWriter::preserveObjectStreams() | @@ -2118,19 +2104,19 @@ QPDFWriter::preserveObjectStreams() | ||
| 2118 | // source PDF, it also prevents unreferenced objects from being | 2104 | // source PDF, it also prevents unreferenced objects from being |
| 2119 | // included. | 2105 | // included. |
| 2120 | std::set<QPDFObjGen> eligible; | 2106 | std::set<QPDFObjGen> eligible; |
| 2121 | - if (!this->m->preserve_unreferenced_objects) { | 2107 | + if (!m->preserve_unreferenced_objects) { |
| 2122 | std::vector<QPDFObjGen> eligible_v = | 2108 | std::vector<QPDFObjGen> eligible_v = |
| 2123 | - QPDF::Writer::getCompressibleObjGens(this->m->pdf); | 2109 | + QPDF::Writer::getCompressibleObjGens(m->pdf); |
| 2124 | eligible = std::set<QPDFObjGen>(eligible_v.begin(), eligible_v.end()); | 2110 | eligible = std::set<QPDFObjGen>(eligible_v.begin(), eligible_v.end()); |
| 2125 | } | 2111 | } |
| 2126 | QTC::TC( | 2112 | QTC::TC( |
| 2127 | "qpdf", | 2113 | "qpdf", |
| 2128 | "QPDFWriter preserve object streams", | 2114 | "QPDFWriter preserve object streams", |
| 2129 | - this->m->preserve_unreferenced_objects ? 0 : 1); | 2115 | + m->preserve_unreferenced_objects ? 0 : 1); |
| 2130 | for (auto iter: omap) { | 2116 | for (auto iter: omap) { |
| 2131 | QPDFObjGen og(iter.first, 0); | 2117 | QPDFObjGen og(iter.first, 0); |
| 2132 | - if (eligible.count(og) || this->m->preserve_unreferenced_objects) { | ||
| 2133 | - this->m->object_to_object_stream[og] = iter.second; | 2118 | + if (eligible.count(og) || m->preserve_unreferenced_objects) { |
| 2119 | + m->object_to_object_stream[og] = iter.second; | ||
| 2134 | } else { | 2120 | } else { |
| 2135 | QTC::TC("qpdf", "QPDFWriter exclude from object stream"); | 2121 | QTC::TC("qpdf", "QPDFWriter exclude from object stream"); |
| 2136 | } | 2122 | } |
| @@ -2151,7 +2137,7 @@ QPDFWriter::generateObjectStreams() | @@ -2151,7 +2137,7 @@ QPDFWriter::generateObjectStreams() | ||
| 2151 | // This code doesn't do anything with /Extends. | 2137 | // This code doesn't do anything with /Extends. |
| 2152 | 2138 | ||
| 2153 | std::vector<QPDFObjGen> eligible = | 2139 | std::vector<QPDFObjGen> eligible = |
| 2154 | - QPDF::Writer::getCompressibleObjGens(this->m->pdf); | 2140 | + QPDF::Writer::getCompressibleObjGens(m->pdf); |
| 2155 | size_t n_object_streams = (eligible.size() + 99U) / 100U; | 2141 | size_t n_object_streams = (eligible.size() + 99U) / 100U; |
| 2156 | if (n_object_streams == 0) { | 2142 | if (n_object_streams == 0) { |
| 2157 | return; | 2143 | return; |
| @@ -2173,11 +2159,10 @@ QPDFWriter::generateObjectStreams() | @@ -2173,11 +2159,10 @@ QPDFWriter::generateObjectStreams() | ||
| 2173 | // Construct a new null object as the "original" object | 2159 | // Construct a new null object as the "original" object |
| 2174 | // stream. The rest of the code knows that this means | 2160 | // stream. The rest of the code knows that this means |
| 2175 | // we're creating the object stream from scratch. | 2161 | // we're creating the object stream from scratch. |
| 2176 | - cur_ostream = | ||
| 2177 | - this->m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()) | ||
| 2178 | - .getObjectID(); | 2162 | + cur_ostream = m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()) |
| 2163 | + .getObjectID(); | ||
| 2179 | } | 2164 | } |
| 2180 | - this->m->object_to_object_stream[iter] = cur_ostream; | 2165 | + m->object_to_object_stream[iter] = cur_ostream; |
| 2181 | ++n; | 2166 | ++n; |
| 2182 | } | 2167 | } |
| 2183 | } | 2168 | } |
| @@ -2188,7 +2173,7 @@ QPDFWriter::getTrimmedTrailer() | @@ -2188,7 +2173,7 @@ QPDFWriter::getTrimmedTrailer() | ||
| 2188 | // Remove keys from the trailer that necessarily have to be | 2173 | // Remove keys from the trailer that necessarily have to be |
| 2189 | // replaced when writing the file. | 2174 | // replaced when writing the file. |
| 2190 | 2175 | ||
| 2191 | - QPDFObjectHandle trailer = this->m->pdf.getTrailer().unsafeShallowCopy(); | 2176 | + QPDFObjectHandle trailer = m->pdf.getTrailer().unsafeShallowCopy(); |
| 2192 | 2177 | ||
| 2193 | // Remove encryption keys | 2178 | // Remove encryption keys |
| 2194 | trailer.removeKey("/ID"); | 2179 | trailer.removeKey("/ID"); |
| @@ -2216,8 +2201,8 @@ QPDFWriter::prepareFileForWrite() | @@ -2216,8 +2201,8 @@ QPDFWriter::prepareFileForWrite() | ||
| 2216 | // Make document extension level information direct as required by | 2201 | // Make document extension level information direct as required by |
| 2217 | // the spec. | 2202 | // the spec. |
| 2218 | 2203 | ||
| 2219 | - this->m->pdf.fixDanglingReferences(); | ||
| 2220 | - QPDFObjectHandle root = this->m->pdf.getRoot(); | 2204 | + m->pdf.fixDanglingReferences(); |
| 2205 | + QPDFObjectHandle root = m->pdf.getRoot(); | ||
| 2221 | for (auto const& key: root.getKeys()) { | 2206 | for (auto const& key: root.getKeys()) { |
| 2222 | QPDFObjectHandle oh = root.getKey(key); | 2207 | QPDFObjectHandle oh = root.getKey(key); |
| 2223 | if ((key == "/Extensions") && (oh.isDictionary())) { | 2208 | if ((key == "/Extensions") && (oh.isDictionary())) { |
| @@ -2245,76 +2230,74 @@ QPDFWriter::prepareFileForWrite() | @@ -2245,76 +2230,74 @@ QPDFWriter::prepareFileForWrite() | ||
| 2245 | void | 2230 | void |
| 2246 | QPDFWriter::doWriteSetup() | 2231 | QPDFWriter::doWriteSetup() |
| 2247 | { | 2232 | { |
| 2248 | - if (this->m->did_write_setup) { | 2233 | + if (m->did_write_setup) { |
| 2249 | return; | 2234 | return; |
| 2250 | } | 2235 | } |
| 2251 | - this->m->did_write_setup = true; | 2236 | + m->did_write_setup = true; |
| 2252 | 2237 | ||
| 2253 | // Do preliminary setup | 2238 | // Do preliminary setup |
| 2254 | 2239 | ||
| 2255 | - if (this->m->linearized) { | ||
| 2256 | - this->m->qdf_mode = false; | 2240 | + if (m->linearized) { |
| 2241 | + m->qdf_mode = false; | ||
| 2257 | } | 2242 | } |
| 2258 | 2243 | ||
| 2259 | - if (this->m->pclm) { | ||
| 2260 | - this->m->stream_decode_level = qpdf_dl_none; | ||
| 2261 | - this->m->compress_streams = false; | ||
| 2262 | - this->m->encrypted = false; | 2244 | + if (m->pclm) { |
| 2245 | + m->stream_decode_level = qpdf_dl_none; | ||
| 2246 | + m->compress_streams = false; | ||
| 2247 | + m->encrypted = false; | ||
| 2263 | } | 2248 | } |
| 2264 | 2249 | ||
| 2265 | - if (this->m->qdf_mode) { | ||
| 2266 | - if (!this->m->normalize_content_set) { | ||
| 2267 | - this->m->normalize_content = true; | 2250 | + if (m->qdf_mode) { |
| 2251 | + if (!m->normalize_content_set) { | ||
| 2252 | + m->normalize_content = true; | ||
| 2268 | } | 2253 | } |
| 2269 | - if (!this->m->compress_streams_set) { | ||
| 2270 | - this->m->compress_streams = false; | 2254 | + if (!m->compress_streams_set) { |
| 2255 | + m->compress_streams = false; | ||
| 2271 | } | 2256 | } |
| 2272 | - if (!this->m->stream_decode_level_set) { | ||
| 2273 | - this->m->stream_decode_level = qpdf_dl_generalized; | 2257 | + if (!m->stream_decode_level_set) { |
| 2258 | + m->stream_decode_level = qpdf_dl_generalized; | ||
| 2274 | } | 2259 | } |
| 2275 | } | 2260 | } |
| 2276 | 2261 | ||
| 2277 | - if (this->m->encrypted) { | 2262 | + if (m->encrypted) { |
| 2278 | // Encryption has been explicitly set | 2263 | // Encryption has been explicitly set |
| 2279 | - this->m->preserve_encryption = false; | 2264 | + m->preserve_encryption = false; |
| 2280 | } else if ( | 2265 | } else if ( |
| 2281 | - this->m->normalize_content || this->m->stream_decode_level || | ||
| 2282 | - this->m->pclm || this->m->qdf_mode) { | 2266 | + m->normalize_content || m->stream_decode_level || m->pclm || |
| 2267 | + m->qdf_mode) { | ||
| 2283 | // Encryption makes looking at contents pretty useless. If | 2268 | // Encryption makes looking at contents pretty useless. If |
| 2284 | // the user explicitly encrypted though, we still obey that. | 2269 | // the user explicitly encrypted though, we still obey that. |
| 2285 | - this->m->preserve_encryption = false; | 2270 | + m->preserve_encryption = false; |
| 2286 | } | 2271 | } |
| 2287 | 2272 | ||
| 2288 | - if (this->m->preserve_encryption) { | ||
| 2289 | - copyEncryptionParameters(this->m->pdf); | 2273 | + if (m->preserve_encryption) { |
| 2274 | + copyEncryptionParameters(m->pdf); | ||
| 2290 | } | 2275 | } |
| 2291 | 2276 | ||
| 2292 | - if (!this->m->forced_pdf_version.empty()) { | 2277 | + if (!m->forced_pdf_version.empty()) { |
| 2293 | int major = 0; | 2278 | int major = 0; |
| 2294 | int minor = 0; | 2279 | int minor = 0; |
| 2295 | - parseVersion(this->m->forced_pdf_version, major, minor); | ||
| 2296 | - disableIncompatibleEncryption( | ||
| 2297 | - major, minor, this->m->forced_extension_level); | 2280 | + parseVersion(m->forced_pdf_version, major, minor); |
| 2281 | + disableIncompatibleEncryption(major, minor, m->forced_extension_level); | ||
| 2298 | if (compareVersions(major, minor, 1, 5) < 0) { | 2282 | if (compareVersions(major, minor, 1, 5) < 0) { |
| 2299 | QTC::TC("qpdf", "QPDFWriter forcing object stream disable"); | 2283 | QTC::TC("qpdf", "QPDFWriter forcing object stream disable"); |
| 2300 | - this->m->object_stream_mode = qpdf_o_disable; | 2284 | + m->object_stream_mode = qpdf_o_disable; |
| 2301 | } | 2285 | } |
| 2302 | } | 2286 | } |
| 2303 | 2287 | ||
| 2304 | - if (this->m->qdf_mode || this->m->normalize_content || | ||
| 2305 | - this->m->stream_decode_level) { | 2288 | + if (m->qdf_mode || m->normalize_content || m->stream_decode_level) { |
| 2306 | initializeSpecialStreams(); | 2289 | initializeSpecialStreams(); |
| 2307 | } | 2290 | } |
| 2308 | 2291 | ||
| 2309 | - if (this->m->qdf_mode) { | 2292 | + if (m->qdf_mode) { |
| 2310 | // Generate indirect stream lengths for qdf mode since fix-qdf | 2293 | // Generate indirect stream lengths for qdf mode since fix-qdf |
| 2311 | // uses them for storing recomputed stream length data. | 2294 | // uses them for storing recomputed stream length data. |
| 2312 | // Certain streams such as object streams, xref streams, and | 2295 | // Certain streams such as object streams, xref streams, and |
| 2313 | // hint streams always get direct stream lengths. | 2296 | // hint streams always get direct stream lengths. |
| 2314 | - this->m->direct_stream_lengths = false; | 2297 | + m->direct_stream_lengths = false; |
| 2315 | } | 2298 | } |
| 2316 | 2299 | ||
| 2317 | - switch (this->m->object_stream_mode) { | 2300 | + switch (m->object_stream_mode) { |
| 2318 | case qpdf_o_disable: | 2301 | case qpdf_o_disable: |
| 2319 | // no action required | 2302 | // no action required |
| 2320 | break; | 2303 | break; |
| @@ -2330,18 +2313,18 @@ QPDFWriter::doWriteSetup() | @@ -2330,18 +2313,18 @@ QPDFWriter::doWriteSetup() | ||
| 2330 | // no default so gcc will warn for missing case tag | 2313 | // no default so gcc will warn for missing case tag |
| 2331 | } | 2314 | } |
| 2332 | 2315 | ||
| 2333 | - if (this->m->linearized) { | 2316 | + if (m->linearized) { |
| 2334 | // Page dictionaries are not allowed to be compressed objects. | 2317 | // Page dictionaries are not allowed to be compressed objects. |
| 2335 | - for (auto& page: this->m->pdf.getAllPages()) { | 2318 | + for (auto& page: m->pdf.getAllPages()) { |
| 2336 | QPDFObjGen og = page.getObjGen(); | 2319 | QPDFObjGen og = page.getObjGen(); |
| 2337 | - if (this->m->object_to_object_stream.count(og)) { | 2320 | + if (m->object_to_object_stream.count(og)) { |
| 2338 | QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary"); | 2321 | QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary"); |
| 2339 | - this->m->object_to_object_stream.erase(og); | 2322 | + m->object_to_object_stream.erase(og); |
| 2340 | } | 2323 | } |
| 2341 | } | 2324 | } |
| 2342 | } | 2325 | } |
| 2343 | 2326 | ||
| 2344 | - if (this->m->linearized || this->m->encrypted) { | 2327 | + if (m->linearized || m->encrypted) { |
| 2345 | // The document catalog is not allowed to be compressed in | 2328 | // The document catalog is not allowed to be compressed in |
| 2346 | // linearized files either. It also appears that Adobe Reader | 2329 | // linearized files either. It also appears that Adobe Reader |
| 2347 | // 8.0.0 has a bug that prevents it from being able to handle | 2330 | // 8.0.0 has a bug that prevents it from being able to handle |
| @@ -2349,33 +2332,31 @@ QPDFWriter::doWriteSetup() | @@ -2349,33 +2332,31 @@ QPDFWriter::doWriteSetup() | ||
| 2349 | // disable them in that case as well. | 2332 | // disable them in that case as well. |
| 2350 | if (m->object_to_object_stream.count(m->root_og)) { | 2333 | if (m->object_to_object_stream.count(m->root_og)) { |
| 2351 | QTC::TC("qpdf", "QPDFWriter uncompressing root"); | 2334 | QTC::TC("qpdf", "QPDFWriter uncompressing root"); |
| 2352 | - this->m->object_to_object_stream.erase(m->root_og); | 2335 | + m->object_to_object_stream.erase(m->root_og); |
| 2353 | } | 2336 | } |
| 2354 | } | 2337 | } |
| 2355 | 2338 | ||
| 2356 | // Generate reverse mapping from object stream to objects | 2339 | // Generate reverse mapping from object stream to objects |
| 2357 | - for (auto const& iter: this->m->object_to_object_stream) { | 2340 | + for (auto const& iter: m->object_to_object_stream) { |
| 2358 | QPDFObjGen const& obj = iter.first; | 2341 | QPDFObjGen const& obj = iter.first; |
| 2359 | int stream = iter.second; | 2342 | int stream = iter.second; |
| 2360 | - this->m->object_stream_to_objects[stream].insert(obj); | ||
| 2361 | - this->m->max_ostream_index = std::max( | ||
| 2362 | - this->m->max_ostream_index, | ||
| 2363 | - QIntC::to_int(this->m->object_stream_to_objects[stream].size()) - | ||
| 2364 | - 1); | 2343 | + m->object_stream_to_objects[stream].insert(obj); |
| 2344 | + m->max_ostream_index = std::max( | ||
| 2345 | + m->max_ostream_index, | ||
| 2346 | + QIntC::to_int(m->object_stream_to_objects[stream].size()) - 1); | ||
| 2365 | } | 2347 | } |
| 2366 | 2348 | ||
| 2367 | - if (!this->m->object_stream_to_objects.empty()) { | 2349 | + if (!m->object_stream_to_objects.empty()) { |
| 2368 | setMinimumPDFVersion("1.5"); | 2350 | setMinimumPDFVersion("1.5"); |
| 2369 | } | 2351 | } |
| 2370 | 2352 | ||
| 2371 | - setMinimumPDFVersion( | ||
| 2372 | - this->m->pdf.getPDFVersion(), this->m->pdf.getExtensionLevel()); | ||
| 2373 | - this->m->final_pdf_version = this->m->min_pdf_version; | ||
| 2374 | - this->m->final_extension_level = this->m->min_extension_level; | ||
| 2375 | - if (!this->m->forced_pdf_version.empty()) { | 2353 | + setMinimumPDFVersion(m->pdf.getPDFVersion(), m->pdf.getExtensionLevel()); |
| 2354 | + m->final_pdf_version = m->min_pdf_version; | ||
| 2355 | + m->final_extension_level = m->min_extension_level; | ||
| 2356 | + if (!m->forced_pdf_version.empty()) { | ||
| 2376 | QTC::TC("qpdf", "QPDFWriter using forced PDF version"); | 2357 | QTC::TC("qpdf", "QPDFWriter using forced PDF version"); |
| 2377 | - this->m->final_pdf_version = this->m->forced_pdf_version; | ||
| 2378 | - this->m->final_extension_level = this->m->forced_extension_level; | 2358 | + m->final_pdf_version = m->forced_pdf_version; |
| 2359 | + m->final_extension_level = m->forced_extension_level; | ||
| 2379 | } | 2360 | } |
| 2380 | } | 2361 | } |
| 2381 | 2362 | ||
| @@ -2387,25 +2368,25 @@ QPDFWriter::write() | @@ -2387,25 +2368,25 @@ QPDFWriter::write() | ||
| 2387 | // Set up progress reporting. For linearized files, we write two | 2368 | // Set up progress reporting. For linearized files, we write two |
| 2388 | // passes. events_expected is an approximation, but it's good | 2369 | // passes. events_expected is an approximation, but it's good |
| 2389 | // enough for progress reporting, which is mostly a guess anyway. | 2370 | // enough for progress reporting, which is mostly a guess anyway. |
| 2390 | - this->m->events_expected = QIntC::to_int( | ||
| 2391 | - this->m->pdf.getObjectCount() * (this->m->linearized ? 2 : 1)); | 2371 | + m->events_expected = |
| 2372 | + QIntC::to_int(m->pdf.getObjectCount() * (m->linearized ? 2 : 1)); | ||
| 2392 | 2373 | ||
| 2393 | prepareFileForWrite(); | 2374 | prepareFileForWrite(); |
| 2394 | 2375 | ||
| 2395 | - if (this->m->linearized) { | 2376 | + if (m->linearized) { |
| 2396 | writeLinearized(); | 2377 | writeLinearized(); |
| 2397 | } else { | 2378 | } else { |
| 2398 | writeStandard(); | 2379 | writeStandard(); |
| 2399 | } | 2380 | } |
| 2400 | 2381 | ||
| 2401 | - this->m->pipeline->finish(); | ||
| 2402 | - if (this->m->close_file) { | ||
| 2403 | - fclose(this->m->file); | 2382 | + m->pipeline->finish(); |
| 2383 | + if (m->close_file) { | ||
| 2384 | + fclose(m->file); | ||
| 2404 | } | 2385 | } |
| 2405 | - this->m->file = nullptr; | ||
| 2406 | - if (this->m->buffer_pipeline) { | ||
| 2407 | - this->m->output_buffer = this->m->buffer_pipeline->getBuffer(); | ||
| 2408 | - this->m->buffer_pipeline = nullptr; | 2386 | + m->file = nullptr; |
| 2387 | + if (m->buffer_pipeline) { | ||
| 2388 | + m->output_buffer = m->buffer_pipeline->getBuffer(); | ||
| 2389 | + m->buffer_pipeline = nullptr; | ||
| 2409 | } | 2390 | } |
| 2410 | indicateProgress(false, true); | 2391 | indicateProgress(false, true); |
| 2411 | } | 2392 | } |
| @@ -2413,7 +2394,7 @@ QPDFWriter::write() | @@ -2413,7 +2394,7 @@ QPDFWriter::write() | ||
| 2413 | QPDFObjGen | 2394 | QPDFObjGen |
| 2414 | QPDFWriter::getRenumberedObjGen(QPDFObjGen og) | 2395 | QPDFWriter::getRenumberedObjGen(QPDFObjGen og) |
| 2415 | { | 2396 | { |
| 2416 | - return QPDFObjGen(this->m->obj_renumber[og], 0); | 2397 | + return QPDFObjGen(m->obj_renumber[og], 0); |
| 2417 | } | 2398 | } |
| 2418 | 2399 | ||
| 2419 | std::map<QPDFObjGen, QPDFXRefEntry> | 2400 | std::map<QPDFObjGen, QPDFXRefEntry> |
| @@ -2421,7 +2402,7 @@ QPDFWriter::getWrittenXRefTable() | @@ -2421,7 +2402,7 @@ QPDFWriter::getWrittenXRefTable() | ||
| 2421 | { | 2402 | { |
| 2422 | std::map<QPDFObjGen, QPDFXRefEntry> result; | 2403 | std::map<QPDFObjGen, QPDFXRefEntry> result; |
| 2423 | 2404 | ||
| 2424 | - for (auto const& iter: this->m->xref) { | 2405 | + for (auto const& iter: m->xref) { |
| 2425 | if (iter.first != 0 && iter.second.getType() != 0) { | 2406 | if (iter.first != 0 && iter.second.getType() != 0) { |
| 2426 | result[QPDFObjGen(iter.first, 0)] = iter.second; | 2407 | result[QPDFObjGen(iter.first, 0)] = iter.second; |
| 2427 | } | 2408 | } |
| @@ -2441,31 +2422,31 @@ QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part) | @@ -2441,31 +2422,31 @@ QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part) | ||
| 2441 | void | 2422 | void |
| 2442 | QPDFWriter::writeEncryptionDictionary() | 2423 | QPDFWriter::writeEncryptionDictionary() |
| 2443 | { | 2424 | { |
| 2444 | - this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid); | 2425 | + m->encryption_dict_objid = openObject(m->encryption_dict_objid); |
| 2445 | writeString("<<"); | 2426 | writeString("<<"); |
| 2446 | - for (auto const& iter: this->m->encryption_dictionary) { | 2427 | + for (auto const& iter: m->encryption_dictionary) { |
| 2447 | writeString(" "); | 2428 | writeString(" "); |
| 2448 | writeString(iter.first); | 2429 | writeString(iter.first); |
| 2449 | writeString(" "); | 2430 | writeString(" "); |
| 2450 | writeString(iter.second); | 2431 | writeString(iter.second); |
| 2451 | } | 2432 | } |
| 2452 | writeString(" >>"); | 2433 | writeString(" >>"); |
| 2453 | - closeObject(this->m->encryption_dict_objid); | 2434 | + closeObject(m->encryption_dict_objid); |
| 2454 | } | 2435 | } |
| 2455 | 2436 | ||
| 2456 | std::string | 2437 | std::string |
| 2457 | QPDFWriter::getFinalVersion() | 2438 | QPDFWriter::getFinalVersion() |
| 2458 | { | 2439 | { |
| 2459 | doWriteSetup(); | 2440 | doWriteSetup(); |
| 2460 | - return this->m->final_pdf_version; | 2441 | + return m->final_pdf_version; |
| 2461 | } | 2442 | } |
| 2462 | 2443 | ||
| 2463 | void | 2444 | void |
| 2464 | QPDFWriter::writeHeader() | 2445 | QPDFWriter::writeHeader() |
| 2465 | { | 2446 | { |
| 2466 | writeString("%PDF-"); | 2447 | writeString("%PDF-"); |
| 2467 | - writeString(this->m->final_pdf_version); | ||
| 2468 | - if (this->m->pclm) { | 2448 | + writeString(m->final_pdf_version); |
| 2449 | + if (m->pclm) { | ||
| 2469 | // PCLm version | 2450 | // PCLm version |
| 2470 | writeString("\n%PCLm 1.0\n"); | 2451 | writeString("\n%PCLm 1.0\n"); |
| 2471 | } else { | 2452 | } else { |
| @@ -2489,13 +2470,7 @@ QPDFWriter::writeHintStream(int hint_id) | @@ -2489,13 +2470,7 @@ QPDFWriter::writeHintStream(int hint_id) | ||
| 2489 | int S = 0; | 2470 | int S = 0; |
| 2490 | int O = 0; | 2471 | int O = 0; |
| 2491 | QPDF::Writer::generateHintStream( | 2472 | QPDF::Writer::generateHintStream( |
| 2492 | - this->m->pdf, | ||
| 2493 | - this->m->xref, | ||
| 2494 | - this->m->lengths, | ||
| 2495 | - this->m->obj_renumber_no_gen, | ||
| 2496 | - hint_buffer, | ||
| 2497 | - S, | ||
| 2498 | - O); | 2473 | + m->pdf, m->xref, m->lengths, m->obj_renumber_no_gen, hint_buffer, S, O); |
| 2499 | 2474 | ||
| 2500 | openObject(hint_id); | 2475 | openObject(hint_id); |
| 2501 | setDataKey(hint_id); | 2476 | setDataKey(hint_id); |
| @@ -2513,7 +2488,7 @@ QPDFWriter::writeHintStream(int hint_id) | @@ -2513,7 +2488,7 @@ QPDFWriter::writeHintStream(int hint_id) | ||
| 2513 | writeString(std::to_string(hlen)); | 2488 | writeString(std::to_string(hlen)); |
| 2514 | writeString(" >>\nstream\n"); | 2489 | writeString(" >>\nstream\n"); |
| 2515 | 2490 | ||
| 2516 | - if (this->m->encrypted) { | 2491 | + if (m->encrypted) { |
| 2517 | QTC::TC("qpdf", "QPDFWriter encrypted hint stream"); | 2492 | QTC::TC("qpdf", "QPDFWriter encrypted hint stream"); |
| 2518 | } | 2493 | } |
| 2519 | unsigned char last_char = '\0'; | 2494 | unsigned char last_char = '\0'; |
| @@ -2521,7 +2496,7 @@ QPDFWriter::writeHintStream(int hint_id) | @@ -2521,7 +2496,7 @@ QPDFWriter::writeHintStream(int hint_id) | ||
| 2521 | PipelinePopper pp_enc(this); | 2496 | PipelinePopper pp_enc(this); |
| 2522 | pushEncryptionFilter(pp_enc); | 2497 | pushEncryptionFilter(pp_enc); |
| 2523 | writeBuffer(hint_buffer); | 2498 | writeBuffer(hint_buffer); |
| 2524 | - last_char = this->m->pipeline->getLastChar(); | 2499 | + last_char = m->pipeline->getLastChar(); |
| 2525 | } | 2500 | } |
| 2526 | 2501 | ||
| 2527 | if (last_char != '\n') { | 2502 | if (last_char != '\n') { |
| @@ -2557,7 +2532,7 @@ QPDFWriter::writeXRefTable( | @@ -2557,7 +2532,7 @@ QPDFWriter::writeXRefTable( | ||
| 2557 | writeString(std::to_string(first)); | 2532 | writeString(std::to_string(first)); |
| 2558 | writeString(" "); | 2533 | writeString(" "); |
| 2559 | writeString(std::to_string(last - first + 1)); | 2534 | writeString(std::to_string(last - first + 1)); |
| 2560 | - qpdf_offset_t space_before_zero = this->m->pipeline->getCount(); | 2535 | + qpdf_offset_t space_before_zero = m->pipeline->getCount(); |
| 2561 | writeString("\n"); | 2536 | writeString("\n"); |
| 2562 | for (int i = first; i <= last; ++i) { | 2537 | for (int i = first; i <= last; ++i) { |
| 2563 | if (i == 0) { | 2538 | if (i == 0) { |
| @@ -2565,7 +2540,7 @@ QPDFWriter::writeXRefTable( | @@ -2565,7 +2540,7 @@ QPDFWriter::writeXRefTable( | ||
| 2565 | } else { | 2540 | } else { |
| 2566 | qpdf_offset_t offset = 0; | 2541 | qpdf_offset_t offset = 0; |
| 2567 | if (!suppress_offsets) { | 2542 | if (!suppress_offsets) { |
| 2568 | - offset = this->m->xref[i].getOffset(); | 2543 | + offset = m->xref[i].getOffset(); |
| 2569 | if ((hint_id != 0) && (i != hint_id) && | 2544 | if ((hint_id != 0) && (i != hint_id) && |
| 2570 | (offset >= hint_offset)) { | 2545 | (offset >= hint_offset)) { |
| 2571 | offset += hint_length; | 2546 | offset += hint_length; |
| @@ -2625,7 +2600,7 @@ QPDFWriter::writeXRefStream( | @@ -2625,7 +2600,7 @@ QPDFWriter::writeXRefStream( | ||
| 2625 | bool skip_compression, | 2600 | bool skip_compression, |
| 2626 | int linearization_pass) | 2601 | int linearization_pass) |
| 2627 | { | 2602 | { |
| 2628 | - qpdf_offset_t xref_offset = this->m->pipeline->getCount(); | 2603 | + qpdf_offset_t xref_offset = m->pipeline->getCount(); |
| 2629 | qpdf_offset_t space_before_zero = xref_offset - 1; | 2604 | qpdf_offset_t space_before_zero = xref_offset - 1; |
| 2630 | 2605 | ||
| 2631 | // field 1 contains offsets and object stream identifiers | 2606 | // field 1 contains offsets and object stream identifiers |
| @@ -2633,19 +2608,18 @@ QPDFWriter::writeXRefStream( | @@ -2633,19 +2608,18 @@ QPDFWriter::writeXRefStream( | ||
| 2633 | std::max(bytesNeeded(max_offset + hint_length), bytesNeeded(max_id)); | 2608 | std::max(bytesNeeded(max_offset + hint_length), bytesNeeded(max_id)); |
| 2634 | 2609 | ||
| 2635 | // field 2 contains object stream indices | 2610 | // field 2 contains object stream indices |
| 2636 | - unsigned int f2_size = bytesNeeded(this->m->max_ostream_index); | 2611 | + unsigned int f2_size = bytesNeeded(m->max_ostream_index); |
| 2637 | 2612 | ||
| 2638 | unsigned int esize = 1 + f1_size + f2_size; | 2613 | unsigned int esize = 1 + f1_size + f2_size; |
| 2639 | 2614 | ||
| 2640 | // Must store in xref table in advance of writing the actual data | 2615 | // Must store in xref table in advance of writing the actual data |
| 2641 | // rather than waiting for openObject to do it. | 2616 | // rather than waiting for openObject to do it. |
| 2642 | - this->m->xref[xref_id] = QPDFXRefEntry(m->pipeline->getCount()); | 2617 | + m->xref[xref_id] = QPDFXRefEntry(m->pipeline->getCount()); |
| 2643 | 2618 | ||
| 2644 | Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); | 2619 | Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); |
| 2645 | bool compressed = false; | 2620 | bool compressed = false; |
| 2646 | - if ((this->m->compress_streams || | ||
| 2647 | - (this->m->stream_decode_level == qpdf_dl_none)) && | ||
| 2648 | - (!this->m->qdf_mode)) { | 2621 | + if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) && |
| 2622 | + (!m->qdf_mode)) { | ||
| 2649 | compressed = true; | 2623 | compressed = true; |
| 2650 | if (!skip_compression) { | 2624 | if (!skip_compression) { |
| 2651 | // Write the stream dictionary for compression but don't | 2625 | // Write the stream dictionary for compression but don't |
| @@ -2662,7 +2636,7 @@ QPDFWriter::writeXRefStream( | @@ -2662,7 +2636,7 @@ QPDFWriter::writeXRefStream( | ||
| 2662 | PipelinePopper pp_xref(this, &xref_data); | 2636 | PipelinePopper pp_xref(this, &xref_data); |
| 2663 | activatePipelineStack(pp_xref); | 2637 | activatePipelineStack(pp_xref); |
| 2664 | for (int i = first; i <= last; ++i) { | 2638 | for (int i = first; i <= last; ++i) { |
| 2665 | - QPDFXRefEntry& e = this->m->xref[i]; | 2639 | + QPDFXRefEntry& e = m->xref[i]; |
| 2666 | switch (e.getType()) { | 2640 | switch (e.getType()) { |
| 2667 | case 0: | 2641 | case 0: |
| 2668 | writeBinary(0, 1); | 2642 | writeBinary(0, 1); |
| @@ -2781,8 +2755,7 @@ QPDFWriter::writeLinearized() | @@ -2781,8 +2755,7 @@ QPDFWriter::writeLinearized() | ||
| 2781 | // Optimize file and enqueue objects in order | 2755 | // Optimize file and enqueue objects in order |
| 2782 | 2756 | ||
| 2783 | discardGeneration( | 2757 | discardGeneration( |
| 2784 | - this->m->object_to_object_stream, | ||
| 2785 | - this->m->object_to_object_stream_no_gen); | 2758 | + m->object_to_object_stream, m->object_to_object_stream_no_gen); |
| 2786 | 2759 | ||
| 2787 | auto skip_stream_parameters = [this](QPDFObjectHandle& stream) { | 2760 | auto skip_stream_parameters = [this](QPDFObjectHandle& stream) { |
| 2788 | bool compress_stream; | 2761 | bool compress_stream; |
| @@ -2794,8 +2767,8 @@ QPDFWriter::writeLinearized() | @@ -2794,8 +2767,8 @@ QPDFWriter::writeLinearized() | ||
| 2794 | } | 2767 | } |
| 2795 | }; | 2768 | }; |
| 2796 | 2769 | ||
| 2797 | - this->m->pdf.optimize( | ||
| 2798 | - this->m->object_to_object_stream_no_gen, true, skip_stream_parameters); | 2770 | + m->pdf.optimize( |
| 2771 | + m->object_to_object_stream_no_gen, true, skip_stream_parameters); | ||
| 2799 | 2772 | ||
| 2800 | std::vector<QPDFObjectHandle> part4; | 2773 | std::vector<QPDFObjectHandle> part4; |
| 2801 | std::vector<QPDFObjectHandle> part6; | 2774 | std::vector<QPDFObjectHandle> part6; |
| @@ -2803,8 +2776,8 @@ QPDFWriter::writeLinearized() | @@ -2803,8 +2776,8 @@ QPDFWriter::writeLinearized() | ||
| 2803 | std::vector<QPDFObjectHandle> part8; | 2776 | std::vector<QPDFObjectHandle> part8; |
| 2804 | std::vector<QPDFObjectHandle> part9; | 2777 | std::vector<QPDFObjectHandle> part9; |
| 2805 | QPDF::Writer::getLinearizedParts( | 2778 | QPDF::Writer::getLinearizedParts( |
| 2806 | - this->m->pdf, | ||
| 2807 | - this->m->object_to_object_stream_no_gen, | 2779 | + m->pdf, |
| 2780 | + m->object_to_object_stream_no_gen, | ||
| 2808 | part4, | 2781 | part4, |
| 2809 | part6, | 2782 | part6, |
| 2810 | part7, | 2783 | part7, |
| @@ -2832,11 +2805,11 @@ QPDFWriter::writeLinearized() | @@ -2832,11 +2805,11 @@ QPDFWriter::writeLinearized() | ||
| 2832 | QIntC::to_int(part7.size() + part8.size() + part9.size()); | 2805 | QIntC::to_int(part7.size() + part8.size() + part9.size()); |
| 2833 | int second_half_first_obj = 1; | 2806 | int second_half_first_obj = 1; |
| 2834 | int after_second_half = 1 + second_half_uncompressed; | 2807 | int after_second_half = 1 + second_half_uncompressed; |
| 2835 | - this->m->next_objid = after_second_half; | 2808 | + m->next_objid = after_second_half; |
| 2836 | int second_half_xref = 0; | 2809 | int second_half_xref = 0; |
| 2837 | - bool need_xref_stream = (!this->m->object_to_object_stream.empty()); | 2810 | + bool need_xref_stream = (!m->object_to_object_stream.empty()); |
| 2838 | if (need_xref_stream) { | 2811 | if (need_xref_stream) { |
| 2839 | - second_half_xref = this->m->next_objid++; | 2812 | + second_half_xref = m->next_objid++; |
| 2840 | } | 2813 | } |
| 2841 | // Assign numbers to all compressed objects in the second half. | 2814 | // Assign numbers to all compressed objects in the second half. |
| 2842 | std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9}; | 2815 | std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9}; |
| @@ -2845,26 +2818,26 @@ QPDFWriter::writeLinearized() | @@ -2845,26 +2818,26 @@ QPDFWriter::writeLinearized() | ||
| 2845 | assignCompressedObjectNumbers(oh.getObjGen()); | 2818 | assignCompressedObjectNumbers(oh.getObjGen()); |
| 2846 | } | 2819 | } |
| 2847 | } | 2820 | } |
| 2848 | - int second_half_end = this->m->next_objid - 1; | ||
| 2849 | - int second_trailer_size = this->m->next_objid; | 2821 | + int second_half_end = m->next_objid - 1; |
| 2822 | + int second_trailer_size = m->next_objid; | ||
| 2850 | 2823 | ||
| 2851 | // First half objects | 2824 | // First half objects |
| 2852 | - int first_half_start = this->m->next_objid; | ||
| 2853 | - int lindict_id = this->m->next_objid++; | 2825 | + int first_half_start = m->next_objid; |
| 2826 | + int lindict_id = m->next_objid++; | ||
| 2854 | int first_half_xref = 0; | 2827 | int first_half_xref = 0; |
| 2855 | if (need_xref_stream) { | 2828 | if (need_xref_stream) { |
| 2856 | - first_half_xref = this->m->next_objid++; | ||
| 2857 | - } | ||
| 2858 | - int part4_first_obj = this->m->next_objid; | ||
| 2859 | - this->m->next_objid += QIntC::to_int(part4.size()); | ||
| 2860 | - int after_part4 = this->m->next_objid; | ||
| 2861 | - if (this->m->encrypted) { | ||
| 2862 | - this->m->encryption_dict_objid = this->m->next_objid++; | ||
| 2863 | - } | ||
| 2864 | - int hint_id = this->m->next_objid++; | ||
| 2865 | - int part6_first_obj = this->m->next_objid; | ||
| 2866 | - this->m->next_objid += QIntC::to_int(part6.size()); | ||
| 2867 | - int after_part6 = this->m->next_objid; | 2829 | + first_half_xref = m->next_objid++; |
| 2830 | + } | ||
| 2831 | + int part4_first_obj = m->next_objid; | ||
| 2832 | + m->next_objid += QIntC::to_int(part4.size()); | ||
| 2833 | + int after_part4 = m->next_objid; | ||
| 2834 | + if (m->encrypted) { | ||
| 2835 | + m->encryption_dict_objid = m->next_objid++; | ||
| 2836 | + } | ||
| 2837 | + int hint_id = m->next_objid++; | ||
| 2838 | + int part6_first_obj = m->next_objid; | ||
| 2839 | + m->next_objid += QIntC::to_int(part6.size()); | ||
| 2840 | + int after_part6 = m->next_objid; | ||
| 2868 | // Assign numbers to all compressed objects in the first half | 2841 | // Assign numbers to all compressed objects in the first half |
| 2869 | std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6}; | 2842 | std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6}; |
| 2870 | for (int i = 0; i < 2; ++i) { | 2843 | for (int i = 0; i < 2; ++i) { |
| @@ -2872,8 +2845,8 @@ QPDFWriter::writeLinearized() | @@ -2872,8 +2845,8 @@ QPDFWriter::writeLinearized() | ||
| 2872 | assignCompressedObjectNumbers(oh.getObjGen()); | 2845 | assignCompressedObjectNumbers(oh.getObjGen()); |
| 2873 | } | 2846 | } |
| 2874 | } | 2847 | } |
| 2875 | - int first_half_end = this->m->next_objid - 1; | ||
| 2876 | - int first_trailer_size = this->m->next_objid; | 2848 | + int first_half_end = m->next_objid - 1; |
| 2849 | + int first_trailer_size = m->next_objid; | ||
| 2877 | 2850 | ||
| 2878 | int part4_end_marker = part4.back().getObjectID(); | 2851 | int part4_end_marker = part4.back().getObjectID(); |
| 2879 | int part6_end_marker = part6.back().getObjectID(); | 2852 | int part6_end_marker = part6.back().getObjectID(); |
| @@ -2885,26 +2858,26 @@ QPDFWriter::writeLinearized() | @@ -2885,26 +2858,26 @@ QPDFWriter::writeLinearized() | ||
| 2885 | qpdf_offset_t first_xref_end = 0; | 2858 | qpdf_offset_t first_xref_end = 0; |
| 2886 | qpdf_offset_t second_xref_end = 0; | 2859 | qpdf_offset_t second_xref_end = 0; |
| 2887 | 2860 | ||
| 2888 | - this->m->next_objid = part4_first_obj; | 2861 | + m->next_objid = part4_first_obj; |
| 2889 | enqueuePart(part4); | 2862 | enqueuePart(part4); |
| 2890 | - if (this->m->next_objid != after_part4) { | 2863 | + if (m->next_objid != after_part4) { |
| 2891 | // This can happen with very botched files as in the fuzzer | 2864 | // This can happen with very botched files as in the fuzzer |
| 2892 | // test. There are likely some faulty assumptions in | 2865 | // test. There are likely some faulty assumptions in |
| 2893 | // calculateLinearizationData | 2866 | // calculateLinearizationData |
| 2894 | throw std::runtime_error("error encountered after" | 2867 | throw std::runtime_error("error encountered after" |
| 2895 | " writing part 4 of linearized data"); | 2868 | " writing part 4 of linearized data"); |
| 2896 | } | 2869 | } |
| 2897 | - this->m->next_objid = part6_first_obj; | 2870 | + m->next_objid = part6_first_obj; |
| 2898 | enqueuePart(part6); | 2871 | enqueuePart(part6); |
| 2899 | - if (this->m->next_objid != after_part6) { | 2872 | + if (m->next_objid != after_part6) { |
| 2900 | throw std::runtime_error("error encountered after" | 2873 | throw std::runtime_error("error encountered after" |
| 2901 | " writing part 6 of linearized data"); | 2874 | " writing part 6 of linearized data"); |
| 2902 | } | 2875 | } |
| 2903 | - this->m->next_objid = second_half_first_obj; | 2876 | + m->next_objid = second_half_first_obj; |
| 2904 | enqueuePart(part7); | 2877 | enqueuePart(part7); |
| 2905 | enqueuePart(part8); | 2878 | enqueuePart(part8); |
| 2906 | enqueuePart(part9); | 2879 | enqueuePart(part9); |
| 2907 | - if (this->m->next_objid != after_second_half) { | 2880 | + if (m->next_objid != after_second_half) { |
| 2908 | throw std::runtime_error("error encountered after" | 2881 | throw std::runtime_error("error encountered after" |
| 2909 | " writing part 9 of linearized data"); | 2882 | " writing part 9 of linearized data"); |
| 2910 | } | 2883 | } |
| @@ -2919,16 +2892,16 @@ QPDFWriter::writeLinearized() | @@ -2919,16 +2892,16 @@ QPDFWriter::writeLinearized() | ||
| 2919 | auto pp_md5 = std::make_shared<PipelinePopper>(this); | 2892 | auto pp_md5 = std::make_shared<PipelinePopper>(this); |
| 2920 | for (int pass = 1; pass <= 2; ++pass) { | 2893 | for (int pass = 1; pass <= 2; ++pass) { |
| 2921 | if (pass == 1) { | 2894 | if (pass == 1) { |
| 2922 | - if (!this->m->lin_pass1_filename.empty()) { | ||
| 2923 | - lin_pass1_file = QUtil::safe_fopen( | ||
| 2924 | - this->m->lin_pass1_filename.c_str(), "wb"); | 2895 | + if (!m->lin_pass1_filename.empty()) { |
| 2896 | + lin_pass1_file = | ||
| 2897 | + QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb"); | ||
| 2925 | pushPipeline( | 2898 | pushPipeline( |
| 2926 | new Pl_StdioFile("linearization pass1", lin_pass1_file)); | 2899 | new Pl_StdioFile("linearization pass1", lin_pass1_file)); |
| 2927 | activatePipelineStack(*pp_pass1); | 2900 | activatePipelineStack(*pp_pass1); |
| 2928 | } else { | 2901 | } else { |
| 2929 | pushDiscardFilter(*pp_pass1); | 2902 | pushDiscardFilter(*pp_pass1); |
| 2930 | } | 2903 | } |
| 2931 | - if (this->m->deterministic_id) { | 2904 | + if (m->deterministic_id) { |
| 2932 | pushMD5Pipeline(*pp_md5); | 2905 | pushMD5Pipeline(*pp_md5); |
| 2933 | } | 2906 | } |
| 2934 | } | 2907 | } |
| @@ -2945,14 +2918,12 @@ QPDFWriter::writeLinearized() | @@ -2945,14 +2918,12 @@ QPDFWriter::writeLinearized() | ||
| 2945 | // dictionary must appear within the first 1024 characters of | 2918 | // dictionary must appear within the first 1024 characters of |
| 2946 | // the file. | 2919 | // the file. |
| 2947 | 2920 | ||
| 2948 | - qpdf_offset_t pos = this->m->pipeline->getCount(); | 2921 | + qpdf_offset_t pos = m->pipeline->getCount(); |
| 2949 | openObject(lindict_id); | 2922 | openObject(lindict_id); |
| 2950 | writeString("<<"); | 2923 | writeString("<<"); |
| 2951 | if (pass == 2) { | 2924 | if (pass == 2) { |
| 2952 | - std::vector<QPDFObjectHandle> const& pages = | ||
| 2953 | - this->m->pdf.getAllPages(); | ||
| 2954 | - int first_page_object = | ||
| 2955 | - this->m->obj_renumber[pages.at(0).getObjGen()]; | 2925 | + std::vector<QPDFObjectHandle> const& pages = m->pdf.getAllPages(); |
| 2926 | + int first_page_object = m->obj_renumber[pages.at(0).getObjGen()]; | ||
| 2956 | int npages = QIntC::to_int(pages.size()); | 2927 | int npages = QIntC::to_int(pages.size()); |
| 2957 | 2928 | ||
| 2958 | writeString(" /Linearized 1 /L "); | 2929 | writeString(" /Linearized 1 /L "); |
| @@ -2960,7 +2931,7 @@ QPDFWriter::writeLinearized() | @@ -2960,7 +2931,7 @@ QPDFWriter::writeLinearized() | ||
| 2960 | // Implementation note 121 states that a space is | 2931 | // Implementation note 121 states that a space is |
| 2961 | // mandatory after this open bracket. | 2932 | // mandatory after this open bracket. |
| 2962 | writeString(" /H [ "); | 2933 | writeString(" /H [ "); |
| 2963 | - writeString(std::to_string(this->m->xref[hint_id].getOffset())); | 2934 | + writeString(std::to_string(m->xref[hint_id].getOffset())); |
| 2964 | writeString(" "); | 2935 | writeString(" "); |
| 2965 | writeString(std::to_string(hint_length)); | 2936 | writeString(std::to_string(hint_length)); |
| 2966 | writeString(" ] /O "); | 2937 | writeString(" ] /O "); |
| @@ -2975,19 +2946,19 @@ QPDFWriter::writeLinearized() | @@ -2975,19 +2946,19 @@ QPDFWriter::writeLinearized() | ||
| 2975 | writeString(" >>"); | 2946 | writeString(" >>"); |
| 2976 | closeObject(lindict_id); | 2947 | closeObject(lindict_id); |
| 2977 | static int const pad = 200; | 2948 | static int const pad = 200; |
| 2978 | - writePad(QIntC::to_size(pos - this->m->pipeline->getCount() + pad)); | 2949 | + writePad(QIntC::to_size(pos - m->pipeline->getCount() + pad)); |
| 2979 | writeString("\n"); | 2950 | writeString("\n"); |
| 2980 | 2951 | ||
| 2981 | // If the user supplied any additional header text, write it | 2952 | // If the user supplied any additional header text, write it |
| 2982 | // here after the linearization parameter dictionary. | 2953 | // here after the linearization parameter dictionary. |
| 2983 | - writeString(this->m->extra_header_text); | 2954 | + writeString(m->extra_header_text); |
| 2984 | 2955 | ||
| 2985 | // Part 3: first page cross reference table and trailer. | 2956 | // Part 3: first page cross reference table and trailer. |
| 2986 | 2957 | ||
| 2987 | - qpdf_offset_t first_xref_offset = this->m->pipeline->getCount(); | 2958 | + qpdf_offset_t first_xref_offset = m->pipeline->getCount(); |
| 2988 | qpdf_offset_t hint_offset = 0; | 2959 | qpdf_offset_t hint_offset = 0; |
| 2989 | if (pass == 2) { | 2960 | if (pass == 2) { |
| 2990 | - hint_offset = this->m->xref[hint_id].getOffset(); | 2961 | + hint_offset = m->xref[hint_id].getOffset(); |
| 2991 | } | 2962 | } |
| 2992 | if (need_xref_stream) { | 2963 | if (need_xref_stream) { |
| 2993 | // Must pad here too. | 2964 | // Must pad here too. |
| @@ -3002,7 +2973,7 @@ QPDFWriter::writeLinearized() | @@ -3002,7 +2973,7 @@ QPDFWriter::writeLinearized() | ||
| 3002 | // it's smaller. | 2973 | // it's smaller. |
| 3003 | first_half_max_obj_offset = 1 << 25; | 2974 | first_half_max_obj_offset = 1 << 25; |
| 3004 | } | 2975 | } |
| 3005 | - pos = this->m->pipeline->getCount(); | 2976 | + pos = m->pipeline->getCount(); |
| 3006 | writeXRefStream( | 2977 | writeXRefStream( |
| 3007 | first_half_xref, | 2978 | first_half_xref, |
| 3008 | first_half_end, | 2979 | first_half_end, |
| @@ -3017,18 +2988,18 @@ QPDFWriter::writeLinearized() | @@ -3017,18 +2988,18 @@ QPDFWriter::writeLinearized() | ||
| 3017 | hint_length, | 2988 | hint_length, |
| 3018 | (pass == 1), | 2989 | (pass == 1), |
| 3019 | pass); | 2990 | pass); |
| 3020 | - qpdf_offset_t endpos = this->m->pipeline->getCount(); | 2991 | + qpdf_offset_t endpos = m->pipeline->getCount(); |
| 3021 | if (pass == 1) { | 2992 | if (pass == 1) { |
| 3022 | // Pad so we have enough room for the real xref | 2993 | // Pad so we have enough room for the real xref |
| 3023 | // stream. | 2994 | // stream. |
| 3024 | writePad(calculateXrefStreamPadding(endpos - pos)); | 2995 | writePad(calculateXrefStreamPadding(endpos - pos)); |
| 3025 | - first_xref_end = this->m->pipeline->getCount(); | 2996 | + first_xref_end = m->pipeline->getCount(); |
| 3026 | } else { | 2997 | } else { |
| 3027 | // Pad so that the next object starts at the same | 2998 | // Pad so that the next object starts at the same |
| 3028 | // place as in pass 1. | 2999 | // place as in pass 1. |
| 3029 | writePad(QIntC::to_size(first_xref_end - endpos)); | 3000 | writePad(QIntC::to_size(first_xref_end - endpos)); |
| 3030 | 3001 | ||
| 3031 | - if (this->m->pipeline->getCount() != first_xref_end) { | 3002 | + if (m->pipeline->getCount() != first_xref_end) { |
| 3032 | throw std::logic_error( | 3003 | throw std::logic_error( |
| 3033 | "insufficient padding for first pass xref stream; " | 3004 | "insufficient padding for first pass xref stream; " |
| 3034 | "first_xref_end=" + | 3005 | "first_xref_end=" + |
| @@ -3054,25 +3025,24 @@ QPDFWriter::writeLinearized() | @@ -3054,25 +3025,24 @@ QPDFWriter::writeLinearized() | ||
| 3054 | 3025 | ||
| 3055 | // Parts 4 through 9 | 3026 | // Parts 4 through 9 |
| 3056 | 3027 | ||
| 3057 | - for (auto const& cur_object: this->m->object_queue) { | 3028 | + for (auto const& cur_object: m->object_queue) { |
| 3058 | if (cur_object.getObjectID() == part6_end_marker) { | 3029 | if (cur_object.getObjectID() == part6_end_marker) { |
| 3059 | - first_half_max_obj_offset = this->m->pipeline->getCount(); | 3030 | + first_half_max_obj_offset = m->pipeline->getCount(); |
| 3060 | } | 3031 | } |
| 3061 | writeObject(cur_object); | 3032 | writeObject(cur_object); |
| 3062 | if (cur_object.getObjectID() == part4_end_marker) { | 3033 | if (cur_object.getObjectID() == part4_end_marker) { |
| 3063 | - if (this->m->encrypted) { | 3034 | + if (m->encrypted) { |
| 3064 | writeEncryptionDictionary(); | 3035 | writeEncryptionDictionary(); |
| 3065 | } | 3036 | } |
| 3066 | if (pass == 1) { | 3037 | if (pass == 1) { |
| 3067 | - this->m->xref[hint_id] = | ||
| 3068 | - QPDFXRefEntry(m->pipeline->getCount()); | 3038 | + m->xref[hint_id] = QPDFXRefEntry(m->pipeline->getCount()); |
| 3069 | } else { | 3039 | } else { |
| 3070 | // Part 5: hint stream | 3040 | // Part 5: hint stream |
| 3071 | writeBuffer(hint_buffer); | 3041 | writeBuffer(hint_buffer); |
| 3072 | } | 3042 | } |
| 3073 | } | 3043 | } |
| 3074 | if (cur_object.getObjectID() == part6_end_marker) { | 3044 | if (cur_object.getObjectID() == part6_end_marker) { |
| 3075 | - part6_end_offset = this->m->pipeline->getCount(); | 3045 | + part6_end_offset = m->pipeline->getCount(); |
| 3076 | } | 3046 | } |
| 3077 | } | 3047 | } |
| 3078 | 3048 | ||
| @@ -3080,9 +3050,9 @@ QPDFWriter::writeLinearized() | @@ -3080,9 +3050,9 @@ QPDFWriter::writeLinearized() | ||
| 3080 | 3050 | ||
| 3081 | // Part 11: main cross reference table and trailer | 3051 | // Part 11: main cross reference table and trailer |
| 3082 | 3052 | ||
| 3083 | - second_xref_offset = this->m->pipeline->getCount(); | 3053 | + second_xref_offset = m->pipeline->getCount(); |
| 3084 | if (need_xref_stream) { | 3054 | if (need_xref_stream) { |
| 3085 | - pos = this->m->pipeline->getCount(); | 3055 | + pos = m->pipeline->getCount(); |
| 3086 | space_before_zero = writeXRefStream( | 3056 | space_before_zero = writeXRefStream( |
| 3087 | second_half_xref, | 3057 | second_half_xref, |
| 3088 | second_half_end, | 3058 | second_half_end, |
| @@ -3097,7 +3067,7 @@ QPDFWriter::writeLinearized() | @@ -3097,7 +3067,7 @@ QPDFWriter::writeLinearized() | ||
| 3097 | 0, | 3067 | 0, |
| 3098 | (pass == 1), | 3068 | (pass == 1), |
| 3099 | pass); | 3069 | pass); |
| 3100 | - qpdf_offset_t endpos = this->m->pipeline->getCount(); | 3070 | + qpdf_offset_t endpos = m->pipeline->getCount(); |
| 3101 | 3071 | ||
| 3102 | if (pass == 1) { | 3072 | if (pass == 1) { |
| 3103 | // Pad so we have enough room for the real xref | 3073 | // Pad so we have enough room for the real xref |
| @@ -3105,18 +3075,17 @@ QPDFWriter::writeLinearized() | @@ -3105,18 +3075,17 @@ QPDFWriter::writeLinearized() | ||
| 3105 | // how we calculate the padding. | 3075 | // how we calculate the padding. |
| 3106 | writePad(calculateXrefStreamPadding(endpos - pos)); | 3076 | writePad(calculateXrefStreamPadding(endpos - pos)); |
| 3107 | writeString("\n"); | 3077 | writeString("\n"); |
| 3108 | - second_xref_end = this->m->pipeline->getCount(); | 3078 | + second_xref_end = m->pipeline->getCount(); |
| 3109 | } else { | 3079 | } else { |
| 3110 | // Make the file size the same. | 3080 | // Make the file size the same. |
| 3111 | writePad(QIntC::to_size( | 3081 | writePad(QIntC::to_size( |
| 3112 | second_xref_end + hint_length - 1 - | 3082 | second_xref_end + hint_length - 1 - |
| 3113 | - this->m->pipeline->getCount())); | 3083 | + m->pipeline->getCount())); |
| 3114 | writeString("\n"); | 3084 | writeString("\n"); |
| 3115 | 3085 | ||
| 3116 | // If this assertion fails, maybe we didn't have | 3086 | // If this assertion fails, maybe we didn't have |
| 3117 | // enough padding above. | 3087 | // enough padding above. |
| 3118 | - if (this->m->pipeline->getCount() != | ||
| 3119 | - second_xref_end + hint_length) { | 3088 | + if (m->pipeline->getCount() != second_xref_end + hint_length) { |
| 3120 | throw std::logic_error("count mismatch after xref stream;" | 3089 | throw std::logic_error("count mismatch after xref stream;" |
| 3121 | " possible insufficient padding?"); | 3090 | " possible insufficient padding?"); |
| 3122 | } | 3091 | } |
| @@ -3138,26 +3107,26 @@ QPDFWriter::writeLinearized() | @@ -3138,26 +3107,26 @@ QPDFWriter::writeLinearized() | ||
| 3138 | writeString(std::to_string(first_xref_offset)); | 3107 | writeString(std::to_string(first_xref_offset)); |
| 3139 | writeString("\n%%EOF\n"); | 3108 | writeString("\n%%EOF\n"); |
| 3140 | 3109 | ||
| 3141 | - discardGeneration(this->m->obj_renumber, this->m->obj_renumber_no_gen); | 3110 | + discardGeneration(m->obj_renumber, m->obj_renumber_no_gen); |
| 3142 | 3111 | ||
| 3143 | if (pass == 1) { | 3112 | if (pass == 1) { |
| 3144 | - if (this->m->deterministic_id) { | 3113 | + if (m->deterministic_id) { |
| 3145 | QTC::TC( | 3114 | QTC::TC( |
| 3146 | "qpdf", | 3115 | "qpdf", |
| 3147 | "QPDFWriter linearized deterministic ID", | 3116 | "QPDFWriter linearized deterministic ID", |
| 3148 | need_xref_stream ? 0 : 1); | 3117 | need_xref_stream ? 0 : 1); |
| 3149 | computeDeterministicIDData(); | 3118 | computeDeterministicIDData(); |
| 3150 | pp_md5 = nullptr; | 3119 | pp_md5 = nullptr; |
| 3151 | - qpdf_assert_debug(this->m->md5_pipeline == nullptr); | 3120 | + qpdf_assert_debug(m->md5_pipeline == nullptr); |
| 3152 | } | 3121 | } |
| 3153 | 3122 | ||
| 3154 | // Close first pass pipeline | 3123 | // Close first pass pipeline |
| 3155 | - file_size = this->m->pipeline->getCount(); | 3124 | + file_size = m->pipeline->getCount(); |
| 3156 | pp_pass1 = nullptr; | 3125 | pp_pass1 = nullptr; |
| 3157 | 3126 | ||
| 3158 | // Save hint offset since it will be set to zero by | 3127 | // Save hint offset since it will be set to zero by |
| 3159 | // calling openObject. | 3128 | // calling openObject. |
| 3160 | - qpdf_offset_t hint_offset1 = this->m->xref[hint_id].getOffset(); | 3129 | + qpdf_offset_t hint_offset1 = m->xref[hint_id].getOffset(); |
| 3161 | 3130 | ||
| 3162 | // Write hint stream to a buffer | 3131 | // Write hint stream to a buffer |
| 3163 | { | 3132 | { |
| @@ -3169,7 +3138,7 @@ QPDFWriter::writeLinearized() | @@ -3169,7 +3138,7 @@ QPDFWriter::writeLinearized() | ||
| 3169 | hint_length = QIntC::to_offset(hint_buffer->getSize()); | 3138 | hint_length = QIntC::to_offset(hint_buffer->getSize()); |
| 3170 | 3139 | ||
| 3171 | // Restore hint offset | 3140 | // Restore hint offset |
| 3172 | - this->m->xref[hint_id] = QPDFXRefEntry(hint_offset1); | 3141 | + m->xref[hint_id] = QPDFXRefEntry(hint_offset1); |
| 3173 | if (lin_pass1_file) { | 3142 | if (lin_pass1_file) { |
| 3174 | // Write some debugging information | 3143 | // Write some debugging information |
| 3175 | fprintf( | 3144 | fprintf( |
| @@ -3198,9 +3167,9 @@ QPDFWriter::writeLinearized() | @@ -3198,9 +3167,9 @@ QPDFWriter::writeLinearized() | ||
| 3198 | void | 3167 | void |
| 3199 | QPDFWriter::enqueueObjectsStandard() | 3168 | QPDFWriter::enqueueObjectsStandard() |
| 3200 | { | 3169 | { |
| 3201 | - if (this->m->preserve_unreferenced_objects) { | 3170 | + if (m->preserve_unreferenced_objects) { |
| 3202 | QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard"); | 3171 | QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard"); |
| 3203 | - for (auto const& oh: this->m->pdf.getAllObjects()) { | 3172 | + for (auto const& oh: m->pdf.getAllObjects()) { |
| 3204 | enqueueObject(oh); | 3173 | enqueueObject(oh); |
| 3205 | } | 3174 | } |
| 3206 | } | 3175 | } |
| @@ -3227,7 +3196,7 @@ QPDFWriter::enqueueObjectsPCLm() | @@ -3227,7 +3196,7 @@ QPDFWriter::enqueueObjectsPCLm() | ||
| 3227 | std::string image_transform_content = "q /image Do Q\n"; | 3196 | std::string image_transform_content = "q /image Do Q\n"; |
| 3228 | 3197 | ||
| 3229 | // enqueue all pages first | 3198 | // enqueue all pages first |
| 3230 | - std::vector<QPDFObjectHandle> all = this->m->pdf.getAllPages(); | 3199 | + std::vector<QPDFObjectHandle> all = m->pdf.getAllPages(); |
| 3231 | for (auto& page: all) { | 3200 | for (auto& page: all) { |
| 3232 | // enqueue page | 3201 | // enqueue page |
| 3233 | enqueueObject(page); | 3202 | enqueueObject(page); |
| @@ -3239,8 +3208,8 @@ QPDFWriter::enqueueObjectsPCLm() | @@ -3239,8 +3208,8 @@ QPDFWriter::enqueueObjectsPCLm() | ||
| 3239 | QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); | 3208 | QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); |
| 3240 | for (auto const& image: strips.getKeys()) { | 3209 | for (auto const& image: strips.getKeys()) { |
| 3241 | enqueueObject(strips.getKey(image)); | 3210 | enqueueObject(strips.getKey(image)); |
| 3242 | - enqueueObject(QPDFObjectHandle::newStream( | ||
| 3243 | - &this->m->pdf, image_transform_content)); | 3211 | + enqueueObject( |
| 3212 | + QPDFObjectHandle::newStream(&m->pdf, image_transform_content)); | ||
| 3244 | } | 3213 | } |
| 3245 | } | 3214 | } |
| 3246 | 3215 | ||
| @@ -3253,54 +3222,51 @@ void | @@ -3253,54 +3222,51 @@ void | ||
| 3253 | QPDFWriter::indicateProgress(bool decrement, bool finished) | 3222 | QPDFWriter::indicateProgress(bool decrement, bool finished) |
| 3254 | { | 3223 | { |
| 3255 | if (decrement) { | 3224 | if (decrement) { |
| 3256 | - --this->m->events_seen; | 3225 | + --m->events_seen; |
| 3257 | return; | 3226 | return; |
| 3258 | } | 3227 | } |
| 3259 | 3228 | ||
| 3260 | - ++this->m->events_seen; | 3229 | + ++m->events_seen; |
| 3261 | 3230 | ||
| 3262 | - if (!this->m->progress_reporter.get()) { | 3231 | + if (!m->progress_reporter.get()) { |
| 3263 | return; | 3232 | return; |
| 3264 | } | 3233 | } |
| 3265 | 3234 | ||
| 3266 | - if (finished || (this->m->events_seen >= this->m->next_progress_report)) { | 3235 | + if (finished || (m->events_seen >= m->next_progress_report)) { |
| 3267 | int percentage = | 3236 | int percentage = |
| 3268 | (finished ? 100 | 3237 | (finished ? 100 |
| 3269 | - : this->m->next_progress_report == 0 | 3238 | + : m->next_progress_report == 0 |
| 3270 | ? 0 | 3239 | ? 0 |
| 3271 | : std::min( | 3240 | : std::min( |
| 3272 | - 99, | ||
| 3273 | - 1 + | ||
| 3274 | - ((100 * this->m->events_seen) / | ||
| 3275 | - this->m->events_expected))); | ||
| 3276 | - this->m->progress_reporter->reportProgress(percentage); | 3241 | + 99, 1 + ((100 * m->events_seen) / m->events_expected))); |
| 3242 | + m->progress_reporter->reportProgress(percentage); | ||
| 3277 | } | 3243 | } |
| 3278 | - int increment = std::max(1, (this->m->events_expected / 100)); | ||
| 3279 | - while (this->m->events_seen >= this->m->next_progress_report) { | ||
| 3280 | - this->m->next_progress_report += increment; | 3244 | + int increment = std::max(1, (m->events_expected / 100)); |
| 3245 | + while (m->events_seen >= m->next_progress_report) { | ||
| 3246 | + m->next_progress_report += increment; | ||
| 3281 | } | 3247 | } |
| 3282 | } | 3248 | } |
| 3283 | 3249 | ||
| 3284 | void | 3250 | void |
| 3285 | QPDFWriter::registerProgressReporter(std::shared_ptr<ProgressReporter> pr) | 3251 | QPDFWriter::registerProgressReporter(std::shared_ptr<ProgressReporter> pr) |
| 3286 | { | 3252 | { |
| 3287 | - this->m->progress_reporter = pr; | 3253 | + m->progress_reporter = pr; |
| 3288 | } | 3254 | } |
| 3289 | 3255 | ||
| 3290 | void | 3256 | void |
| 3291 | QPDFWriter::writeStandard() | 3257 | QPDFWriter::writeStandard() |
| 3292 | { | 3258 | { |
| 3293 | auto pp_md5 = std::make_shared<PipelinePopper>(this); | 3259 | auto pp_md5 = std::make_shared<PipelinePopper>(this); |
| 3294 | - if (this->m->deterministic_id) { | 3260 | + if (m->deterministic_id) { |
| 3295 | pushMD5Pipeline(*pp_md5); | 3261 | pushMD5Pipeline(*pp_md5); |
| 3296 | } | 3262 | } |
| 3297 | 3263 | ||
| 3298 | // Start writing | 3264 | // Start writing |
| 3299 | 3265 | ||
| 3300 | writeHeader(); | 3266 | writeHeader(); |
| 3301 | - writeString(this->m->extra_header_text); | 3267 | + writeString(m->extra_header_text); |
| 3302 | 3268 | ||
| 3303 | - if (this->m->pclm) { | 3269 | + if (m->pclm) { |
| 3304 | enqueueObjectsPCLm(); | 3270 | enqueueObjectsPCLm(); |
| 3305 | } else { | 3271 | } else { |
| 3306 | enqueueObjectsStandard(); | 3272 | enqueueObjectsStandard(); |
| @@ -3314,38 +3280,37 @@ QPDFWriter::writeStandard() | @@ -3314,38 +3280,37 @@ QPDFWriter::writeStandard() | ||
| 3314 | } | 3280 | } |
| 3315 | 3281 | ||
| 3316 | // Write out the encryption dictionary, if any | 3282 | // Write out the encryption dictionary, if any |
| 3317 | - if (this->m->encrypted) { | 3283 | + if (m->encrypted) { |
| 3318 | writeEncryptionDictionary(); | 3284 | writeEncryptionDictionary(); |
| 3319 | } | 3285 | } |
| 3320 | 3286 | ||
| 3321 | // Now write out xref. next_objid is now the number of objects. | 3287 | // Now write out xref. next_objid is now the number of objects. |
| 3322 | - qpdf_offset_t xref_offset = this->m->pipeline->getCount(); | ||
| 3323 | - if (this->m->object_stream_to_objects.empty()) { | 3288 | + qpdf_offset_t xref_offset = m->pipeline->getCount(); |
| 3289 | + if (m->object_stream_to_objects.empty()) { | ||
| 3324 | // Write regular cross-reference table | 3290 | // Write regular cross-reference table |
| 3325 | - writeXRefTable( | ||
| 3326 | - t_normal, 0, this->m->next_objid - 1, this->m->next_objid); | 3291 | + writeXRefTable(t_normal, 0, m->next_objid - 1, m->next_objid); |
| 3327 | } else { | 3292 | } else { |
| 3328 | // Write cross-reference stream. | 3293 | // Write cross-reference stream. |
| 3329 | - int xref_id = this->m->next_objid++; | 3294 | + int xref_id = m->next_objid++; |
| 3330 | writeXRefStream( | 3295 | writeXRefStream( |
| 3331 | xref_id, | 3296 | xref_id, |
| 3332 | xref_id, | 3297 | xref_id, |
| 3333 | xref_offset, | 3298 | xref_offset, |
| 3334 | t_normal, | 3299 | t_normal, |
| 3335 | 0, | 3300 | 0, |
| 3336 | - this->m->next_objid - 1, | ||
| 3337 | - this->m->next_objid); | 3301 | + m->next_objid - 1, |
| 3302 | + m->next_objid); | ||
| 3338 | } | 3303 | } |
| 3339 | writeString("startxref\n"); | 3304 | writeString("startxref\n"); |
| 3340 | writeString(std::to_string(xref_offset)); | 3305 | writeString(std::to_string(xref_offset)); |
| 3341 | writeString("\n%%EOF\n"); | 3306 | writeString("\n%%EOF\n"); |
| 3342 | 3307 | ||
| 3343 | - if (this->m->deterministic_id) { | 3308 | + if (m->deterministic_id) { |
| 3344 | QTC::TC( | 3309 | QTC::TC( |
| 3345 | "qpdf", | 3310 | "qpdf", |
| 3346 | "QPDFWriter standard deterministic ID", | 3311 | "QPDFWriter standard deterministic ID", |
| 3347 | - this->m->object_stream_to_objects.empty() ? 0 : 1); | 3312 | + m->object_stream_to_objects.empty() ? 0 : 1); |
| 3348 | pp_md5 = nullptr; | 3313 | pp_md5 = nullptr; |
| 3349 | - qpdf_assert_debug(this->m->md5_pipeline == nullptr); | 3314 | + qpdf_assert_debug(m->md5_pipeline == nullptr); |
| 3350 | } | 3315 | } |
| 3351 | } | 3316 | } |
libqpdf/QPDF_encryption.cc
| @@ -774,27 +774,27 @@ QPDF::interpretCF( | @@ -774,27 +774,27 @@ QPDF::interpretCF( | ||
| 774 | void | 774 | void |
| 775 | QPDF::initializeEncryption() | 775 | QPDF::initializeEncryption() |
| 776 | { | 776 | { |
| 777 | - if (this->m->encp->encryption_initialized) { | 777 | + if (m->encp->encryption_initialized) { |
| 778 | return; | 778 | return; |
| 779 | } | 779 | } |
| 780 | - this->m->encp->encryption_initialized = true; | 780 | + m->encp->encryption_initialized = true; |
| 781 | 781 | ||
| 782 | // After we initialize encryption parameters, we must used stored | 782 | // After we initialize encryption parameters, we must used stored |
| 783 | // key information and never look at /Encrypt again. Otherwise, | 783 | // key information and never look at /Encrypt again. Otherwise, |
| 784 | // things could go wrong if someone mutates the encryption | 784 | // things could go wrong if someone mutates the encryption |
| 785 | // dictionary. | 785 | // dictionary. |
| 786 | 786 | ||
| 787 | - if (!this->m->trailer.hasKey("/Encrypt")) { | 787 | + if (!m->trailer.hasKey("/Encrypt")) { |
| 788 | return; | 788 | return; |
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | - // Go ahead and set this->m->encrypted here. That way, isEncrypted | 791 | + // Go ahead and set m->encrypted here. That way, isEncrypted |
| 792 | // will return true even if there were errors reading the | 792 | // will return true even if there were errors reading the |
| 793 | // encryption dictionary. | 793 | // encryption dictionary. |
| 794 | - this->m->encp->encrypted = true; | 794 | + m->encp->encrypted = true; |
| 795 | 795 | ||
| 796 | std::string id1; | 796 | std::string id1; |
| 797 | - QPDFObjectHandle id_obj = this->m->trailer.getKey("/ID"); | 797 | + QPDFObjectHandle id_obj = m->trailer.getKey("/ID"); |
| 798 | if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) && | 798 | if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) && |
| 799 | id_obj.getArrayItem(0).isString())) { | 799 | id_obj.getArrayItem(0).isString())) { |
| 800 | id1 = id_obj.getArrayItem(0).getStringValue(); | 800 | id1 = id_obj.getArrayItem(0).getStringValue(); |
| @@ -805,7 +805,7 @@ QPDF::initializeEncryption() | @@ -805,7 +805,7 @@ QPDF::initializeEncryption() | ||
| 805 | warn(damagedPDF("trailer", "invalid /ID in trailer dictionary")); | 805 | warn(damagedPDF("trailer", "invalid /ID in trailer dictionary")); |
| 806 | } | 806 | } |
| 807 | 807 | ||
| 808 | - QPDFObjectHandle encryption_dict = this->m->trailer.getKey("/Encrypt"); | 808 | + QPDFObjectHandle encryption_dict = m->trailer.getKey("/Encrypt"); |
| 809 | if (!encryption_dict.isDictionary()) { | 809 | if (!encryption_dict.isDictionary()) { |
| 810 | throw damagedPDF("/Encrypt in trailer dictionary is not a dictionary"); | 810 | throw damagedPDF("/Encrypt in trailer dictionary is not a dictionary"); |
| 811 | } | 811 | } |
| @@ -814,16 +814,16 @@ QPDF::initializeEncryption() | @@ -814,16 +814,16 @@ QPDF::initializeEncryption() | ||
| 814 | (encryption_dict.getKey("/Filter").getName() == "/Standard"))) { | 814 | (encryption_dict.getKey("/Filter").getName() == "/Standard"))) { |
| 815 | throw QPDFExc( | 815 | throw QPDFExc( |
| 816 | qpdf_e_unsupported, | 816 | qpdf_e_unsupported, |
| 817 | - this->m->file->getName(), | 817 | + m->file->getName(), |
| 818 | "encryption dictionary", | 818 | "encryption dictionary", |
| 819 | - this->m->file->getLastOffset(), | 819 | + m->file->getLastOffset(), |
| 820 | "unsupported encryption filter"); | 820 | "unsupported encryption filter"); |
| 821 | } | 821 | } |
| 822 | if (!encryption_dict.getKey("/SubFilter").isNull()) { | 822 | if (!encryption_dict.getKey("/SubFilter").isNull()) { |
| 823 | warn( | 823 | warn( |
| 824 | qpdf_e_unsupported, | 824 | qpdf_e_unsupported, |
| 825 | "encryption dictionary", | 825 | "encryption dictionary", |
| 826 | - this->m->file->getLastOffset(), | 826 | + m->file->getLastOffset(), |
| 827 | "file uses encryption SubFilters, which qpdf does not support"); | 827 | "file uses encryption SubFilters, which qpdf does not support"); |
| 828 | } | 828 | } |
| 829 | 829 | ||
| @@ -850,16 +850,16 @@ QPDF::initializeEncryption() | @@ -850,16 +850,16 @@ QPDF::initializeEncryption() | ||
| 850 | ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) { | 850 | ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) { |
| 851 | throw QPDFExc( | 851 | throw QPDFExc( |
| 852 | qpdf_e_unsupported, | 852 | qpdf_e_unsupported, |
| 853 | - this->m->file->getName(), | 853 | + m->file->getName(), |
| 854 | "encryption dictionary", | 854 | "encryption dictionary", |
| 855 | - this->m->file->getLastOffset(), | 855 | + m->file->getLastOffset(), |
| 856 | "Unsupported /R or /V in encryption dictionary; R = " + | 856 | "Unsupported /R or /V in encryption dictionary; R = " + |
| 857 | std::to_string(R) + " (max 6), V = " + std::to_string(V) + | 857 | std::to_string(R) + " (max 6), V = " + std::to_string(V) + |
| 858 | " (max 5)"); | 858 | " (max 5)"); |
| 859 | } | 859 | } |
| 860 | 860 | ||
| 861 | - this->m->encp->encryption_V = V; | ||
| 862 | - this->m->encp->encryption_R = R; | 861 | + m->encp->encryption_V = V; |
| 862 | + m->encp->encryption_R = R; | ||
| 863 | 863 | ||
| 864 | // OE, UE, and Perms are only present if V >= 5. | 864 | // OE, UE, and Perms are only present if V >= 5. |
| 865 | std::string OE; | 865 | std::string OE; |
| @@ -916,9 +916,9 @@ QPDF::initializeEncryption() | @@ -916,9 +916,9 @@ QPDF::initializeEncryption() | ||
| 916 | Length = 128; | 916 | Length = 128; |
| 917 | } | 917 | } |
| 918 | 918 | ||
| 919 | - this->m->encp->encrypt_metadata = true; | 919 | + m->encp->encrypt_metadata = true; |
| 920 | if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) { | 920 | if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) { |
| 921 | - this->m->encp->encrypt_metadata = | 921 | + m->encp->encrypt_metadata = |
| 922 | encryption_dict.getKey("/EncryptMetadata").getBoolValue(); | 922 | encryption_dict.getKey("/EncryptMetadata").getBoolValue(); |
| 923 | } | 923 | } |
| 924 | 924 | ||
| @@ -945,15 +945,15 @@ QPDF::initializeEncryption() | @@ -945,15 +945,15 @@ QPDF::initializeEncryption() | ||
| 945 | method = e_unknown; | 945 | method = e_unknown; |
| 946 | } | 946 | } |
| 947 | } | 947 | } |
| 948 | - this->m->encp->crypt_filters[filter] = method; | 948 | + m->encp->crypt_filters[filter] = method; |
| 949 | } | 949 | } |
| 950 | } | 950 | } |
| 951 | 951 | ||
| 952 | QPDFObjectHandle StmF = encryption_dict.getKey("/StmF"); | 952 | QPDFObjectHandle StmF = encryption_dict.getKey("/StmF"); |
| 953 | QPDFObjectHandle StrF = encryption_dict.getKey("/StrF"); | 953 | QPDFObjectHandle StrF = encryption_dict.getKey("/StrF"); |
| 954 | QPDFObjectHandle EFF = encryption_dict.getKey("/EFF"); | 954 | QPDFObjectHandle EFF = encryption_dict.getKey("/EFF"); |
| 955 | - this->m->encp->cf_stream = interpretCF(this->m->encp, StmF); | ||
| 956 | - this->m->encp->cf_string = interpretCF(this->m->encp, StrF); | 955 | + m->encp->cf_stream = interpretCF(m->encp, StmF); |
| 956 | + m->encp->cf_string = interpretCF(m->encp, StrF); | ||
| 957 | if (EFF.isName()) { | 957 | if (EFF.isName()) { |
| 958 | // qpdf does not use this for anything other than | 958 | // qpdf does not use this for anything other than |
| 959 | // informational purposes. This is intended to instruct | 959 | // informational purposes. This is intended to instruct |
| @@ -969,9 +969,9 @@ QPDF::initializeEncryption() | @@ -969,9 +969,9 @@ QPDF::initializeEncryption() | ||
| 969 | // at a file generated by something else, such as Acrobat | 969 | // at a file generated by something else, such as Acrobat |
| 970 | // when specifying that only attachments should be | 970 | // when specifying that only attachments should be |
| 971 | // encrypted. | 971 | // encrypted. |
| 972 | - this->m->encp->cf_file = interpretCF(this->m->encp, EFF); | 972 | + m->encp->cf_file = interpretCF(m->encp, EFF); |
| 973 | } else { | 973 | } else { |
| 974 | - this->m->encp->cf_file = this->m->encp->cf_stream; | 974 | + m->encp->cf_file = m->encp->cf_stream; |
| 975 | } | 975 | } |
| 976 | } | 976 | } |
| 977 | 977 | ||
| @@ -986,59 +986,51 @@ QPDF::initializeEncryption() | @@ -986,59 +986,51 @@ QPDF::initializeEncryption() | ||
| 986 | UE, | 986 | UE, |
| 987 | Perms, | 987 | Perms, |
| 988 | id1, | 988 | id1, |
| 989 | - this->m->encp->encrypt_metadata); | ||
| 990 | - if (this->m->provided_password_is_hex_key) { | 989 | + m->encp->encrypt_metadata); |
| 990 | + if (m->provided_password_is_hex_key) { | ||
| 991 | // ignore passwords in file | 991 | // ignore passwords in file |
| 992 | } else { | 992 | } else { |
| 993 | - this->m->encp->owner_password_matched = check_owner_password( | ||
| 994 | - this->m->encp->user_password, | ||
| 995 | - this->m->encp->provided_password, | ||
| 996 | - data); | ||
| 997 | - if (this->m->encp->owner_password_matched && (V < 5)) { | 993 | + m->encp->owner_password_matched = check_owner_password( |
| 994 | + m->encp->user_password, m->encp->provided_password, data); | ||
| 995 | + if (m->encp->owner_password_matched && (V < 5)) { | ||
| 998 | // password supplied was owner password; user_password has | 996 | // password supplied was owner password; user_password has |
| 999 | // been initialized for V < 5 | 997 | // been initialized for V < 5 |
| 1000 | - if (getTrimmedUserPassword() == this->m->encp->provided_password) { | ||
| 1001 | - this->m->encp->user_password_matched = true; | 998 | + if (getTrimmedUserPassword() == m->encp->provided_password) { |
| 999 | + m->encp->user_password_matched = true; | ||
| 1002 | QTC::TC("qpdf", "QPDF_encryption user matches owner V < 5"); | 1000 | QTC::TC("qpdf", "QPDF_encryption user matches owner V < 5"); |
| 1003 | } | 1001 | } |
| 1004 | } else { | 1002 | } else { |
| 1005 | - this->m->encp->user_password_matched = | ||
| 1006 | - check_user_password(this->m->encp->provided_password, data); | ||
| 1007 | - if (this->m->encp->user_password_matched) { | ||
| 1008 | - this->m->encp->user_password = this->m->encp->provided_password; | 1003 | + m->encp->user_password_matched = |
| 1004 | + check_user_password(m->encp->provided_password, data); | ||
| 1005 | + if (m->encp->user_password_matched) { | ||
| 1006 | + m->encp->user_password = m->encp->provided_password; | ||
| 1009 | } | 1007 | } |
| 1010 | } | 1008 | } |
| 1011 | - if (this->m->encp->user_password_matched && | ||
| 1012 | - this->m->encp->owner_password_matched) { | 1009 | + if (m->encp->user_password_matched && m->encp->owner_password_matched) { |
| 1013 | QTC::TC("qpdf", "QPDF_encryption same password", (V < 5) ? 0 : 1); | 1010 | QTC::TC("qpdf", "QPDF_encryption same password", (V < 5) ? 0 : 1); |
| 1014 | } | 1011 | } |
| 1015 | - if (!(this->m->encp->owner_password_matched || | ||
| 1016 | - this->m->encp->user_password_matched)) { | 1012 | + if (!(m->encp->owner_password_matched || |
| 1013 | + m->encp->user_password_matched)) { | ||
| 1017 | throw QPDFExc( | 1014 | throw QPDFExc( |
| 1018 | - qpdf_e_password, | ||
| 1019 | - this->m->file->getName(), | ||
| 1020 | - "", | ||
| 1021 | - 0, | ||
| 1022 | - "invalid password"); | 1015 | + qpdf_e_password, m->file->getName(), "", 0, "invalid password"); |
| 1023 | } | 1016 | } |
| 1024 | } | 1017 | } |
| 1025 | 1018 | ||
| 1026 | - if (this->m->provided_password_is_hex_key) { | ||
| 1027 | - this->m->encp->encryption_key = | ||
| 1028 | - QUtil::hex_decode(this->m->encp->provided_password); | 1019 | + if (m->provided_password_is_hex_key) { |
| 1020 | + m->encp->encryption_key = QUtil::hex_decode(m->encp->provided_password); | ||
| 1029 | } else if (V < 5) { | 1021 | } else if (V < 5) { |
| 1030 | // For V < 5, the user password is encrypted with the owner | 1022 | // For V < 5, the user password is encrypted with the owner |
| 1031 | // password, and the user password is always used for | 1023 | // password, and the user password is always used for |
| 1032 | // computing the encryption key. | 1024 | // computing the encryption key. |
| 1033 | - this->m->encp->encryption_key = | ||
| 1034 | - compute_encryption_key(this->m->encp->user_password, data); | 1025 | + m->encp->encryption_key = |
| 1026 | + compute_encryption_key(m->encp->user_password, data); | ||
| 1035 | } else { | 1027 | } else { |
| 1036 | // For V >= 5, either password can be used independently to | 1028 | // For V >= 5, either password can be used independently to |
| 1037 | // compute the encryption key, and neither password can be | 1029 | // compute the encryption key, and neither password can be |
| 1038 | // used to recover the other. | 1030 | // used to recover the other. |
| 1039 | bool perms_valid; | 1031 | bool perms_valid; |
| 1040 | - this->m->encp->encryption_key = recover_encryption_key_with_password( | ||
| 1041 | - this->m->encp->provided_password, data, perms_valid); | 1032 | + m->encp->encryption_key = recover_encryption_key_with_password( |
| 1033 | + m->encp->provided_password, data, perms_valid); | ||
| 1042 | if (!perms_valid) { | 1034 | if (!perms_valid) { |
| 1043 | warn(damagedPDF( | 1035 | warn(damagedPDF( |
| 1044 | "encryption dictionary", | 1036 | "encryption dictionary", |
| @@ -1080,8 +1072,8 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | @@ -1080,8 +1072,8 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | ||
| 1080 | return; | 1072 | return; |
| 1081 | } | 1073 | } |
| 1082 | bool use_aes = false; | 1074 | bool use_aes = false; |
| 1083 | - if (this->m->encp->encryption_V >= 4) { | ||
| 1084 | - switch (this->m->encp->cf_string) { | 1075 | + if (m->encp->encryption_V >= 4) { |
| 1076 | + switch (m->encp->cf_string) { | ||
| 1085 | case e_none: | 1077 | case e_none: |
| 1086 | return; | 1078 | return; |
| 1087 | 1079 | ||
| @@ -1102,13 +1094,13 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | @@ -1102,13 +1094,13 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | ||
| 1102 | "/Encrypt dictionary); strings may be decrypted improperly")); | 1094 | "/Encrypt dictionary); strings may be decrypted improperly")); |
| 1103 | // To avoid repeated warnings, reset cf_string. Assume | 1095 | // To avoid repeated warnings, reset cf_string. Assume |
| 1104 | // we'd want to use AES if V == 4. | 1096 | // we'd want to use AES if V == 4. |
| 1105 | - this->m->encp->cf_string = e_aes; | 1097 | + m->encp->cf_string = e_aes; |
| 1106 | use_aes = true; | 1098 | use_aes = true; |
| 1107 | break; | 1099 | break; |
| 1108 | } | 1100 | } |
| 1109 | } | 1101 | } |
| 1110 | 1102 | ||
| 1111 | - std::string key = getKeyForObject(this->m->encp, og, use_aes); | 1103 | + std::string key = getKeyForObject(m->encp, og, use_aes); |
| 1112 | try { | 1104 | try { |
| 1113 | if (use_aes) { | 1105 | if (use_aes) { |
| 1114 | QTC::TC("qpdf", "QPDF_encryption aes decode string"); | 1106 | QTC::TC("qpdf", "QPDF_encryption aes decode string"); |
| @@ -1320,13 +1312,13 @@ QPDF::compute_encryption_parameters_V5( | @@ -1320,13 +1312,13 @@ QPDF::compute_encryption_parameters_V5( | ||
| 1320 | std::string const& | 1312 | std::string const& |
| 1321 | QPDF::getPaddedUserPassword() const | 1313 | QPDF::getPaddedUserPassword() const |
| 1322 | { | 1314 | { |
| 1323 | - return this->m->encp->user_password; | 1315 | + return m->encp->user_password; |
| 1324 | } | 1316 | } |
| 1325 | 1317 | ||
| 1326 | std::string | 1318 | std::string |
| 1327 | QPDF::getTrimmedUserPassword() const | 1319 | QPDF::getTrimmedUserPassword() const |
| 1328 | { | 1320 | { |
| 1329 | - std::string result = this->m->encp->user_password; | 1321 | + std::string result = m->encp->user_password; |
| 1330 | trim_user_password(result); | 1322 | trim_user_password(result); |
| 1331 | return result; | 1323 | return result; |
| 1332 | } | 1324 | } |
| @@ -1334,13 +1326,13 @@ QPDF::getTrimmedUserPassword() const | @@ -1334,13 +1326,13 @@ QPDF::getTrimmedUserPassword() const | ||
| 1334 | std::string | 1326 | std::string |
| 1335 | QPDF::getEncryptionKey() const | 1327 | QPDF::getEncryptionKey() const |
| 1336 | { | 1328 | { |
| 1337 | - return this->m->encp->encryption_key; | 1329 | + return m->encp->encryption_key; |
| 1338 | } | 1330 | } |
| 1339 | 1331 | ||
| 1340 | bool | 1332 | bool |
| 1341 | QPDF::isEncrypted() const | 1333 | QPDF::isEncrypted() const |
| 1342 | { | 1334 | { |
| 1343 | - return this->m->encp->encrypted; | 1335 | + return m->encp->encrypted; |
| 1344 | } | 1336 | } |
| 1345 | 1337 | ||
| 1346 | bool | 1338 | bool |
| @@ -1360,7 +1352,7 @@ QPDF::isEncrypted( | @@ -1360,7 +1352,7 @@ QPDF::isEncrypted( | ||
| 1360 | encryption_method_e& string_method, | 1352 | encryption_method_e& string_method, |
| 1361 | encryption_method_e& file_method) | 1353 | encryption_method_e& file_method) |
| 1362 | { | 1354 | { |
| 1363 | - if (this->m->encp->encrypted) { | 1355 | + if (m->encp->encrypted) { |
| 1364 | QPDFObjectHandle trailer = getTrailer(); | 1356 | QPDFObjectHandle trailer = getTrailer(); |
| 1365 | QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); | 1357 | QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); |
| 1366 | QPDFObjectHandle Pkey = encrypt.getKey("/P"); | 1358 | QPDFObjectHandle Pkey = encrypt.getKey("/P"); |
| @@ -1369,9 +1361,9 @@ QPDF::isEncrypted( | @@ -1369,9 +1361,9 @@ QPDF::isEncrypted( | ||
| 1369 | P = static_cast<int>(Pkey.getIntValue()); | 1361 | P = static_cast<int>(Pkey.getIntValue()); |
| 1370 | R = Rkey.getIntValueAsInt(); | 1362 | R = Rkey.getIntValueAsInt(); |
| 1371 | V = Vkey.getIntValueAsInt(); | 1363 | V = Vkey.getIntValueAsInt(); |
| 1372 | - stream_method = this->m->encp->cf_stream; | ||
| 1373 | - string_method = this->m->encp->cf_string; | ||
| 1374 | - file_method = this->m->encp->cf_file; | 1364 | + stream_method = m->encp->cf_stream; |
| 1365 | + string_method = m->encp->cf_string; | ||
| 1366 | + file_method = m->encp->cf_file; | ||
| 1375 | return true; | 1367 | return true; |
| 1376 | } else { | 1368 | } else { |
| 1377 | return false; | 1369 | return false; |
| @@ -1381,13 +1373,13 @@ QPDF::isEncrypted( | @@ -1381,13 +1373,13 @@ QPDF::isEncrypted( | ||
| 1381 | bool | 1373 | bool |
| 1382 | QPDF::ownerPasswordMatched() const | 1374 | QPDF::ownerPasswordMatched() const |
| 1383 | { | 1375 | { |
| 1384 | - return this->m->encp->owner_password_matched; | 1376 | + return m->encp->owner_password_matched; |
| 1385 | } | 1377 | } |
| 1386 | 1378 | ||
| 1387 | bool | 1379 | bool |
| 1388 | QPDF::userPasswordMatched() const | 1380 | QPDF::userPasswordMatched() const |
| 1389 | { | 1381 | { |
| 1390 | - return this->m->encp->user_password_matched; | 1382 | + return m->encp->user_password_matched; |
| 1391 | } | 1383 | } |
| 1392 | 1384 | ||
| 1393 | static bool | 1385 | static bool |
libqpdf/QPDF_linearization.cc
| @@ -67,7 +67,7 @@ load_vector_vector( | @@ -67,7 +67,7 @@ load_vector_vector( | ||
| 67 | void | 67 | void |
| 68 | QPDF::linearizationWarning(std::string_view msg) | 68 | QPDF::linearizationWarning(std::string_view msg) |
| 69 | { | 69 | { |
| 70 | - this->m->linearization_warnings = true; | 70 | + m->linearization_warnings = true; |
| 71 | warn(qpdf_e_linearization, "", 0, std::string(msg)); | 71 | warn(qpdf_e_linearization, "", 0, std::string(msg)); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| @@ -91,7 +91,7 @@ QPDF::isLinearized() | @@ -91,7 +91,7 @@ QPDF::isLinearized() | ||
| 91 | { | 91 | { |
| 92 | // If the first object in the file is a dictionary with a suitable | 92 | // If the first object in the file is a dictionary with a suitable |
| 93 | // /Linearized key and has an /L key that accurately indicates the | 93 | // /Linearized key and has an /L key that accurately indicates the |
| 94 | - // file size, initialize this->m->lindict and return true. | 94 | + // file size, initialize m->lindict and return true. |
| 95 | 95 | ||
| 96 | // A linearized PDF spec's first object will be contained within | 96 | // A linearized PDF spec's first object will be contained within |
| 97 | // the first 1024 bytes of the file and will be a dictionary with | 97 | // the first 1024 bytes of the file and will be a dictionary with |
| @@ -105,9 +105,9 @@ QPDF::isLinearized() | @@ -105,9 +105,9 @@ QPDF::isLinearized() | ||
| 105 | 105 | ||
| 106 | auto b = std::make_unique<char[]>(tbuf_size); | 106 | auto b = std::make_unique<char[]>(tbuf_size); |
| 107 | char* buf = b.get(); | 107 | char* buf = b.get(); |
| 108 | - this->m->file->seek(0, SEEK_SET); | 108 | + m->file->seek(0, SEEK_SET); |
| 109 | memset(buf, '\0', tbuf_size); | 109 | memset(buf, '\0', tbuf_size); |
| 110 | - this->m->file->read(buf, tbuf_size - 1); | 110 | + m->file->read(buf, tbuf_size - 1); |
| 111 | 111 | ||
| 112 | int lindict_obj = -1; | 112 | int lindict_obj = -1; |
| 113 | char* p = buf; | 113 | char* p = buf; |
| @@ -121,12 +121,12 @@ QPDF::isLinearized() | @@ -121,12 +121,12 @@ QPDF::isLinearized() | ||
| 121 | } | 121 | } |
| 122 | // Seek to the digit. Then skip over digits for a potential | 122 | // Seek to the digit. Then skip over digits for a potential |
| 123 | // next iteration. | 123 | // next iteration. |
| 124 | - this->m->file->seek(p - buf, SEEK_SET); | 124 | + m->file->seek(p - buf, SEEK_SET); |
| 125 | while (((p - buf) < tbuf_size) && QUtil::is_digit(*p)) { | 125 | while (((p - buf) < tbuf_size) && QUtil::is_digit(*p)) { |
| 126 | ++p; | 126 | ++p; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | - QPDFTokenizer::Token t1 = readToken(this->m->file); | 129 | + QPDFTokenizer::Token t1 = readToken(m->file); |
| 130 | if (t1.isInteger() && readToken(m->file).isInteger() && | 130 | if (t1.isInteger() && readToken(m->file).isInteger() && |
| 131 | readToken(m->file).isWord("obj") && | 131 | readToken(m->file).isWord("obj") && |
| 132 | (readToken(m->file).getType() == QPDFTokenizer::tt_dict_open)) { | 132 | (readToken(m->file).getType() == QPDFTokenizer::tt_dict_open)) { |
| @@ -151,16 +151,16 @@ QPDF::isLinearized() | @@ -151,16 +151,16 @@ QPDF::isLinearized() | ||
| 151 | QPDFObjectHandle L = candidate.getKey("/L"); | 151 | QPDFObjectHandle L = candidate.getKey("/L"); |
| 152 | if (L.isInteger()) { | 152 | if (L.isInteger()) { |
| 153 | qpdf_offset_t Li = L.getIntValue(); | 153 | qpdf_offset_t Li = L.getIntValue(); |
| 154 | - this->m->file->seek(0, SEEK_END); | ||
| 155 | - if (Li != this->m->file->tell()) { | 154 | + m->file->seek(0, SEEK_END); |
| 155 | + if (Li != m->file->tell()) { | ||
| 156 | QTC::TC("qpdf", "QPDF /L mismatch"); | 156 | QTC::TC("qpdf", "QPDF /L mismatch"); |
| 157 | return false; | 157 | return false; |
| 158 | } else { | 158 | } else { |
| 159 | - this->m->linp.file_size = Li; | 159 | + m->linp.file_size = Li; |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | - this->m->lindict = candidate; | 163 | + m->lindict = candidate; |
| 164 | 164 | ||
| 165 | return true; | 165 | return true; |
| 166 | } | 166 | } |
| @@ -177,12 +177,12 @@ QPDF::readLinearizationData() | @@ -177,12 +177,12 @@ QPDF::readLinearizationData() | ||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | // /L is read and stored in linp by isLinearized() | 179 | // /L is read and stored in linp by isLinearized() |
| 180 | - QPDFObjectHandle H = this->m->lindict.getKey("/H"); | ||
| 181 | - QPDFObjectHandle O = this->m->lindict.getKey("/O"); | ||
| 182 | - QPDFObjectHandle E = this->m->lindict.getKey("/E"); | ||
| 183 | - QPDFObjectHandle N = this->m->lindict.getKey("/N"); | ||
| 184 | - QPDFObjectHandle T = this->m->lindict.getKey("/T"); | ||
| 185 | - QPDFObjectHandle P = this->m->lindict.getKey("/P"); | 180 | + QPDFObjectHandle H = m->lindict.getKey("/H"); |
| 181 | + QPDFObjectHandle O = m->lindict.getKey("/O"); | ||
| 182 | + QPDFObjectHandle E = m->lindict.getKey("/E"); | ||
| 183 | + QPDFObjectHandle N = m->lindict.getKey("/N"); | ||
| 184 | + QPDFObjectHandle T = m->lindict.getKey("/T"); | ||
| 185 | + QPDFObjectHandle P = m->lindict.getKey("/P"); | ||
| 186 | 186 | ||
| 187 | if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() && | 187 | if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() && |
| 188 | T.isInteger() && (P.isInteger() || P.isNull()))) { | 188 | T.isInteger() && (P.isInteger() || P.isNull()))) { |
| @@ -243,13 +243,13 @@ QPDF::readLinearizationData() | @@ -243,13 +243,13 @@ QPDF::readLinearizationData() | ||
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | // file_size initialized by isLinearized() | 245 | // file_size initialized by isLinearized() |
| 246 | - this->m->linp.first_page_object = O.getIntValueAsInt(); | ||
| 247 | - this->m->linp.first_page_end = E.getIntValue(); | ||
| 248 | - this->m->linp.npages = N.getIntValueAsInt(); | ||
| 249 | - this->m->linp.xref_zero_offset = T.getIntValue(); | ||
| 250 | - this->m->linp.first_page = first_page; | ||
| 251 | - this->m->linp.H_offset = H0_offset; | ||
| 252 | - this->m->linp.H_length = H0_length; | 246 | + m->linp.first_page_object = O.getIntValueAsInt(); |
| 247 | + m->linp.first_page_end = E.getIntValue(); | ||
| 248 | + m->linp.npages = N.getIntValueAsInt(); | ||
| 249 | + m->linp.xref_zero_offset = T.getIntValue(); | ||
| 250 | + m->linp.first_page = first_page; | ||
| 251 | + m->linp.H_offset = H0_offset; | ||
| 252 | + m->linp.H_length = H0_length; | ||
| 253 | 253 | ||
| 254 | // Read hint streams | 254 | // Read hint streams |
| 255 | 255 | ||
| @@ -296,7 +296,7 @@ QPDF::readLinearizationData() | @@ -296,7 +296,7 @@ QPDF::readLinearizationData() | ||
| 296 | "/O (outline) offset is out of bounds"); | 296 | "/O (outline) offset is out of bounds"); |
| 297 | } | 297 | } |
| 298 | readHGeneric( | 298 | readHGeneric( |
| 299 | - BitStream(h_buf + HOi, h_size - toS(HOi)), this->m->outline_hints); | 299 | + BitStream(h_buf + HOi, h_size - toS(HOi)), m->outline_hints); |
| 300 | } | 300 | } |
| 301 | } | 301 | } |
| 302 | 302 | ||
| @@ -311,7 +311,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | @@ -311,7 +311,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | ||
| 311 | QPDFObjGen(0, 0), | 311 | QPDFObjGen(0, 0), |
| 312 | og, | 312 | og, |
| 313 | false); | 313 | false); |
| 314 | - ObjCache& oc = this->m->obj_cache[og]; | 314 | + ObjCache& oc = m->obj_cache[og]; |
| 315 | qpdf_offset_t min_end_offset = oc.end_before_space; | 315 | qpdf_offset_t min_end_offset = oc.end_before_space; |
| 316 | qpdf_offset_t max_end_offset = oc.end_after_space; | 316 | qpdf_offset_t max_end_offset = oc.end_after_space; |
| 317 | if (!H.isStream()) { | 317 | if (!H.isStream()) { |
| @@ -331,7 +331,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | @@ -331,7 +331,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | ||
| 331 | QTC::TC("qpdf", "QPDF hint table length indirect"); | 331 | QTC::TC("qpdf", "QPDF hint table length indirect"); |
| 332 | // Force resolution | 332 | // Force resolution |
| 333 | (void)length_obj.getIntValue(); | 333 | (void)length_obj.getIntValue(); |
| 334 | - ObjCache& oc2 = this->m->obj_cache[length_obj.getObjGen()]; | 334 | + ObjCache& oc2 = m->obj_cache[length_obj.getObjGen()]; |
| 335 | min_end_offset = oc2.end_before_space; | 335 | min_end_offset = oc2.end_before_space; |
| 336 | max_end_offset = oc2.end_after_space; | 336 | max_end_offset = oc2.end_after_space; |
| 337 | } else { | 337 | } else { |
| @@ -356,7 +356,7 @@ QPDF::readHPageOffset(BitStream h) | @@ -356,7 +356,7 @@ QPDF::readHPageOffset(BitStream h) | ||
| 356 | // All comments referring to the PDF spec refer to the spec for | 356 | // All comments referring to the PDF spec refer to the spec for |
| 357 | // version 1.4. | 357 | // version 1.4. |
| 358 | 358 | ||
| 359 | - HPageOffset& t = this->m->page_offset_hints; | 359 | + HPageOffset& t = m->page_offset_hints; |
| 360 | 360 | ||
| 361 | t.min_nobjects = h.getBitsInt(32); // 1 | 361 | t.min_nobjects = h.getBitsInt(32); // 1 |
| 362 | t.first_page_offset = h.getBitsInt(32); // 2 | 362 | t.first_page_offset = h.getBitsInt(32); // 2 |
| @@ -374,7 +374,7 @@ QPDF::readHPageOffset(BitStream h) | @@ -374,7 +374,7 @@ QPDF::readHPageOffset(BitStream h) | ||
| 374 | 374 | ||
| 375 | std::vector<HPageOffsetEntry>& entries = t.entries; | 375 | std::vector<HPageOffsetEntry>& entries = t.entries; |
| 376 | entries.clear(); | 376 | entries.clear(); |
| 377 | - int nitems = this->m->linp.npages; | 377 | + int nitems = m->linp.npages; |
| 378 | load_vector_int( | 378 | load_vector_int( |
| 379 | h, | 379 | h, |
| 380 | nitems, | 380 | nitems, |
| @@ -424,7 +424,7 @@ QPDF::readHPageOffset(BitStream h) | @@ -424,7 +424,7 @@ QPDF::readHPageOffset(BitStream h) | ||
| 424 | void | 424 | void |
| 425 | QPDF::readHSharedObject(BitStream h) | 425 | QPDF::readHSharedObject(BitStream h) |
| 426 | { | 426 | { |
| 427 | - HSharedObject& t = this->m->shared_object_hints; | 427 | + HSharedObject& t = m->shared_object_hints; |
| 428 | 428 | ||
| 429 | t.first_shared_obj = h.getBitsInt(32); // 1 | 429 | t.first_shared_obj = h.getBitsInt(32); // 1 |
| 430 | t.first_shared_offset = h.getBitsInt(32); // 2 | 430 | t.first_shared_offset = h.getBitsInt(32); // 2 |
| @@ -485,7 +485,7 @@ QPDF::checkLinearizationInternal() | @@ -485,7 +485,7 @@ QPDF::checkLinearizationInternal() | ||
| 485 | 485 | ||
| 486 | // Check all values in linearization parameter dictionary | 486 | // Check all values in linearization parameter dictionary |
| 487 | 487 | ||
| 488 | - LinParameters& p = this->m->linp; | 488 | + LinParameters& p = m->linp; |
| 489 | 489 | ||
| 490 | // L: file size in bytes -- checked by isLinearized | 490 | // L: file size in bytes -- checked by isLinearized |
| 491 | 491 | ||
| @@ -506,7 +506,7 @@ QPDF::checkLinearizationInternal() | @@ -506,7 +506,7 @@ QPDF::checkLinearizationInternal() | ||
| 506 | for (size_t i = 0; i < toS(npages); ++i) { | 506 | for (size_t i = 0; i < toS(npages); ++i) { |
| 507 | QPDFObjectHandle const& page = pages.at(i); | 507 | QPDFObjectHandle const& page = pages.at(i); |
| 508 | QPDFObjGen og(page.getObjGen()); | 508 | QPDFObjGen og(page.getObjGen()); |
| 509 | - if (this->m->xref_table[og].getType() == 2) { | 509 | + if (m->xref_table[og].getType() == 2) { |
| 510 | linearizationWarning( | 510 | linearizationWarning( |
| 511 | "page dictionary for page " + std::to_string(i) + | 511 | "page dictionary for page " + std::to_string(i) + |
| 512 | " is compressed"); | 512 | " is compressed"); |
| @@ -514,22 +514,22 @@ QPDF::checkLinearizationInternal() | @@ -514,22 +514,22 @@ QPDF::checkLinearizationInternal() | ||
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | // T: offset of whitespace character preceding xref entry for object 0 | 516 | // T: offset of whitespace character preceding xref entry for object 0 |
| 517 | - this->m->file->seek(p.xref_zero_offset, SEEK_SET); | 517 | + m->file->seek(p.xref_zero_offset, SEEK_SET); |
| 518 | while (true) { | 518 | while (true) { |
| 519 | char ch; | 519 | char ch; |
| 520 | - this->m->file->read(&ch, 1); | 520 | + m->file->read(&ch, 1); |
| 521 | if (!((ch == ' ') || (ch == '\r') || (ch == '\n'))) { | 521 | if (!((ch == ' ') || (ch == '\r') || (ch == '\n'))) { |
| 522 | - this->m->file->seek(-1, SEEK_CUR); | 522 | + m->file->seek(-1, SEEK_CUR); |
| 523 | break; | 523 | break; |
| 524 | } | 524 | } |
| 525 | } | 525 | } |
| 526 | - if (this->m->file->tell() != this->m->first_xref_item_offset) { | 526 | + if (m->file->tell() != m->first_xref_item_offset) { |
| 527 | QTC::TC("qpdf", "QPDF err /T mismatch"); | 527 | QTC::TC("qpdf", "QPDF err /T mismatch"); |
| 528 | linearizationWarning( | 528 | linearizationWarning( |
| 529 | "space before first xref item (/T) mismatch " | 529 | "space before first xref item (/T) mismatch " |
| 530 | "(computed = " + | 530 | "(computed = " + |
| 531 | - std::to_string(this->m->first_xref_item_offset) + | ||
| 532 | - "; file = " + std::to_string(this->m->file->tell())); | 531 | + std::to_string(m->first_xref_item_offset) + |
| 532 | + "; file = " + std::to_string(m->file->tell())); | ||
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | // P: first page number -- Implementation note 124 says Acrobat | 535 | // P: first page number -- Implementation note 124 says Acrobat |
| @@ -540,7 +540,7 @@ QPDF::checkLinearizationInternal() | @@ -540,7 +540,7 @@ QPDF::checkLinearizationInternal() | ||
| 540 | // at the end of the containing xref section if any object streams | 540 | // at the end of the containing xref section if any object streams |
| 541 | // are in use. | 541 | // are in use. |
| 542 | 542 | ||
| 543 | - if (this->m->uncompressed_after_compressed) { | 543 | + if (m->uncompressed_after_compressed) { |
| 544 | linearizationWarning( | 544 | linearizationWarning( |
| 545 | "linearized file contains an uncompressed object" | 545 | "linearized file contains an uncompressed object" |
| 546 | " after a compressed one in a cross-reference stream"); | 546 | " after a compressed one in a cross-reference stream"); |
| @@ -553,7 +553,7 @@ QPDF::checkLinearizationInternal() | @@ -553,7 +553,7 @@ QPDF::checkLinearizationInternal() | ||
| 553 | // uncompressed. | 553 | // uncompressed. |
| 554 | { // local scope | 554 | { // local scope |
| 555 | std::map<int, int> object_stream_data; | 555 | std::map<int, int> object_stream_data; |
| 556 | - for (auto const& iter: this->m->xref_table) { | 556 | + for (auto const& iter: m->xref_table) { |
| 557 | QPDFObjGen const& og = iter.first; | 557 | QPDFObjGen const& og = iter.first; |
| 558 | QPDFXRefEntry const& entry = iter.second; | 558 | QPDFXRefEntry const& entry = iter.second; |
| 559 | if (entry.getType() == 2) { | 559 | if (entry.getType() == 2) { |
| @@ -575,18 +575,18 @@ QPDF::checkLinearizationInternal() | @@ -575,18 +575,18 @@ QPDF::checkLinearizationInternal() | ||
| 575 | // agree with pdlin. As of this writing, the test suite doesn't | 575 | // agree with pdlin. As of this writing, the test suite doesn't |
| 576 | // contain any files with threads. | 576 | // contain any files with threads. |
| 577 | 577 | ||
| 578 | - if (this->m->part6.empty()) { | 578 | + if (m->part6.empty()) { |
| 579 | stopOnError("linearization part 6 unexpectedly empty"); | 579 | stopOnError("linearization part 6 unexpectedly empty"); |
| 580 | } | 580 | } |
| 581 | qpdf_offset_t min_E = -1; | 581 | qpdf_offset_t min_E = -1; |
| 582 | qpdf_offset_t max_E = -1; | 582 | qpdf_offset_t max_E = -1; |
| 583 | - for (auto const& oh: this->m->part6) { | 583 | + for (auto const& oh: m->part6) { |
| 584 | QPDFObjGen og(oh.getObjGen()); | 584 | QPDFObjGen og(oh.getObjGen()); |
| 585 | - if (this->m->obj_cache.count(og) == 0) { | 585 | + if (m->obj_cache.count(og) == 0) { |
| 586 | // All objects have to have been dereferenced to be classified. | 586 | // All objects have to have been dereferenced to be classified. |
| 587 | throw std::logic_error("linearization part6 object not in cache"); | 587 | throw std::logic_error("linearization part6 object not in cache"); |
| 588 | } | 588 | } |
| 589 | - ObjCache const& oc = this->m->obj_cache[og]; | 589 | + ObjCache const& oc = m->obj_cache[og]; |
| 590 | min_E = std::max(min_E, oc.end_before_space); | 590 | min_E = std::max(min_E, oc.end_before_space); |
| 591 | max_E = std::max(max_E, oc.end_after_space); | 591 | max_E = std::max(max_E, oc.end_after_space); |
| 592 | } | 592 | } |
| @@ -605,21 +605,21 @@ QPDF::checkLinearizationInternal() | @@ -605,21 +605,21 @@ QPDF::checkLinearizationInternal() | ||
| 605 | checkHPageOffset(pages, shared_idx_to_obj); | 605 | checkHPageOffset(pages, shared_idx_to_obj); |
| 606 | checkHOutlines(); | 606 | checkHOutlines(); |
| 607 | 607 | ||
| 608 | - return !this->m->linearization_warnings; | 608 | + return !m->linearization_warnings; |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | qpdf_offset_t | 611 | qpdf_offset_t |
| 612 | QPDF::maxEnd(ObjUser const& ou) | 612 | QPDF::maxEnd(ObjUser const& ou) |
| 613 | { | 613 | { |
| 614 | - if (this->m->obj_user_to_objects.count(ou) == 0) { | 614 | + if (m->obj_user_to_objects.count(ou) == 0) { |
| 615 | stopOnError("no entry in object user table for requested object user"); | 615 | stopOnError("no entry in object user table for requested object user"); |
| 616 | } | 616 | } |
| 617 | qpdf_offset_t end = 0; | 617 | qpdf_offset_t end = 0; |
| 618 | - for (auto const& og: this->m->obj_user_to_objects[ou]) { | ||
| 619 | - if (this->m->obj_cache.count(og) == 0) { | 618 | + for (auto const& og: m->obj_user_to_objects[ou]) { |
| 619 | + if (m->obj_cache.count(og) == 0) { | ||
| 620 | stopOnError("unknown object referenced in object user table"); | 620 | stopOnError("unknown object referenced in object user table"); |
| 621 | } | 621 | } |
| 622 | - end = std::max(end, this->m->obj_cache[og].end_after_space); | 622 | + end = std::max(end, m->obj_cache[og].end_after_space); |
| 623 | } | 623 | } |
| 624 | return end; | 624 | return end; |
| 625 | } | 625 | } |
| @@ -627,7 +627,7 @@ QPDF::maxEnd(ObjUser const& ou) | @@ -627,7 +627,7 @@ QPDF::maxEnd(ObjUser const& ou) | ||
| 627 | qpdf_offset_t | 627 | qpdf_offset_t |
| 628 | QPDF::getLinearizationOffset(QPDFObjGen const& og) | 628 | QPDF::getLinearizationOffset(QPDFObjGen const& og) |
| 629 | { | 629 | { |
| 630 | - QPDFXRefEntry entry = this->m->xref_table[og]; | 630 | + QPDFXRefEntry entry = m->xref_table[og]; |
| 631 | qpdf_offset_t result = 0; | 631 | qpdf_offset_t result = 0; |
| 632 | switch (entry.getType()) { | 632 | switch (entry.getType()) { |
| 633 | case 1: | 633 | case 1: |
| @@ -667,18 +667,17 @@ QPDF::lengthNextN(int first_object, int n) | @@ -667,18 +667,17 @@ QPDF::lengthNextN(int first_object, int n) | ||
| 667 | int length = 0; | 667 | int length = 0; |
| 668 | for (int i = 0; i < n; ++i) { | 668 | for (int i = 0; i < n; ++i) { |
| 669 | QPDFObjGen og(first_object + i, 0); | 669 | QPDFObjGen og(first_object + i, 0); |
| 670 | - if (this->m->xref_table.count(og) == 0) { | 670 | + if (m->xref_table.count(og) == 0) { |
| 671 | linearizationWarning( | 671 | linearizationWarning( |
| 672 | "no xref table entry for " + std::to_string(first_object + i) + | 672 | "no xref table entry for " + std::to_string(first_object + i) + |
| 673 | " 0"); | 673 | " 0"); |
| 674 | } else { | 674 | } else { |
| 675 | - if (this->m->obj_cache.count(og) == 0) { | 675 | + if (m->obj_cache.count(og) == 0) { |
| 676 | stopOnError("found unknown object while" | 676 | stopOnError("found unknown object while" |
| 677 | " calculating length for linearization data"); | 677 | " calculating length for linearization data"); |
| 678 | } | 678 | } |
| 679 | - length += | ||
| 680 | - toI(this->m->obj_cache[og].end_after_space - | ||
| 681 | - getLinearizationOffset(og)); | 679 | + length += toI( |
| 680 | + m->obj_cache[og].end_after_space - getLinearizationOffset(og)); | ||
| 682 | } | 681 | } |
| 683 | } | 682 | } |
| 684 | return length; | 683 | return length; |
| @@ -708,9 +707,9 @@ QPDF::checkHPageOffset( | @@ -708,9 +707,9 @@ QPDF::checkHPageOffset( | ||
| 708 | 707 | ||
| 709 | int npages = toI(pages.size()); | 708 | int npages = toI(pages.size()); |
| 710 | qpdf_offset_t table_offset = | 709 | qpdf_offset_t table_offset = |
| 711 | - adjusted_offset(this->m->page_offset_hints.first_page_offset); | 710 | + adjusted_offset(m->page_offset_hints.first_page_offset); |
| 712 | QPDFObjGen first_page_og(pages.at(0).getObjGen()); | 711 | QPDFObjGen first_page_og(pages.at(0).getObjGen()); |
| 713 | - if (this->m->xref_table.count(first_page_og) == 0) { | 712 | + if (m->xref_table.count(first_page_og) == 0) { |
| 714 | stopOnError("supposed first page object is not known"); | 713 | stopOnError("supposed first page object is not known"); |
| 715 | } | 714 | } |
| 716 | qpdf_offset_t offset = getLinearizationOffset(first_page_og); | 715 | qpdf_offset_t offset = getLinearizationOffset(first_page_og); |
| @@ -721,17 +720,14 @@ QPDF::checkHPageOffset( | @@ -721,17 +720,14 @@ QPDF::checkHPageOffset( | ||
| 721 | for (int pageno = 0; pageno < npages; ++pageno) { | 720 | for (int pageno = 0; pageno < npages; ++pageno) { |
| 722 | QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen()); | 721 | QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen()); |
| 723 | int first_object = page_og.getObj(); | 722 | int first_object = page_og.getObj(); |
| 724 | - if (this->m->xref_table.count(page_og) == 0) { | 723 | + if (m->xref_table.count(page_og) == 0) { |
| 725 | stopOnError("unknown object in page offset hint table"); | 724 | stopOnError("unknown object in page offset hint table"); |
| 726 | } | 725 | } |
| 727 | offset = getLinearizationOffset(page_og); | 726 | offset = getLinearizationOffset(page_og); |
| 728 | 727 | ||
| 729 | - HPageOffsetEntry& he = | ||
| 730 | - this->m->page_offset_hints.entries.at(toS(pageno)); | ||
| 731 | - CHPageOffsetEntry& ce = | ||
| 732 | - this->m->c_page_offset_data.entries.at(toS(pageno)); | ||
| 733 | - int h_nobjects = | ||
| 734 | - he.delta_nobjects + this->m->page_offset_hints.min_nobjects; | 728 | + HPageOffsetEntry& he = m->page_offset_hints.entries.at(toS(pageno)); |
| 729 | + CHPageOffsetEntry& ce = m->c_page_offset_data.entries.at(toS(pageno)); | ||
| 730 | + int h_nobjects = he.delta_nobjects + m->page_offset_hints.min_nobjects; | ||
| 735 | if (h_nobjects != ce.nobjects) { | 731 | if (h_nobjects != ce.nobjects) { |
| 736 | // This happens with pdlin when there are thumbnails. | 732 | // This happens with pdlin when there are thumbnails. |
| 737 | linearizationWarning( | 733 | linearizationWarning( |
| @@ -743,8 +739,8 @@ QPDF::checkHPageOffset( | @@ -743,8 +739,8 @@ QPDF::checkHPageOffset( | ||
| 743 | // Use value for number of objects in hint table rather than | 739 | // Use value for number of objects in hint table rather than |
| 744 | // computed value if there is a discrepancy. | 740 | // computed value if there is a discrepancy. |
| 745 | int length = lengthNextN(first_object, h_nobjects); | 741 | int length = lengthNextN(first_object, h_nobjects); |
| 746 | - int h_length = toI( | ||
| 747 | - he.delta_page_length + this->m->page_offset_hints.min_page_length); | 742 | + int h_length = |
| 743 | + toI(he.delta_page_length + m->page_offset_hints.min_page_length); | ||
| 748 | if (length != h_length) { | 744 | if (length != h_length) { |
| 749 | // This condition almost certainly indicates a bad hint | 745 | // This condition almost certainly indicates a bad hint |
| 750 | // table or a bug in this code. | 746 | // table or a bug in this code. |
| @@ -778,10 +774,10 @@ QPDF::checkHPageOffset( | @@ -778,10 +774,10 @@ QPDF::checkHPageOffset( | ||
| 778 | 774 | ||
| 779 | for (size_t i = 0; i < toS(ce.nshared_objects); ++i) { | 775 | for (size_t i = 0; i < toS(ce.nshared_objects); ++i) { |
| 780 | int idx = ce.shared_identifiers.at(i); | 776 | int idx = ce.shared_identifiers.at(i); |
| 781 | - if (idx >= this->m->c_shared_object_data.nshared_total) { | 777 | + if (idx >= m->c_shared_object_data.nshared_total) { |
| 782 | stopOnError("index out of bounds for shared object hint table"); | 778 | stopOnError("index out of bounds for shared object hint table"); |
| 783 | } | 779 | } |
| 784 | - int obj = this->m->c_shared_object_data.entries.at(toS(idx)).object; | 780 | + int obj = m->c_shared_object_data.entries.at(toS(idx)).object; |
| 785 | computed_shared.insert(obj); | 781 | computed_shared.insert(obj); |
| 786 | } | 782 | } |
| 787 | 783 | ||
| @@ -831,7 +827,7 @@ QPDF::checkHSharedObject( | @@ -831,7 +827,7 @@ QPDF::checkHSharedObject( | ||
| 831 | // these whenever there are no shared objects not referenced by | 827 | // these whenever there are no shared objects not referenced by |
| 832 | // the first page (i.e., nshared_total == nshared_first_page). | 828 | // the first page (i.e., nshared_total == nshared_first_page). |
| 833 | 829 | ||
| 834 | - HSharedObject& so = this->m->shared_object_hints; | 830 | + HSharedObject& so = m->shared_object_hints; |
| 835 | if (so.nshared_total < so.nshared_first_page) { | 831 | if (so.nshared_total < so.nshared_first_page) { |
| 836 | linearizationWarning("shared object hint table: ntotal < nfirst_page"); | 832 | linearizationWarning("shared object hint table: ntotal < nfirst_page"); |
| 837 | } else { | 833 | } else { |
| @@ -842,11 +838,11 @@ QPDF::checkHSharedObject( | @@ -842,11 +838,11 @@ QPDF::checkHSharedObject( | ||
| 842 | for (int i = 0; i < so.nshared_total; ++i) { | 838 | for (int i = 0; i < so.nshared_total; ++i) { |
| 843 | if (i == so.nshared_first_page) { | 839 | if (i == so.nshared_first_page) { |
| 844 | QTC::TC("qpdf", "QPDF lin check shared past first page"); | 840 | QTC::TC("qpdf", "QPDF lin check shared past first page"); |
| 845 | - if (this->m->part8.empty()) { | 841 | + if (m->part8.empty()) { |
| 846 | linearizationWarning("part 8 is empty but nshared_total > " | 842 | linearizationWarning("part 8 is empty but nshared_total > " |
| 847 | "nshared_first_page"); | 843 | "nshared_first_page"); |
| 848 | } else { | 844 | } else { |
| 849 | - int obj = this->m->part8.at(0).getObjectID(); | 845 | + int obj = m->part8.at(0).getObjectID(); |
| 850 | if (obj != so.first_shared_obj) { | 846 | if (obj != so.first_shared_obj) { |
| 851 | linearizationWarning( | 847 | linearizationWarning( |
| 852 | "first shared object number mismatch: " | 848 | "first shared object number mismatch: " |
| @@ -859,7 +855,7 @@ QPDF::checkHSharedObject( | @@ -859,7 +855,7 @@ QPDF::checkHSharedObject( | ||
| 859 | cur_object = so.first_shared_obj; | 855 | cur_object = so.first_shared_obj; |
| 860 | 856 | ||
| 861 | QPDFObjGen og(cur_object, 0); | 857 | QPDFObjGen og(cur_object, 0); |
| 862 | - if (this->m->xref_table.count(og) == 0) { | 858 | + if (m->xref_table.count(og) == 0) { |
| 863 | stopOnError("unknown object in shared object hint table"); | 859 | stopOnError("unknown object in shared object hint table"); |
| 864 | } | 860 | } |
| 865 | qpdf_offset_t offset = getLinearizationOffset(og); | 861 | qpdf_offset_t offset = getLinearizationOffset(og); |
| @@ -901,13 +897,12 @@ QPDF::checkHOutlines() | @@ -901,13 +897,12 @@ QPDF::checkHOutlines() | ||
| 901 | // wrong starting place). pdlin appears to generate correct | 897 | // wrong starting place). pdlin appears to generate correct |
| 902 | // values in those cases. | 898 | // values in those cases. |
| 903 | 899 | ||
| 904 | - if (this->m->c_outline_data.nobjects == this->m->outline_hints.nobjects) { | ||
| 905 | - if (this->m->c_outline_data.nobjects == 0) { | 900 | + if (m->c_outline_data.nobjects == m->outline_hints.nobjects) { |
| 901 | + if (m->c_outline_data.nobjects == 0) { | ||
| 906 | return; | 902 | return; |
| 907 | } | 903 | } |
| 908 | 904 | ||
| 909 | - if (this->m->c_outline_data.first_object == | ||
| 910 | - this->m->outline_hints.first_object) { | 905 | + if (m->c_outline_data.first_object == m->outline_hints.first_object) { |
| 911 | // Check length and offset. Acrobat gets these wrong. | 906 | // Check length and offset. Acrobat gets these wrong. |
| 912 | QPDFObjectHandle outlines = getRoot().getKey("/Outlines"); | 907 | QPDFObjectHandle outlines = getRoot().getKey("/Outlines"); |
| 913 | if (!outlines.isIndirect()) { | 908 | if (!outlines.isIndirect()) { |
| @@ -919,21 +914,21 @@ QPDF::checkHOutlines() | @@ -919,21 +914,21 @@ QPDF::checkHOutlines() | ||
| 919 | return; | 914 | return; |
| 920 | } | 915 | } |
| 921 | QPDFObjGen og(outlines.getObjGen()); | 916 | QPDFObjGen og(outlines.getObjGen()); |
| 922 | - if (this->m->xref_table.count(og) == 0) { | 917 | + if (m->xref_table.count(og) == 0) { |
| 923 | stopOnError("unknown object in outlines hint table"); | 918 | stopOnError("unknown object in outlines hint table"); |
| 924 | } | 919 | } |
| 925 | qpdf_offset_t offset = getLinearizationOffset(og); | 920 | qpdf_offset_t offset = getLinearizationOffset(og); |
| 926 | ObjUser ou(ObjUser::ou_root_key, "/Outlines"); | 921 | ObjUser ou(ObjUser::ou_root_key, "/Outlines"); |
| 927 | int length = toI(maxEnd(ou) - offset); | 922 | int length = toI(maxEnd(ou) - offset); |
| 928 | qpdf_offset_t table_offset = | 923 | qpdf_offset_t table_offset = |
| 929 | - adjusted_offset(this->m->outline_hints.first_object_offset); | 924 | + adjusted_offset(m->outline_hints.first_object_offset); |
| 930 | if (offset != table_offset) { | 925 | if (offset != table_offset) { |
| 931 | linearizationWarning( | 926 | linearizationWarning( |
| 932 | "incorrect offset in outlines table: hint table = " + | 927 | "incorrect offset in outlines table: hint table = " + |
| 933 | std::to_string(table_offset) + | 928 | std::to_string(table_offset) + |
| 934 | "; computed = " + std::to_string(offset)); | 929 | "; computed = " + std::to_string(offset)); |
| 935 | } | 930 | } |
| 936 | - int table_length = this->m->outline_hints.group_length; | 931 | + int table_length = m->outline_hints.group_length; |
| 937 | if (length != table_length) { | 932 | if (length != table_length) { |
| 938 | linearizationWarning( | 933 | linearizationWarning( |
| 939 | "incorrect length in outlines table: hint table = " + | 934 | "incorrect length in outlines table: hint table = " + |
| @@ -964,28 +959,28 @@ QPDF::showLinearizationData() | @@ -964,28 +959,28 @@ QPDF::showLinearizationData() | ||
| 964 | void | 959 | void |
| 965 | QPDF::dumpLinearizationDataInternal() | 960 | QPDF::dumpLinearizationDataInternal() |
| 966 | { | 961 | { |
| 967 | - *this->m->log->getInfo() | ||
| 968 | - << this->m->file->getName() << ": linearization data:\n\n"; | ||
| 969 | - | ||
| 970 | - *this->m->log->getInfo() | ||
| 971 | - << "file_size: " << this->m->linp.file_size << "\n" | ||
| 972 | - << "first_page_object: " << this->m->linp.first_page_object << "\n" | ||
| 973 | - << "first_page_end: " << this->m->linp.first_page_end << "\n" | ||
| 974 | - << "npages: " << this->m->linp.npages << "\n" | ||
| 975 | - << "xref_zero_offset: " << this->m->linp.xref_zero_offset << "\n" | ||
| 976 | - << "first_page: " << this->m->linp.first_page << "\n" | ||
| 977 | - << "H_offset: " << this->m->linp.H_offset << "\n" | ||
| 978 | - << "H_length: " << this->m->linp.H_length << "\n" | ||
| 979 | - << "\n"; | ||
| 980 | - | ||
| 981 | - *this->m->log->getInfo() << "Page Offsets Hint Table\n\n"; | 962 | + *m->log->getInfo() << m->file->getName() << ": linearization data:\n\n"; |
| 963 | + | ||
| 964 | + *m->log->getInfo() << "file_size: " << m->linp.file_size << "\n" | ||
| 965 | + << "first_page_object: " << m->linp.first_page_object | ||
| 966 | + << "\n" | ||
| 967 | + << "first_page_end: " << m->linp.first_page_end << "\n" | ||
| 968 | + << "npages: " << m->linp.npages << "\n" | ||
| 969 | + << "xref_zero_offset: " << m->linp.xref_zero_offset | ||
| 970 | + << "\n" | ||
| 971 | + << "first_page: " << m->linp.first_page << "\n" | ||
| 972 | + << "H_offset: " << m->linp.H_offset << "\n" | ||
| 973 | + << "H_length: " << m->linp.H_length << "\n" | ||
| 974 | + << "\n"; | ||
| 975 | + | ||
| 976 | + *m->log->getInfo() << "Page Offsets Hint Table\n\n"; | ||
| 982 | dumpHPageOffset(); | 977 | dumpHPageOffset(); |
| 983 | - *this->m->log->getInfo() << "\nShared Objects Hint Table\n\n"; | 978 | + *m->log->getInfo() << "\nShared Objects Hint Table\n\n"; |
| 984 | dumpHSharedObject(); | 979 | dumpHSharedObject(); |
| 985 | 980 | ||
| 986 | - if (this->m->outline_hints.nobjects > 0) { | ||
| 987 | - *this->m->log->getInfo() << "\nOutlines Hint Table\n\n"; | ||
| 988 | - dumpHGeneric(this->m->outline_hints); | 981 | + if (m->outline_hints.nobjects > 0) { |
| 982 | + *m->log->getInfo() << "\nOutlines Hint Table\n\n"; | ||
| 983 | + dumpHGeneric(m->outline_hints); | ||
| 989 | } | 984 | } |
| 990 | } | 985 | } |
| 991 | 986 | ||
| @@ -995,8 +990,8 @@ QPDF::adjusted_offset(qpdf_offset_t offset) | @@ -995,8 +990,8 @@ QPDF::adjusted_offset(qpdf_offset_t offset) | ||
| 995 | // All offsets >= H_offset have to be increased by H_length | 990 | // All offsets >= H_offset have to be increased by H_length |
| 996 | // since all hint table location values disregard the hint table | 991 | // since all hint table location values disregard the hint table |
| 997 | // itself. | 992 | // itself. |
| 998 | - if (offset >= this->m->linp.H_offset) { | ||
| 999 | - return offset + this->m->linp.H_length; | 993 | + if (offset >= m->linp.H_offset) { |
| 994 | + return offset + m->linp.H_length; | ||
| 1000 | } | 995 | } |
| 1001 | return offset; | 996 | return offset; |
| 1002 | } | 997 | } |
| @@ -1004,8 +999,8 @@ QPDF::adjusted_offset(qpdf_offset_t offset) | @@ -1004,8 +999,8 @@ QPDF::adjusted_offset(qpdf_offset_t offset) | ||
| 1004 | void | 999 | void |
| 1005 | QPDF::dumpHPageOffset() | 1000 | QPDF::dumpHPageOffset() |
| 1006 | { | 1001 | { |
| 1007 | - HPageOffset& t = this->m->page_offset_hints; | ||
| 1008 | - *this->m->log->getInfo() | 1002 | + HPageOffset& t = m->page_offset_hints; |
| 1003 | + *m->log->getInfo() | ||
| 1009 | << "min_nobjects: " << t.min_nobjects << "\n" | 1004 | << "min_nobjects: " << t.min_nobjects << "\n" |
| 1010 | << "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n" | 1005 | << "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n" |
| 1011 | << "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n" | 1006 | << "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n" |
| @@ -1022,9 +1017,9 @@ QPDF::dumpHPageOffset() | @@ -1022,9 +1017,9 @@ QPDF::dumpHPageOffset() | ||
| 1022 | << "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n" | 1017 | << "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n" |
| 1023 | << "shared_denominator: " << t.shared_denominator << "\n"; | 1018 | << "shared_denominator: " << t.shared_denominator << "\n"; |
| 1024 | 1019 | ||
| 1025 | - for (size_t i1 = 0; i1 < toS(this->m->linp.npages); ++i1) { | 1020 | + for (size_t i1 = 0; i1 < toS(m->linp.npages); ++i1) { |
| 1026 | HPageOffsetEntry& pe = t.entries.at(i1); | 1021 | HPageOffsetEntry& pe = t.entries.at(i1); |
| 1027 | - *this->m->log->getInfo() | 1022 | + *m->log->getInfo() |
| 1028 | << "Page " << i1 << ":\n" | 1023 | << "Page " << i1 << ":\n" |
| 1029 | << " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n" | 1024 | << " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n" |
| 1030 | << " length: " << pe.delta_page_length + t.min_page_length | 1025 | << " length: " << pe.delta_page_length + t.min_page_length |
| @@ -1036,10 +1031,10 @@ QPDF::dumpHPageOffset() | @@ -1036,10 +1031,10 @@ QPDF::dumpHPageOffset() | ||
| 1036 | << pe.delta_content_length + t.min_content_length << "\n" | 1031 | << pe.delta_content_length + t.min_content_length << "\n" |
| 1037 | << " nshared_objects: " << pe.nshared_objects << "\n"; | 1032 | << " nshared_objects: " << pe.nshared_objects << "\n"; |
| 1038 | for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2) { | 1033 | for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2) { |
| 1039 | - *this->m->log->getInfo() << " identifier " << i2 << ": " | ||
| 1040 | - << pe.shared_identifiers.at(i2) << "\n"; | ||
| 1041 | - *this->m->log->getInfo() << " numerator " << i2 << ": " | ||
| 1042 | - << pe.shared_numerators.at(i2) << "\n"; | 1034 | + *m->log->getInfo() << " identifier " << i2 << ": " |
| 1035 | + << pe.shared_identifiers.at(i2) << "\n"; | ||
| 1036 | + *m->log->getInfo() << " numerator " << i2 << ": " | ||
| 1037 | + << pe.shared_numerators.at(i2) << "\n"; | ||
| 1043 | } | 1038 | } |
| 1044 | } | 1039 | } |
| 1045 | } | 1040 | } |
| @@ -1047,30 +1042,30 @@ QPDF::dumpHPageOffset() | @@ -1047,30 +1042,30 @@ QPDF::dumpHPageOffset() | ||
| 1047 | void | 1042 | void |
| 1048 | QPDF::dumpHSharedObject() | 1043 | QPDF::dumpHSharedObject() |
| 1049 | { | 1044 | { |
| 1050 | - HSharedObject& t = this->m->shared_object_hints; | ||
| 1051 | - *this->m->log->getInfo() | ||
| 1052 | - << "first_shared_obj: " << t.first_shared_obj << "\n" | ||
| 1053 | - << "first_shared_offset: " << adjusted_offset(t.first_shared_offset) | ||
| 1054 | - << "\n" | ||
| 1055 | - << "nshared_first_page: " << t.nshared_first_page << "\n" | ||
| 1056 | - << "nshared_total: " << t.nshared_total << "\n" | ||
| 1057 | - << "nbits_nobjects: " << t.nbits_nobjects << "\n" | ||
| 1058 | - << "min_group_length: " << t.min_group_length << "\n" | ||
| 1059 | - << "nbits_delta_group_length: " << t.nbits_delta_group_length << "\n"; | 1045 | + HSharedObject& t = m->shared_object_hints; |
| 1046 | + *m->log->getInfo() << "first_shared_obj: " << t.first_shared_obj << "\n" | ||
| 1047 | + << "first_shared_offset: " | ||
| 1048 | + << adjusted_offset(t.first_shared_offset) << "\n" | ||
| 1049 | + << "nshared_first_page: " << t.nshared_first_page << "\n" | ||
| 1050 | + << "nshared_total: " << t.nshared_total << "\n" | ||
| 1051 | + << "nbits_nobjects: " << t.nbits_nobjects << "\n" | ||
| 1052 | + << "min_group_length: " << t.min_group_length << "\n" | ||
| 1053 | + << "nbits_delta_group_length: " | ||
| 1054 | + << t.nbits_delta_group_length << "\n"; | ||
| 1060 | 1055 | ||
| 1061 | for (size_t i = 0; i < toS(t.nshared_total); ++i) { | 1056 | for (size_t i = 0; i < toS(t.nshared_total); ++i) { |
| 1062 | HSharedObjectEntry& se = t.entries.at(i); | 1057 | HSharedObjectEntry& se = t.entries.at(i); |
| 1063 | - *this->m->log->getInfo() | ||
| 1064 | - << "Shared Object " << i << ":\n" | ||
| 1065 | - << " group length: " << se.delta_group_length + t.min_group_length | ||
| 1066 | - << "\n"; | 1058 | + *m->log->getInfo() << "Shared Object " << i << ":\n" |
| 1059 | + << " group length: " | ||
| 1060 | + << se.delta_group_length + t.min_group_length | ||
| 1061 | + << "\n"; | ||
| 1067 | // PDF spec says signature present nobjects_minus_one are | 1062 | // PDF spec says signature present nobjects_minus_one are |
| 1068 | // always 0, so print them only if they have a non-zero value. | 1063 | // always 0, so print them only if they have a non-zero value. |
| 1069 | if (se.signature_present) { | 1064 | if (se.signature_present) { |
| 1070 | - *this->m->log->getInfo() << " signature present\n"; | 1065 | + *m->log->getInfo() << " signature present\n"; |
| 1071 | } | 1066 | } |
| 1072 | if (se.nobjects_minus_one != 0) { | 1067 | if (se.nobjects_minus_one != 0) { |
| 1073 | - *this->m->log->getInfo() | 1068 | + *m->log->getInfo() |
| 1074 | << " nobjects: " << se.nobjects_minus_one + 1 << "\n"; | 1069 | << " nobjects: " << se.nobjects_minus_one + 1 << "\n"; |
| 1075 | } | 1070 | } |
| 1076 | } | 1071 | } |
| @@ -1079,12 +1074,11 @@ QPDF::dumpHSharedObject() | @@ -1079,12 +1074,11 @@ QPDF::dumpHSharedObject() | ||
| 1079 | void | 1074 | void |
| 1080 | QPDF::dumpHGeneric(HGeneric& t) | 1075 | QPDF::dumpHGeneric(HGeneric& t) |
| 1081 | { | 1076 | { |
| 1082 | - *this->m->log->getInfo() | ||
| 1083 | - << "first_object: " << t.first_object << "\n" | ||
| 1084 | - << "first_object_offset: " << adjusted_offset(t.first_object_offset) | ||
| 1085 | - << "\n" | ||
| 1086 | - << "nobjects: " << t.nobjects << "\n" | ||
| 1087 | - << "group_length: " << t.group_length << "\n"; | 1077 | + *m->log->getInfo() << "first_object: " << t.first_object << "\n" |
| 1078 | + << "first_object_offset: " | ||
| 1079 | + << adjusted_offset(t.first_object_offset) << "\n" | ||
| 1080 | + << "nobjects: " << t.nobjects << "\n" | ||
| 1081 | + << "group_length: " << t.group_length << "\n"; | ||
| 1088 | } | 1082 | } |
| 1089 | 1083 | ||
| 1090 | void | 1084 | void |
| @@ -1097,7 +1091,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1097,7 +1091,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1097 | // this function. Note that actual offsets and lengths are not | 1091 | // this function. Note that actual offsets and lengths are not |
| 1098 | // computed here, but anything related to object ordering is. | 1092 | // computed here, but anything related to object ordering is. |
| 1099 | 1093 | ||
| 1100 | - if (this->m->object_to_obj_users.empty()) { | 1094 | + if (m->object_to_obj_users.empty()) { |
| 1101 | // Note that we can't call optimize here because we don't know | 1095 | // Note that we can't call optimize here because we don't know |
| 1102 | // whether it should be called with or without allow changes. | 1096 | // whether it should be called with or without allow changes. |
| 1103 | throw std::logic_error( | 1097 | throw std::logic_error( |
| @@ -1152,15 +1146,15 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1152,15 +1146,15 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1152 | 1146 | ||
| 1153 | // * outlines: part 6 or 9 | 1147 | // * outlines: part 6 or 9 |
| 1154 | 1148 | ||
| 1155 | - this->m->part4.clear(); | ||
| 1156 | - this->m->part6.clear(); | ||
| 1157 | - this->m->part7.clear(); | ||
| 1158 | - this->m->part8.clear(); | ||
| 1159 | - this->m->part9.clear(); | ||
| 1160 | - this->m->c_linp = LinParameters(); | ||
| 1161 | - this->m->c_page_offset_data = CHPageOffset(); | ||
| 1162 | - this->m->c_shared_object_data = CHSharedObject(); | ||
| 1163 | - this->m->c_outline_data = HGeneric(); | 1149 | + m->part4.clear(); |
| 1150 | + m->part6.clear(); | ||
| 1151 | + m->part7.clear(); | ||
| 1152 | + m->part8.clear(); | ||
| 1153 | + m->part9.clear(); | ||
| 1154 | + m->c_linp = LinParameters(); | ||
| 1155 | + m->c_page_offset_data = CHPageOffset(); | ||
| 1156 | + m->c_shared_object_data = CHSharedObject(); | ||
| 1157 | + m->c_outline_data = HGeneric(); | ||
| 1164 | 1158 | ||
| 1165 | QPDFObjectHandle root = getRoot(); | 1159 | QPDFObjectHandle root = getRoot(); |
| 1166 | bool outlines_in_first_page = false; | 1160 | bool outlines_in_first_page = false; |
| @@ -1199,7 +1193,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1199,7 +1193,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1199 | std::set<QPDFObjGen> lc_outlines; | 1193 | std::set<QPDFObjGen> lc_outlines; |
| 1200 | std::set<QPDFObjGen> lc_root; | 1194 | std::set<QPDFObjGen> lc_root; |
| 1201 | 1195 | ||
| 1202 | - for (auto& oiter: this->m->object_to_obj_users) { | 1196 | + for (auto& oiter: m->object_to_obj_users) { |
| 1203 | QPDFObjGen const& og = oiter.first; | 1197 | QPDFObjGen const& og = oiter.first; |
| 1204 | std::set<ObjUser>& ous = oiter.second; | 1198 | std::set<ObjUser>& ous = oiter.second; |
| 1205 | 1199 | ||
| @@ -1315,9 +1309,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1315,9 +1309,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1315 | // npages is the size of the existing pages vector, which has been | 1309 | // npages is the size of the existing pages vector, which has been |
| 1316 | // created by traversing the pages tree, and as such is a | 1310 | // created by traversing the pages tree, and as such is a |
| 1317 | // reasonable size. | 1311 | // reasonable size. |
| 1318 | - this->m->c_linp.npages = npages; | ||
| 1319 | - this->m->c_page_offset_data.entries = | ||
| 1320 | - std::vector<CHPageOffsetEntry>(toS(npages)); | 1312 | + m->c_linp.npages = npages; |
| 1313 | + m->c_page_offset_data.entries = std::vector<CHPageOffsetEntry>(toS(npages)); | ||
| 1321 | 1314 | ||
| 1322 | // Part 4: open document objects. We don't care about the order. | 1315 | // Part 4: open document objects. We don't care about the order. |
| 1323 | 1316 | ||
| @@ -1325,9 +1318,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1325,9 +1318,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1325 | stopOnError("found other than one root while" | 1318 | stopOnError("found other than one root while" |
| 1326 | " calculating linearization data"); | 1319 | " calculating linearization data"); |
| 1327 | } | 1320 | } |
| 1328 | - this->m->part4.push_back(getObject(*(lc_root.begin()))); | 1321 | + m->part4.push_back(getObject(*(lc_root.begin()))); |
| 1329 | for (auto const& og: lc_open_document) { | 1322 | for (auto const& og: lc_open_document) { |
| 1330 | - this->m->part4.push_back(getObject(og)); | 1323 | + m->part4.push_back(getObject(og)); |
| 1331 | } | 1324 | } |
| 1332 | 1325 | ||
| 1333 | // Part 6: first page objects. Note: implementation note 124 | 1326 | // Part 6: first page objects. Note: implementation note 124 |
| @@ -1347,8 +1340,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1347,8 +1340,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1347 | "object not in lc_first_page_private"); | 1340 | "object not in lc_first_page_private"); |
| 1348 | } | 1341 | } |
| 1349 | lc_first_page_private.erase(first_page_og); | 1342 | lc_first_page_private.erase(first_page_og); |
| 1350 | - this->m->c_linp.first_page_object = pages.at(0).getObjectID(); | ||
| 1351 | - this->m->part6.push_back(pages.at(0)); | 1343 | + m->c_linp.first_page_object = pages.at(0).getObjectID(); |
| 1344 | + m->part6.push_back(pages.at(0)); | ||
| 1352 | 1345 | ||
| 1353 | // The PDF spec "recommends" an order for the rest of the objects, | 1346 | // The PDF spec "recommends" an order for the rest of the objects, |
| 1354 | // but we are going to disregard it except to the extent that it | 1347 | // but we are going to disregard it except to the extent that it |
| @@ -1356,16 +1349,16 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1356,16 +1349,16 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1356 | // hint tables. | 1349 | // hint tables. |
| 1357 | 1350 | ||
| 1358 | for (auto const& og: lc_first_page_private) { | 1351 | for (auto const& og: lc_first_page_private) { |
| 1359 | - this->m->part6.push_back(getObject(og)); | 1352 | + m->part6.push_back(getObject(og)); |
| 1360 | } | 1353 | } |
| 1361 | 1354 | ||
| 1362 | for (auto const& og: lc_first_page_shared) { | 1355 | for (auto const& og: lc_first_page_shared) { |
| 1363 | - this->m->part6.push_back(getObject(og)); | 1356 | + m->part6.push_back(getObject(og)); |
| 1364 | } | 1357 | } |
| 1365 | 1358 | ||
| 1366 | // Place the outline dictionary if it goes in the first page section. | 1359 | // Place the outline dictionary if it goes in the first page section. |
| 1367 | if (outlines_in_first_page) { | 1360 | if (outlines_in_first_page) { |
| 1368 | - pushOutlinesToPart(this->m->part6, lc_outlines, object_stream_data); | 1361 | + pushOutlinesToPart(m->part6, lc_outlines, object_stream_data); |
| 1369 | } | 1362 | } |
| 1370 | 1363 | ||
| 1371 | // Fill in page offset hint table information for the first page. | 1364 | // Fill in page offset hint table information for the first page. |
| @@ -1374,8 +1367,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1374,8 +1367,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1374 | // in garbage values for all the shared object identifiers on the | 1367 | // in garbage values for all the shared object identifiers on the |
| 1375 | // first page. | 1368 | // first page. |
| 1376 | 1369 | ||
| 1377 | - this->m->c_page_offset_data.entries.at(0).nobjects = | ||
| 1378 | - toI(this->m->part6.size()); | 1370 | + m->c_page_offset_data.entries.at(0).nobjects = toI(m->part6.size()); |
| 1379 | 1371 | ||
| 1380 | // Part 7: other pages' private objects | 1372 | // Part 7: other pages' private objects |
| 1381 | 1373 | ||
| @@ -1391,23 +1383,23 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1391,23 +1383,23 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1391 | std::to_string(i) + " not in lc_other_page_private"); | 1383 | std::to_string(i) + " not in lc_other_page_private"); |
| 1392 | } | 1384 | } |
| 1393 | lc_other_page_private.erase(page_og); | 1385 | lc_other_page_private.erase(page_og); |
| 1394 | - this->m->part7.push_back(pages.at(i)); | 1386 | + m->part7.push_back(pages.at(i)); |
| 1395 | 1387 | ||
| 1396 | // Place all non-shared objects referenced by this page, | 1388 | // Place all non-shared objects referenced by this page, |
| 1397 | // updating the page object count for the hint table. | 1389 | // updating the page object count for the hint table. |
| 1398 | 1390 | ||
| 1399 | - this->m->c_page_offset_data.entries.at(i).nobjects = 1; | 1391 | + m->c_page_offset_data.entries.at(i).nobjects = 1; |
| 1400 | 1392 | ||
| 1401 | ObjUser ou(ObjUser::ou_page, toI(i)); | 1393 | ObjUser ou(ObjUser::ou_page, toI(i)); |
| 1402 | - if (this->m->obj_user_to_objects.count(ou) == 0) { | 1394 | + if (m->obj_user_to_objects.count(ou) == 0) { |
| 1403 | stopOnError("found unreferenced page while" | 1395 | stopOnError("found unreferenced page while" |
| 1404 | " calculating linearization data"); | 1396 | " calculating linearization data"); |
| 1405 | } | 1397 | } |
| 1406 | - for (auto const& og: this->m->obj_user_to_objects[ou]) { | 1398 | + for (auto const& og: m->obj_user_to_objects[ou]) { |
| 1407 | if (lc_other_page_private.count(og)) { | 1399 | if (lc_other_page_private.count(og)) { |
| 1408 | lc_other_page_private.erase(og); | 1400 | lc_other_page_private.erase(og); |
| 1409 | - this->m->part7.push_back(getObject(og)); | ||
| 1410 | - ++this->m->c_page_offset_data.entries.at(i).nobjects; | 1401 | + m->part7.push_back(getObject(og)); |
| 1402 | + ++m->c_page_offset_data.entries.at(i).nobjects; | ||
| 1411 | } | 1403 | } |
| 1412 | } | 1404 | } |
| 1413 | } | 1405 | } |
| @@ -1423,7 +1415,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1423,7 +1415,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1423 | 1415 | ||
| 1424 | // Order is unimportant. | 1416 | // Order is unimportant. |
| 1425 | for (auto const& og: lc_other_page_shared) { | 1417 | for (auto const& og: lc_other_page_shared) { |
| 1426 | - this->m->part8.push_back(getObject(og)); | 1418 | + m->part8.push_back(getObject(og)); |
| 1427 | } | 1419 | } |
| 1428 | 1420 | ||
| 1429 | // Part 9: other objects | 1421 | // Part 9: other objects |
| @@ -1437,7 +1429,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1437,7 +1429,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1437 | 1429 | ||
| 1438 | // Place the pages tree. | 1430 | // Place the pages tree. |
| 1439 | std::set<QPDFObjGen> pages_ogs = | 1431 | std::set<QPDFObjGen> pages_ogs = |
| 1440 | - this->m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")]; | 1432 | + m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")]; |
| 1441 | if (pages_ogs.empty()) { | 1433 | if (pages_ogs.empty()) { |
| 1442 | stopOnError("found empty pages tree while" | 1434 | stopOnError("found empty pages tree while" |
| 1443 | " calculating linearization data"); | 1435 | " calculating linearization data"); |
| @@ -1445,7 +1437,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1445,7 +1437,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1445 | for (auto const& og: pages_ogs) { | 1437 | for (auto const& og: pages_ogs) { |
| 1446 | if (lc_other.count(og)) { | 1438 | if (lc_other.count(og)) { |
| 1447 | lc_other.erase(og); | 1439 | lc_other.erase(og); |
| 1448 | - this->m->part9.push_back(getObject(og)); | 1440 | + m->part9.push_back(getObject(og)); |
| 1449 | } | 1441 | } |
| 1450 | } | 1442 | } |
| 1451 | 1443 | ||
| @@ -1460,7 +1452,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1460,7 +1452,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1460 | QPDFObjGen thumb_og(thumb.getObjGen()); | 1452 | QPDFObjGen thumb_og(thumb.getObjGen()); |
| 1461 | if (lc_thumbnail_private.count(thumb_og)) { | 1453 | if (lc_thumbnail_private.count(thumb_og)) { |
| 1462 | lc_thumbnail_private.erase(thumb_og); | 1454 | lc_thumbnail_private.erase(thumb_og); |
| 1463 | - this->m->part9.push_back(thumb); | 1455 | + m->part9.push_back(thumb); |
| 1464 | } else { | 1456 | } else { |
| 1465 | // No internal error this time...there's nothing to | 1457 | // No internal error this time...there's nothing to |
| 1466 | // stop this object from having been referred to | 1458 | // stop this object from having been referred to |
| @@ -1470,12 +1462,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1470,12 +1462,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1470 | // lc_thumbnail_private. | 1462 | // lc_thumbnail_private. |
| 1471 | } | 1463 | } |
| 1472 | std::set<QPDFObjGen>& ogs = | 1464 | std::set<QPDFObjGen>& ogs = |
| 1473 | - this->m | ||
| 1474 | - ->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; | 1465 | + m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; |
| 1475 | for (auto const& og: ogs) { | 1466 | for (auto const& og: ogs) { |
| 1476 | if (lc_thumbnail_private.count(og)) { | 1467 | if (lc_thumbnail_private.count(og)) { |
| 1477 | lc_thumbnail_private.erase(og); | 1468 | lc_thumbnail_private.erase(og); |
| 1478 | - this->m->part9.push_back(getObject(og)); | 1469 | + m->part9.push_back(getObject(og)); |
| 1479 | } | 1470 | } |
| 1480 | } | 1471 | } |
| 1481 | } | 1472 | } |
| @@ -1488,24 +1479,24 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1488,24 +1479,24 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1488 | 1479 | ||
| 1489 | // Place shared thumbnail objects | 1480 | // Place shared thumbnail objects |
| 1490 | for (auto const& og: lc_thumbnail_shared) { | 1481 | for (auto const& og: lc_thumbnail_shared) { |
| 1491 | - this->m->part9.push_back(getObject(og)); | 1482 | + m->part9.push_back(getObject(og)); |
| 1492 | } | 1483 | } |
| 1493 | 1484 | ||
| 1494 | // Place outlines unless in first page | 1485 | // Place outlines unless in first page |
| 1495 | if (!outlines_in_first_page) { | 1486 | if (!outlines_in_first_page) { |
| 1496 | - pushOutlinesToPart(this->m->part9, lc_outlines, object_stream_data); | 1487 | + pushOutlinesToPart(m->part9, lc_outlines, object_stream_data); |
| 1497 | } | 1488 | } |
| 1498 | 1489 | ||
| 1499 | // Place all remaining objects | 1490 | // Place all remaining objects |
| 1500 | for (auto const& og: lc_other) { | 1491 | for (auto const& og: lc_other) { |
| 1501 | - this->m->part9.push_back(getObject(og)); | 1492 | + m->part9.push_back(getObject(og)); |
| 1502 | } | 1493 | } |
| 1503 | 1494 | ||
| 1504 | // Make sure we got everything exactly once. | 1495 | // Make sure we got everything exactly once. |
| 1505 | 1496 | ||
| 1506 | - size_t num_placed = this->m->part4.size() + this->m->part6.size() + | ||
| 1507 | - this->m->part7.size() + this->m->part8.size() + this->m->part9.size(); | ||
| 1508 | - size_t num_wanted = this->m->object_to_obj_users.size(); | 1497 | + size_t num_placed = m->part4.size() + m->part6.size() + m->part7.size() + |
| 1498 | + m->part8.size() + m->part9.size(); | ||
| 1499 | + size_t num_wanted = m->object_to_obj_users.size(); | ||
| 1509 | if (num_placed != num_wanted) { | 1500 | if (num_placed != num_wanted) { |
| 1510 | stopOnError( | 1501 | stopOnError( |
| 1511 | "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong " | 1502 | "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong " |
| @@ -1527,31 +1518,27 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1527,31 +1518,27 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1527 | // can map from object number only without regards to generation. | 1518 | // can map from object number only without regards to generation. |
| 1528 | std::map<int, int> obj_to_index; | 1519 | std::map<int, int> obj_to_index; |
| 1529 | 1520 | ||
| 1530 | - this->m->c_shared_object_data.nshared_first_page = | ||
| 1531 | - toI(this->m->part6.size()); | ||
| 1532 | - this->m->c_shared_object_data.nshared_total = | ||
| 1533 | - this->m->c_shared_object_data.nshared_first_page + | ||
| 1534 | - toI(this->m->part8.size()); | 1521 | + m->c_shared_object_data.nshared_first_page = toI(m->part6.size()); |
| 1522 | + m->c_shared_object_data.nshared_total = | ||
| 1523 | + m->c_shared_object_data.nshared_first_page + toI(m->part8.size()); | ||
| 1535 | 1524 | ||
| 1536 | - std::vector<CHSharedObjectEntry>& shared = | ||
| 1537 | - this->m->c_shared_object_data.entries; | ||
| 1538 | - for (auto& oh: this->m->part6) { | 1525 | + std::vector<CHSharedObjectEntry>& shared = m->c_shared_object_data.entries; |
| 1526 | + for (auto& oh: m->part6) { | ||
| 1539 | int obj = oh.getObjectID(); | 1527 | int obj = oh.getObjectID(); |
| 1540 | obj_to_index[obj] = toI(shared.size()); | 1528 | obj_to_index[obj] = toI(shared.size()); |
| 1541 | shared.push_back(CHSharedObjectEntry(obj)); | 1529 | shared.push_back(CHSharedObjectEntry(obj)); |
| 1542 | } | 1530 | } |
| 1543 | - QTC::TC("qpdf", "QPDF lin part 8 empty", this->m->part8.empty() ? 1 : 0); | ||
| 1544 | - if (!this->m->part8.empty()) { | ||
| 1545 | - this->m->c_shared_object_data.first_shared_obj = | ||
| 1546 | - this->m->part8.at(0).getObjectID(); | ||
| 1547 | - for (auto& oh: this->m->part8) { | 1531 | + QTC::TC("qpdf", "QPDF lin part 8 empty", m->part8.empty() ? 1 : 0); |
| 1532 | + if (!m->part8.empty()) { | ||
| 1533 | + m->c_shared_object_data.first_shared_obj = m->part8.at(0).getObjectID(); | ||
| 1534 | + for (auto& oh: m->part8) { | ||
| 1548 | int obj = oh.getObjectID(); | 1535 | int obj = oh.getObjectID(); |
| 1549 | obj_to_index[obj] = toI(shared.size()); | 1536 | obj_to_index[obj] = toI(shared.size()); |
| 1550 | shared.push_back(CHSharedObjectEntry(obj)); | 1537 | shared.push_back(CHSharedObjectEntry(obj)); |
| 1551 | } | 1538 | } |
| 1552 | } | 1539 | } |
| 1553 | - if (static_cast<size_t>(this->m->c_shared_object_data.nshared_total) != | ||
| 1554 | - this->m->c_shared_object_data.entries.size()) { | 1540 | + if (static_cast<size_t>(m->c_shared_object_data.nshared_total) != |
| 1541 | + m->c_shared_object_data.entries.size()) { | ||
| 1555 | stopOnError("shared object hint table has wrong number of entries"); | 1542 | stopOnError("shared object hint table has wrong number of entries"); |
| 1556 | } | 1543 | } |
| 1557 | 1544 | ||
| @@ -1559,14 +1546,14 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1559,14 +1546,14 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1559 | // first page. | 1546 | // first page. |
| 1560 | 1547 | ||
| 1561 | for (size_t i = 1; i < toS(npages); ++i) { | 1548 | for (size_t i = 1; i < toS(npages); ++i) { |
| 1562 | - CHPageOffsetEntry& pe = this->m->c_page_offset_data.entries.at(i); | 1549 | + CHPageOffsetEntry& pe = m->c_page_offset_data.entries.at(i); |
| 1563 | ObjUser ou(ObjUser::ou_page, toI(i)); | 1550 | ObjUser ou(ObjUser::ou_page, toI(i)); |
| 1564 | - if (this->m->obj_user_to_objects.count(ou) == 0) { | 1551 | + if (m->obj_user_to_objects.count(ou) == 0) { |
| 1565 | stopOnError("found unreferenced page while" | 1552 | stopOnError("found unreferenced page while" |
| 1566 | " calculating linearization data"); | 1553 | " calculating linearization data"); |
| 1567 | } | 1554 | } |
| 1568 | - for (auto const& og: this->m->obj_user_to_objects[ou]) { | ||
| 1569 | - if ((this->m->object_to_obj_users[og].size() > 1) && | 1555 | + for (auto const& og: m->obj_user_to_objects[ou]) { |
| 1556 | + if ((m->object_to_obj_users[og].size() > 1) && | ||
| 1570 | (obj_to_index.count(og.getObj()) > 0)) { | 1557 | (obj_to_index.count(og.getObj()) > 0)) { |
| 1571 | int idx = obj_to_index[og.getObj()]; | 1558 | int idx = obj_to_index[og.getObj()]; |
| 1572 | ++pe.nshared_objects; | 1559 | ++pe.nshared_objects; |
| @@ -1592,16 +1579,16 @@ QPDF::pushOutlinesToPart( | @@ -1592,16 +1579,16 @@ QPDF::pushOutlinesToPart( | ||
| 1592 | QTC::TC( | 1579 | QTC::TC( |
| 1593 | "qpdf", | 1580 | "qpdf", |
| 1594 | "QPDF lin outlines in part", | 1581 | "QPDF lin outlines in part", |
| 1595 | - ((&part == (&this->m->part6)) ? 0 | ||
| 1596 | - : (&part == (&this->m->part9)) ? 1 | ||
| 1597 | - : 9999)); // can't happen | ||
| 1598 | - this->m->c_outline_data.first_object = outlines_og.getObj(); | ||
| 1599 | - this->m->c_outline_data.nobjects = 1; | 1582 | + ((&part == (&m->part6)) ? 0 |
| 1583 | + : (&part == (&m->part9)) ? 1 | ||
| 1584 | + : 9999)); // can't happen | ||
| 1585 | + m->c_outline_data.first_object = outlines_og.getObj(); | ||
| 1586 | + m->c_outline_data.nobjects = 1; | ||
| 1600 | lc_outlines.erase(outlines_og); | 1587 | lc_outlines.erase(outlines_og); |
| 1601 | part.push_back(outlines); | 1588 | part.push_back(outlines); |
| 1602 | for (auto const& og: lc_outlines) { | 1589 | for (auto const& og: lc_outlines) { |
| 1603 | part.push_back(getObject(og)); | 1590 | part.push_back(getObject(og)); |
| 1604 | - ++this->m->c_outline_data.nobjects; | 1591 | + ++m->c_outline_data.nobjects; |
| 1605 | } | 1592 | } |
| 1606 | } | 1593 | } |
| 1607 | 1594 | ||
| @@ -1615,11 +1602,11 @@ QPDF::getLinearizedParts( | @@ -1615,11 +1602,11 @@ QPDF::getLinearizedParts( | ||
| 1615 | std::vector<QPDFObjectHandle>& part9) | 1602 | std::vector<QPDFObjectHandle>& part9) |
| 1616 | { | 1603 | { |
| 1617 | calculateLinearizationData(object_stream_data); | 1604 | calculateLinearizationData(object_stream_data); |
| 1618 | - part4 = this->m->part4; | ||
| 1619 | - part6 = this->m->part6; | ||
| 1620 | - part7 = this->m->part7; | ||
| 1621 | - part8 = this->m->part8; | ||
| 1622 | - part9 = this->m->part9; | 1605 | + part4 = m->part4; |
| 1606 | + part6 = m->part6; | ||
| 1607 | + part7 = m->part7; | ||
| 1608 | + part8 = m->part8; | ||
| 1609 | + part9 = m->part9; | ||
| 1623 | } | 1610 | } |
| 1624 | 1611 | ||
| 1625 | static inline int | 1612 | static inline int |
| @@ -1668,7 +1655,7 @@ QPDF::calculateHPageOffset( | @@ -1668,7 +1655,7 @@ QPDF::calculateHPageOffset( | ||
| 1668 | 1655 | ||
| 1669 | std::vector<QPDFObjectHandle> const& pages = getAllPages(); | 1656 | std::vector<QPDFObjectHandle> const& pages = getAllPages(); |
| 1670 | size_t npages = pages.size(); | 1657 | size_t npages = pages.size(); |
| 1671 | - CHPageOffset& cph = this->m->c_page_offset_data; | 1658 | + CHPageOffset& cph = m->c_page_offset_data; |
| 1672 | std::vector<CHPageOffsetEntry>& cphe = cph.entries; | 1659 | std::vector<CHPageOffsetEntry>& cphe = cph.entries; |
| 1673 | 1660 | ||
| 1674 | // Calculate minimum and maximum values for number of objects per | 1661 | // Calculate minimum and maximum values for number of objects per |
| @@ -1681,7 +1668,7 @@ QPDF::calculateHPageOffset( | @@ -1681,7 +1668,7 @@ QPDF::calculateHPageOffset( | ||
| 1681 | int max_length = min_length; | 1668 | int max_length = min_length; |
| 1682 | int max_shared = cphe.at(0).nshared_objects; | 1669 | int max_shared = cphe.at(0).nshared_objects; |
| 1683 | 1670 | ||
| 1684 | - HPageOffset& ph = this->m->page_offset_hints; | 1671 | + HPageOffset& ph = m->page_offset_hints; |
| 1685 | std::vector<HPageOffsetEntry>& phe = ph.entries; | 1672 | std::vector<HPageOffsetEntry>& phe = ph.entries; |
| 1686 | // npages is the size of the existing pages array. | 1673 | // npages is the size of the existing pages array. |
| 1687 | phe = std::vector<HPageOffsetEntry>(npages); | 1674 | phe = std::vector<HPageOffsetEntry>(npages); |
| @@ -1717,8 +1704,7 @@ QPDF::calculateHPageOffset( | @@ -1717,8 +1704,7 @@ QPDF::calculateHPageOffset( | ||
| 1717 | ph.min_page_length = min_length; | 1704 | ph.min_page_length = min_length; |
| 1718 | ph.nbits_delta_page_length = nbits(max_length - min_length); | 1705 | ph.nbits_delta_page_length = nbits(max_length - min_length); |
| 1719 | ph.nbits_nshared_objects = nbits(max_shared); | 1706 | ph.nbits_nshared_objects = nbits(max_shared); |
| 1720 | - ph.nbits_shared_identifier = | ||
| 1721 | - nbits(this->m->c_shared_object_data.nshared_total); | 1707 | + ph.nbits_shared_identifier = nbits(m->c_shared_object_data.nshared_total); |
| 1722 | ph.shared_denominator = 4; // doesn't matter | 1708 | ph.shared_denominator = 4; // doesn't matter |
| 1723 | 1709 | ||
| 1724 | // It isn't clear how to compute content offset and content | 1710 | // It isn't clear how to compute content offset and content |
| @@ -1754,9 +1740,9 @@ QPDF::calculateHSharedObject( | @@ -1754,9 +1740,9 @@ QPDF::calculateHSharedObject( | ||
| 1754 | std::map<int, qpdf_offset_t> const& lengths, | 1740 | std::map<int, qpdf_offset_t> const& lengths, |
| 1755 | std::map<int, int> const& obj_renumber) | 1741 | std::map<int, int> const& obj_renumber) |
| 1756 | { | 1742 | { |
| 1757 | - CHSharedObject& cso = this->m->c_shared_object_data; | 1743 | + CHSharedObject& cso = m->c_shared_object_data; |
| 1758 | std::vector<CHSharedObjectEntry>& csoe = cso.entries; | 1744 | std::vector<CHSharedObjectEntry>& csoe = cso.entries; |
| 1759 | - HSharedObject& so = this->m->shared_object_hints; | 1745 | + HSharedObject& so = m->shared_object_hints; |
| 1760 | std::vector<HSharedObjectEntry>& soe = so.entries; | 1746 | std::vector<HSharedObjectEntry>& soe = so.entries; |
| 1761 | soe.clear(); | 1747 | soe.clear(); |
| 1762 | 1748 | ||
| @@ -1804,13 +1790,13 @@ QPDF::calculateHOutline( | @@ -1804,13 +1790,13 @@ QPDF::calculateHOutline( | ||
| 1804 | std::map<int, qpdf_offset_t> const& lengths, | 1790 | std::map<int, qpdf_offset_t> const& lengths, |
| 1805 | std::map<int, int> const& obj_renumber) | 1791 | std::map<int, int> const& obj_renumber) |
| 1806 | { | 1792 | { |
| 1807 | - HGeneric& cho = this->m->c_outline_data; | 1793 | + HGeneric& cho = m->c_outline_data; |
| 1808 | 1794 | ||
| 1809 | if (cho.nobjects == 0) { | 1795 | if (cho.nobjects == 0) { |
| 1810 | return; | 1796 | return; |
| 1811 | } | 1797 | } |
| 1812 | 1798 | ||
| 1813 | - HGeneric& ho = this->m->outline_hints; | 1799 | + HGeneric& ho = m->outline_hints; |
| 1814 | 1800 | ||
| 1815 | ho.first_object = (*(obj_renumber.find(cho.first_object))).second; | 1801 | ho.first_object = (*(obj_renumber.find(cho.first_object))).second; |
| 1816 | ho.first_object_offset = (*(xref.find(ho.first_object))).second.getOffset(); | 1802 | ho.first_object_offset = (*(xref.find(ho.first_object))).second.getOffset(); |
| @@ -1861,7 +1847,7 @@ write_vector_vector( | @@ -1861,7 +1847,7 @@ write_vector_vector( | ||
| 1861 | void | 1847 | void |
| 1862 | QPDF::writeHPageOffset(BitWriter& w) | 1848 | QPDF::writeHPageOffset(BitWriter& w) |
| 1863 | { | 1849 | { |
| 1864 | - HPageOffset& t = this->m->page_offset_hints; | 1850 | + HPageOffset& t = m->page_offset_hints; |
| 1865 | 1851 | ||
| 1866 | w.writeBitsInt(t.min_nobjects, 32); // 1 | 1852 | w.writeBitsInt(t.min_nobjects, 32); // 1 |
| 1867 | w.writeBitsInt(toI(t.first_page_offset), 32); // 2 | 1853 | w.writeBitsInt(toI(t.first_page_offset), 32); // 2 |
| @@ -1929,7 +1915,7 @@ QPDF::writeHPageOffset(BitWriter& w) | @@ -1929,7 +1915,7 @@ QPDF::writeHPageOffset(BitWriter& w) | ||
| 1929 | void | 1915 | void |
| 1930 | QPDF::writeHSharedObject(BitWriter& w) | 1916 | QPDF::writeHSharedObject(BitWriter& w) |
| 1931 | { | 1917 | { |
| 1932 | - HSharedObject& t = this->m->shared_object_hints; | 1918 | + HSharedObject& t = m->shared_object_hints; |
| 1933 | 1919 | ||
| 1934 | w.writeBitsInt(t.first_shared_obj, 32); // 1 | 1920 | w.writeBitsInt(t.first_shared_obj, 32); // 1 |
| 1935 | w.writeBitsInt(toI(t.first_shared_offset), 32); // 2 | 1921 | w.writeBitsInt(toI(t.first_shared_offset), 32); // 2 |
| @@ -2004,9 +1990,9 @@ QPDF::generateHintStream( | @@ -2004,9 +1990,9 @@ QPDF::generateHintStream( | ||
| 2004 | S = toI(c.getCount()); | 1990 | S = toI(c.getCount()); |
| 2005 | writeHSharedObject(w); | 1991 | writeHSharedObject(w); |
| 2006 | O = 0; | 1992 | O = 0; |
| 2007 | - if (this->m->outline_hints.nobjects > 0) { | 1993 | + if (m->outline_hints.nobjects > 0) { |
| 2008 | O = toI(c.getCount()); | 1994 | O = toI(c.getCount()); |
| 2009 | - writeHGeneric(w, this->m->outline_hints); | 1995 | + writeHGeneric(w, m->outline_hints); |
| 2010 | } | 1996 | } |
| 2011 | c.finish(); | 1997 | c.finish(); |
| 2012 | 1998 |
libqpdf/QPDF_optimization.cc
| @@ -59,7 +59,7 @@ QPDF::optimize( | @@ -59,7 +59,7 @@ QPDF::optimize( | ||
| 59 | bool allow_changes, | 59 | bool allow_changes, |
| 60 | std::function<int(QPDFObjectHandle&)> skip_stream_parameters) | 60 | std::function<int(QPDFObjectHandle&)> skip_stream_parameters) |
| 61 | { | 61 | { |
| 62 | - if (!this->m->obj_user_to_objects.empty()) { | 62 | + if (!m->obj_user_to_objects.empty()) { |
| 63 | // already optimized | 63 | // already optimized |
| 64 | return; | 64 | return; |
| 65 | } | 65 | } |
| @@ -77,26 +77,26 @@ QPDF::optimize( | @@ -77,26 +77,26 @@ QPDF::optimize( | ||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // Traverse pages tree pushing all inherited resources down to the | 79 | // Traverse pages tree pushing all inherited resources down to the |
| 80 | - // page level. This also initializes this->m->all_pages. | 80 | + // page level. This also initializes m->all_pages. |
| 81 | pushInheritedAttributesToPage(allow_changes, false); | 81 | pushInheritedAttributesToPage(allow_changes, false); |
| 82 | 82 | ||
| 83 | // Traverse pages | 83 | // Traverse pages |
| 84 | - int n = toI(this->m->all_pages.size()); | 84 | + int n = toI(m->all_pages.size()); |
| 85 | for (int pageno = 0; pageno < n; ++pageno) { | 85 | for (int pageno = 0; pageno < n; ++pageno) { |
| 86 | updateObjectMaps( | 86 | updateObjectMaps( |
| 87 | ObjUser(ObjUser::ou_page, pageno), | 87 | ObjUser(ObjUser::ou_page, pageno), |
| 88 | - this->m->all_pages.at(toS(pageno)), | 88 | + m->all_pages.at(toS(pageno)), |
| 89 | skip_stream_parameters); | 89 | skip_stream_parameters); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | // Traverse document-level items | 92 | // Traverse document-level items |
| 93 | - for (auto const& key: this->m->trailer.getKeys()) { | 93 | + for (auto const& key: m->trailer.getKeys()) { |
| 94 | if (key == "/Root") { | 94 | if (key == "/Root") { |
| 95 | // handled separately | 95 | // handled separately |
| 96 | } else { | 96 | } else { |
| 97 | updateObjectMaps( | 97 | updateObjectMaps( |
| 98 | ObjUser(ObjUser::ou_trailer_key, key), | 98 | ObjUser(ObjUser::ou_trailer_key, key), |
| 99 | - this->m->trailer.getKey(key), | 99 | + m->trailer.getKey(key), |
| 100 | skip_stream_parameters); | 100 | skip_stream_parameters); |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| @@ -116,8 +116,8 @@ QPDF::optimize( | @@ -116,8 +116,8 @@ QPDF::optimize( | ||
| 116 | 116 | ||
| 117 | ObjUser root_ou = ObjUser(ObjUser::ou_root); | 117 | ObjUser root_ou = ObjUser(ObjUser::ou_root); |
| 118 | auto root_og = QPDFObjGen(root.getObjGen()); | 118 | auto root_og = QPDFObjGen(root.getObjGen()); |
| 119 | - this->m->obj_user_to_objects[root_ou].insert(root_og); | ||
| 120 | - this->m->object_to_obj_users[root_og].insert(root_ou); | 119 | + m->obj_user_to_objects[root_ou].insert(root_og); |
| 120 | + m->object_to_obj_users[root_og].insert(root_ou); | ||
| 121 | 121 | ||
| 122 | filterCompressedObjects(object_stream_data); | 122 | filterCompressedObjects(object_stream_data); |
| 123 | } | 123 | } |
| @@ -138,7 +138,7 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) | @@ -138,7 +138,7 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) | ||
| 138 | // The record of whether we've done this is cleared by | 138 | // The record of whether we've done this is cleared by |
| 139 | // updateAllPagesCache(). If we're warning for skipped keys, | 139 | // updateAllPagesCache(). If we're warning for skipped keys, |
| 140 | // re-traverse unconditionally. | 140 | // re-traverse unconditionally. |
| 141 | - if (this->m->pushed_inherited_attributes_to_pages && (!warn_skipped_keys)) { | 141 | + if (m->pushed_inherited_attributes_to_pages && (!warn_skipped_keys)) { |
| 142 | return; | 142 | return; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| @@ -151,7 +151,7 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) | @@ -151,7 +151,7 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) | ||
| 151 | // Pages nodes that contain values for them. | 151 | // Pages nodes that contain values for them. |
| 152 | std::map<std::string, std::vector<QPDFObjectHandle>> key_ancestors; | 152 | std::map<std::string, std::vector<QPDFObjectHandle>> key_ancestors; |
| 153 | pushInheritedAttributesToPageInternal( | 153 | pushInheritedAttributesToPageInternal( |
| 154 | - this->m->trailer.getKey("/Root").getKey("/Pages"), | 154 | + m->trailer.getKey("/Root").getKey("/Pages"), |
| 155 | key_ancestors, | 155 | key_ancestors, |
| 156 | allow_changes, | 156 | allow_changes, |
| 157 | warn_skipped_keys); | 157 | warn_skipped_keys); |
| @@ -159,8 +159,8 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) | @@ -159,8 +159,8 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) | ||
| 159 | throw std::logic_error("key_ancestors not empty after" | 159 | throw std::logic_error("key_ancestors not empty after" |
| 160 | " pushing inherited attributes to pages"); | 160 | " pushing inherited attributes to pages"); |
| 161 | } | 161 | } |
| 162 | - this->m->pushed_inherited_attributes_to_pages = true; | ||
| 163 | - this->m->ever_pushed_inherited_attributes_to_pages = true; | 162 | + m->pushed_inherited_attributes_to_pages = true; |
| 163 | + m->ever_pushed_inherited_attributes_to_pages = true; | ||
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | void | 166 | void |
| @@ -182,9 +182,9 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -182,9 +182,9 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 182 | if (!allow_changes) { | 182 | if (!allow_changes) { |
| 183 | throw QPDFExc( | 183 | throw QPDFExc( |
| 184 | qpdf_e_internal, | 184 | qpdf_e_internal, |
| 185 | - this->m->file->getName(), | ||
| 186 | - this->m->last_object_description, | ||
| 187 | - this->m->file->getLastOffset(), | 185 | + m->file->getName(), |
| 186 | + m->last_object_description, | ||
| 187 | + m->file->getLastOffset(), | ||
| 188 | "optimize detected an " | 188 | "optimize detected an " |
| 189 | "inheritable attribute when called " | 189 | "inheritable attribute when called " |
| 190 | "in no-change mode"); | 190 | "in no-change mode"); |
| @@ -226,7 +226,7 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -226,7 +226,7 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 226 | setLastObjectDescription("Pages object", cur_pages.getObjGen()); | 226 | setLastObjectDescription("Pages object", cur_pages.getObjGen()); |
| 227 | warn( | 227 | warn( |
| 228 | qpdf_e_pages, | 228 | qpdf_e_pages, |
| 229 | - this->m->last_object_description, | 229 | + m->last_object_description, |
| 230 | 0, | 230 | 0, |
| 231 | ("Unknown key " + key + | 231 | ("Unknown key " + key + |
| 232 | " in /Pages object" | 232 | " in /Pages object" |
| @@ -314,8 +314,8 @@ QPDF::updateObjectMapsInternal( | @@ -314,8 +314,8 @@ QPDF::updateObjectMapsInternal( | ||
| 314 | QTC::TC("qpdf", "QPDF opt loop detected"); | 314 | QTC::TC("qpdf", "QPDF opt loop detected"); |
| 315 | return; | 315 | return; |
| 316 | } | 316 | } |
| 317 | - this->m->obj_user_to_objects[ou].insert(og); | ||
| 318 | - this->m->object_to_obj_users[og].insert(ou); | 317 | + m->obj_user_to_objects[ou].insert(og); |
| 318 | + m->object_to_obj_users[og].insert(ou); | ||
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | if (oh.isArray()) { | 321 | if (oh.isArray()) { |
| @@ -380,7 +380,7 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | @@ -380,7 +380,7 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | ||
| 380 | std::map<ObjUser, std::set<QPDFObjGen>> t_obj_user_to_objects; | 380 | std::map<ObjUser, std::set<QPDFObjGen>> t_obj_user_to_objects; |
| 381 | std::map<QPDFObjGen, std::set<ObjUser>> t_object_to_obj_users; | 381 | std::map<QPDFObjGen, std::set<ObjUser>> t_object_to_obj_users; |
| 382 | 382 | ||
| 383 | - for (auto const& i1: this->m->obj_user_to_objects) { | 383 | + for (auto const& i1: m->obj_user_to_objects) { |
| 384 | ObjUser const& ou = i1.first; | 384 | ObjUser const& ou = i1.first; |
| 385 | // Loop over objects. | 385 | // Loop over objects. |
| 386 | for (auto const& og: i1.second) { | 386 | for (auto const& og: i1.second) { |
| @@ -393,7 +393,7 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | @@ -393,7 +393,7 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | ||
| 393 | } | 393 | } |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | - for (auto const& i1: this->m->object_to_obj_users) { | 396 | + for (auto const& i1: m->object_to_obj_users) { |
| 397 | QPDFObjGen const& og = i1.first; | 397 | QPDFObjGen const& og = i1.first; |
| 398 | // Loop over obj_users. | 398 | // Loop over obj_users. |
| 399 | for (auto const& ou: i1.second) { | 399 | for (auto const& ou: i1.second) { |
| @@ -406,6 +406,6 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | @@ -406,6 +406,6 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | ||
| 406 | } | 406 | } |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | - this->m->obj_user_to_objects = t_obj_user_to_objects; | ||
| 410 | - this->m->object_to_obj_users = t_object_to_obj_users; | 409 | + m->obj_user_to_objects = t_obj_user_to_objects; |
| 410 | + m->object_to_obj_users = t_object_to_obj_users; | ||
| 411 | } | 411 | } |
libqpdf/QPDF_pages.cc
| @@ -52,9 +52,9 @@ std::vector<QPDFObjectHandle> const& | @@ -52,9 +52,9 @@ std::vector<QPDFObjectHandle> const& | ||
| 52 | QPDF::getAllPages() | 52 | QPDF::getAllPages() |
| 53 | { | 53 | { |
| 54 | // Note that pushInheritedAttributesToPage may also be used to | 54 | // Note that pushInheritedAttributesToPage may also be used to |
| 55 | - // initialize this->m->all_pages. | ||
| 56 | - if (this->m->all_pages.empty()) { | ||
| 57 | - this->m->ever_called_get_all_pages = true; | 55 | + // initialize m->all_pages. |
| 56 | + if (m->all_pages.empty()) { | ||
| 57 | + m->ever_called_get_all_pages = true; | ||
| 58 | QPDFObjGen::set visited; | 58 | QPDFObjGen::set visited; |
| 59 | QPDFObjGen::set seen; | 59 | QPDFObjGen::set seen; |
| 60 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); | 60 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); |
| @@ -86,7 +86,7 @@ QPDF::getAllPages() | @@ -86,7 +86,7 @@ QPDF::getAllPages() | ||
| 86 | getAllPagesInternal(pages, visited, seen); | 86 | getAllPagesInternal(pages, visited, seen); |
| 87 | } | 87 | } |
| 88 | } | 88 | } |
| 89 | - return this->m->all_pages; | 89 | + return m->all_pages; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | void | 92 | void |
| @@ -96,8 +96,8 @@ QPDF::getAllPagesInternal( | @@ -96,8 +96,8 @@ QPDF::getAllPagesInternal( | ||
| 96 | if (!visited.add(cur_node)) { | 96 | if (!visited.add(cur_node)) { |
| 97 | throw QPDFExc( | 97 | throw QPDFExc( |
| 98 | qpdf_e_pages, | 98 | qpdf_e_pages, |
| 99 | - this->m->file->getName(), | ||
| 100 | - this->m->last_object_description, | 99 | + m->file->getName(), |
| 100 | + m->last_object_description, | ||
| 101 | 0, | 101 | 0, |
| 102 | "Loop detected in /Pages structure (getAllPages)"); | 102 | "Loop detected in /Pages structure (getAllPages)"); |
| 103 | } | 103 | } |
| @@ -150,9 +150,9 @@ QPDF::updateAllPagesCache() | @@ -150,9 +150,9 @@ QPDF::updateAllPagesCache() | ||
| 150 | // it that they got from calls to getAllPages(). We can defer | 150 | // it that they got from calls to getAllPages(). We can defer |
| 151 | // recalculation of pageobj_to_pages_pos until needed. | 151 | // recalculation of pageobj_to_pages_pos until needed. |
| 152 | QTC::TC("qpdf", "QPDF updateAllPagesCache"); | 152 | QTC::TC("qpdf", "QPDF updateAllPagesCache"); |
| 153 | - this->m->all_pages.clear(); | ||
| 154 | - this->m->pageobj_to_pages_pos.clear(); | ||
| 155 | - this->m->pushed_inherited_attributes_to_pages = false; | 153 | + m->all_pages.clear(); |
| 154 | + m->pageobj_to_pages_pos.clear(); | ||
| 155 | + m->pushed_inherited_attributes_to_pages = false; | ||
| 156 | getAllPages(); | 156 | getAllPages(); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| @@ -162,27 +162,27 @@ QPDF::flattenPagesTree() | @@ -162,27 +162,27 @@ QPDF::flattenPagesTree() | ||
| 162 | // If not already done, flatten the /Pages structure and | 162 | // If not already done, flatten the /Pages structure and |
| 163 | // initialize pageobj_to_pages_pos. | 163 | // initialize pageobj_to_pages_pos. |
| 164 | 164 | ||
| 165 | - if (!this->m->pageobj_to_pages_pos.empty()) { | 165 | + if (!m->pageobj_to_pages_pos.empty()) { |
| 166 | return; | 166 | return; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | // Push inherited objects down to the /Page level. As a side | 169 | // Push inherited objects down to the /Page level. As a side |
| 170 | - // effect this->m->all_pages will also be generated. | 170 | + // effect m->all_pages will also be generated. |
| 171 | pushInheritedAttributesToPage(true, true); | 171 | pushInheritedAttributesToPage(true, true); |
| 172 | 172 | ||
| 173 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); | 173 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); |
| 174 | 174 | ||
| 175 | - size_t const len = this->m->all_pages.size(); | 175 | + size_t const len = m->all_pages.size(); |
| 176 | for (size_t pos = 0; pos < len; ++pos) { | 176 | for (size_t pos = 0; pos < len; ++pos) { |
| 177 | // Populate pageobj_to_pages_pos and fix parent pointer. There | 177 | // Populate pageobj_to_pages_pos and fix parent pointer. There |
| 178 | // should be no duplicates at this point because | 178 | // should be no duplicates at this point because |
| 179 | // pushInheritedAttributesToPage calls getAllPages which | 179 | // pushInheritedAttributesToPage calls getAllPages which |
| 180 | // resolves duplicates. | 180 | // resolves duplicates. |
| 181 | - insertPageobjToPage(this->m->all_pages.at(pos), toI(pos), true); | ||
| 182 | - this->m->all_pages.at(pos).replaceKey("/Parent", pages); | 181 | + insertPageobjToPage(m->all_pages.at(pos), toI(pos), true); |
| 182 | + m->all_pages.at(pos).replaceKey("/Parent", pages); | ||
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | - pages.replaceKey("/Kids", QPDFObjectHandle::newArray(this->m->all_pages)); | 185 | + pages.replaceKey("/Kids", QPDFObjectHandle::newArray(m->all_pages)); |
| 186 | // /Count has not changed | 186 | // /Count has not changed |
| 187 | if (pages.getKey("/Count").getUIntValue() != len) { | 187 | if (pages.getKey("/Count").getUIntValue() != len) { |
| 188 | throw std::runtime_error("/Count is wrong after flattening pages tree"); | 188 | throw std::runtime_error("/Count is wrong after flattening pages tree"); |
| @@ -195,22 +195,21 @@ QPDF::insertPageobjToPage( | @@ -195,22 +195,21 @@ QPDF::insertPageobjToPage( | ||
| 195 | { | 195 | { |
| 196 | QPDFObjGen og(obj.getObjGen()); | 196 | QPDFObjGen og(obj.getObjGen()); |
| 197 | if (check_duplicate) { | 197 | if (check_duplicate) { |
| 198 | - if (!this->m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)) | ||
| 199 | - .second) { | 198 | + if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) { |
| 200 | // The library never calls insertPageobjToPage in a way | 199 | // The library never calls insertPageobjToPage in a way |
| 201 | // that causes this to happen. | 200 | // that causes this to happen. |
| 202 | setLastObjectDescription( | 201 | setLastObjectDescription( |
| 203 | "page " + std::to_string(pos) + " (numbered from zero)", og); | 202 | "page " + std::to_string(pos) + " (numbered from zero)", og); |
| 204 | throw QPDFExc( | 203 | throw QPDFExc( |
| 205 | qpdf_e_pages, | 204 | qpdf_e_pages, |
| 206 | - this->m->file->getName(), | ||
| 207 | - this->m->last_object_description, | 205 | + m->file->getName(), |
| 206 | + m->last_object_description, | ||
| 208 | 0, | 207 | 0, |
| 209 | "duplicate page reference found;" | 208 | "duplicate page reference found;" |
| 210 | " this would cause loss of data"); | 209 | " this would cause loss of data"); |
| 211 | } | 210 | } |
| 212 | } else { | 211 | } else { |
| 213 | - this->m->pageobj_to_pages_pos[og] = pos; | 212 | + m->pageobj_to_pages_pos[og] = pos; |
| 214 | } | 213 | } |
| 215 | } | 214 | } |
| 216 | 215 | ||
| @@ -247,7 +246,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | @@ -247,7 +246,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | ||
| 247 | 2); // insert in middle | 246 | 2); // insert in middle |
| 248 | 247 | ||
| 249 | auto og = newpage.getObjGen(); | 248 | auto og = newpage.getObjGen(); |
| 250 | - if (this->m->pageobj_to_pages_pos.count(og)) { | 249 | + if (m->pageobj_to_pages_pos.count(og)) { |
| 251 | QTC::TC("qpdf", "QPDF resolve duplicated page in insert"); | 250 | QTC::TC("qpdf", "QPDF resolve duplicated page in insert"); |
| 252 | newpage = makeIndirectObject(QPDFObjectHandle(newpage).shallowCopy()); | 251 | newpage = makeIndirectObject(QPDFObjectHandle(newpage).shallowCopy()); |
| 253 | } | 252 | } |
| @@ -259,9 +258,9 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | @@ -259,9 +258,9 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | ||
| 259 | kids.insertItem(pos, newpage); | 258 | kids.insertItem(pos, newpage); |
| 260 | int npages = kids.getArrayNItems(); | 259 | int npages = kids.getArrayNItems(); |
| 261 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); | 260 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); |
| 262 | - this->m->all_pages.insert(this->m->all_pages.begin() + pos, newpage); | 261 | + m->all_pages.insert(m->all_pages.begin() + pos, newpage); |
| 263 | for (int i = pos + 1; i < npages; ++i) { | 262 | for (int i = pos + 1; i < npages; ++i) { |
| 264 | - insertPageobjToPage(this->m->all_pages.at(toS(i)), i, false); | 263 | + insertPageobjToPage(m->all_pages.at(toS(i)), i, false); |
| 265 | } | 264 | } |
| 266 | insertPageobjToPage(newpage, pos, true); | 265 | insertPageobjToPage(newpage, pos, true); |
| 267 | } | 266 | } |
| @@ -284,10 +283,10 @@ QPDF::removePage(QPDFObjectHandle page) | @@ -284,10 +283,10 @@ QPDF::removePage(QPDFObjectHandle page) | ||
| 284 | kids.eraseItem(pos); | 283 | kids.eraseItem(pos); |
| 285 | int npages = kids.getArrayNItems(); | 284 | int npages = kids.getArrayNItems(); |
| 286 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); | 285 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); |
| 287 | - this->m->all_pages.erase(this->m->all_pages.begin() + pos); | ||
| 288 | - this->m->pageobj_to_pages_pos.erase(page.getObjGen()); | 286 | + m->all_pages.erase(m->all_pages.begin() + pos); |
| 287 | + m->pageobj_to_pages_pos.erase(page.getObjGen()); | ||
| 289 | for (int i = pos; i < npages; ++i) { | 288 | for (int i = pos; i < npages; ++i) { |
| 290 | - insertPageobjToPage(this->m->all_pages.at(toS(i)), i, false); | 289 | + insertPageobjToPage(m->all_pages.at(toS(i)), i, false); |
| 291 | } | 290 | } |
| 292 | } | 291 | } |
| 293 | 292 | ||
| @@ -323,14 +322,14 @@ int | @@ -323,14 +322,14 @@ int | ||
| 323 | QPDF::findPage(QPDFObjGen const& og) | 322 | QPDF::findPage(QPDFObjGen const& og) |
| 324 | { | 323 | { |
| 325 | flattenPagesTree(); | 324 | flattenPagesTree(); |
| 326 | - auto it = this->m->pageobj_to_pages_pos.find(og); | ||
| 327 | - if (it == this->m->pageobj_to_pages_pos.end()) { | 325 | + auto it = m->pageobj_to_pages_pos.find(og); |
| 326 | + if (it == m->pageobj_to_pages_pos.end()) { | ||
| 328 | QTC::TC("qpdf", "QPDF_pages findPage not found"); | 327 | QTC::TC("qpdf", "QPDF_pages findPage not found"); |
| 329 | setLastObjectDescription("page object", og); | 328 | setLastObjectDescription("page object", og); |
| 330 | throw QPDFExc( | 329 | throw QPDFExc( |
| 331 | qpdf_e_pages, | 330 | qpdf_e_pages, |
| 332 | - this->m->file->getName(), | ||
| 333 | - this->m->last_object_description, | 331 | + m->file->getName(), |
| 332 | + m->last_object_description, | ||
| 334 | 0, | 333 | 0, |
| 335 | "page object not referenced in /Pages tree"); | 334 | "page object not referenced in /Pages tree"); |
| 336 | } | 335 | } |