aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_linearization.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-05-21 15:42:34 +0200
committerm-holger <m-holger@kubitscheck.org>2023-05-21 15:42:34 +0200
commit85d784952f8a7c4d8c9e614663ebc5b1eb747384 (patch)
treeb2954d6afa41dc1b4d776084bc31222523865665 /libqpdf/QPDF_linearization.cc
parent2028e35928ee8725128f52cae999ac6829dee2fc (diff)
downloadqpdf-85d784952f8a7c4d8c9e614663ebc5b1eb747384.tar.zst
Globally replace 'this->m->' with 'm->'
Using search and replace.
Diffstat (limited to 'libqpdf/QPDF_linearization.cc')
-rw-r--r--libqpdf/QPDF_linearization.cc409
1 files changed, 198 insertions, 211 deletions
diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc
index eade317e..e2035b1b 100644
--- a/libqpdf/QPDF_linearization.cc
+++ b/libqpdf/QPDF_linearization.cc
@@ -67,7 +67,7 @@ load_vector_vector(
void
QPDF::linearizationWarning(std::string_view msg)
{
- this->m->linearization_warnings = true;
+ m->linearization_warnings = true;
warn(qpdf_e_linearization, "", 0, std::string(msg));
}
@@ -91,7 +91,7 @@ QPDF::isLinearized()
{
// If the first object in the file is a dictionary with a suitable
// /Linearized key and has an /L key that accurately indicates the
- // file size, initialize this->m->lindict and return true.
+ // file size, initialize m->lindict and return true.
// A linearized PDF spec's first object will be contained within
// the first 1024 bytes of the file and will be a dictionary with
@@ -105,9 +105,9 @@ QPDF::isLinearized()
auto b = std::make_unique<char[]>(tbuf_size);
char* buf = b.get();
- this->m->file->seek(0, SEEK_SET);
+ m->file->seek(0, SEEK_SET);
memset(buf, '\0', tbuf_size);
- this->m->file->read(buf, tbuf_size - 1);
+ m->file->read(buf, tbuf_size - 1);
int lindict_obj = -1;
char* p = buf;
@@ -121,12 +121,12 @@ QPDF::isLinearized()
}
// Seek to the digit. Then skip over digits for a potential
// next iteration.
- this->m->file->seek(p - buf, SEEK_SET);
+ m->file->seek(p - buf, SEEK_SET);
while (((p - buf) < tbuf_size) && QUtil::is_digit(*p)) {
++p;
}
- QPDFTokenizer::Token t1 = readToken(this->m->file);
+ QPDFTokenizer::Token t1 = readToken(m->file);
if (t1.isInteger() && readToken(m->file).isInteger() &&
readToken(m->file).isWord("obj") &&
(readToken(m->file).getType() == QPDFTokenizer::tt_dict_open)) {
@@ -151,16 +151,16 @@ QPDF::isLinearized()
QPDFObjectHandle L = candidate.getKey("/L");
if (L.isInteger()) {
qpdf_offset_t Li = L.getIntValue();
- this->m->file->seek(0, SEEK_END);
- if (Li != this->m->file->tell()) {
+ m->file->seek(0, SEEK_END);
+ if (Li != m->file->tell()) {
QTC::TC("qpdf", "QPDF /L mismatch");
return false;
} else {
- this->m->linp.file_size = Li;
+ m->linp.file_size = Li;
}
}
- this->m->lindict = candidate;
+ m->lindict = candidate;
return true;
}
@@ -177,12 +177,12 @@ QPDF::readLinearizationData()
}
// /L is read and stored in linp by isLinearized()
- QPDFObjectHandle H = this->m->lindict.getKey("/H");
- QPDFObjectHandle O = this->m->lindict.getKey("/O");
- QPDFObjectHandle E = this->m->lindict.getKey("/E");
- QPDFObjectHandle N = this->m->lindict.getKey("/N");
- QPDFObjectHandle T = this->m->lindict.getKey("/T");
- QPDFObjectHandle P = this->m->lindict.getKey("/P");
+ QPDFObjectHandle H = m->lindict.getKey("/H");
+ QPDFObjectHandle O = m->lindict.getKey("/O");
+ QPDFObjectHandle E = m->lindict.getKey("/E");
+ QPDFObjectHandle N = m->lindict.getKey("/N");
+ QPDFObjectHandle T = m->lindict.getKey("/T");
+ QPDFObjectHandle P = m->lindict.getKey("/P");
if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() &&
T.isInteger() && (P.isInteger() || P.isNull()))) {
@@ -243,13 +243,13 @@ QPDF::readLinearizationData()
}
// file_size initialized by isLinearized()
- this->m->linp.first_page_object = O.getIntValueAsInt();
- this->m->linp.first_page_end = E.getIntValue();
- this->m->linp.npages = N.getIntValueAsInt();
- this->m->linp.xref_zero_offset = T.getIntValue();
- this->m->linp.first_page = first_page;
- this->m->linp.H_offset = H0_offset;
- this->m->linp.H_length = H0_length;
+ m->linp.first_page_object = O.getIntValueAsInt();
+ m->linp.first_page_end = E.getIntValue();
+ m->linp.npages = N.getIntValueAsInt();
+ m->linp.xref_zero_offset = T.getIntValue();
+ m->linp.first_page = first_page;
+ m->linp.H_offset = H0_offset;
+ m->linp.H_length = H0_length;
// Read hint streams
@@ -296,7 +296,7 @@ QPDF::readLinearizationData()
"/O (outline) offset is out of bounds");
}
readHGeneric(
- BitStream(h_buf + HOi, h_size - toS(HOi)), this->m->outline_hints);
+ BitStream(h_buf + HOi, h_size - toS(HOi)), m->outline_hints);
}
}
@@ -311,7 +311,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
QPDFObjGen(0, 0),
og,
false);
- ObjCache& oc = this->m->obj_cache[og];
+ ObjCache& oc = m->obj_cache[og];
qpdf_offset_t min_end_offset = oc.end_before_space;
qpdf_offset_t max_end_offset = oc.end_after_space;
if (!H.isStream()) {
@@ -331,7 +331,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
QTC::TC("qpdf", "QPDF hint table length indirect");
// Force resolution
(void)length_obj.getIntValue();
- ObjCache& oc2 = this->m->obj_cache[length_obj.getObjGen()];
+ ObjCache& oc2 = m->obj_cache[length_obj.getObjGen()];
min_end_offset = oc2.end_before_space;
max_end_offset = oc2.end_after_space;
} else {
@@ -356,7 +356,7 @@ QPDF::readHPageOffset(BitStream h)
// All comments referring to the PDF spec refer to the spec for
// version 1.4.
- HPageOffset& t = this->m->page_offset_hints;
+ HPageOffset& t = m->page_offset_hints;
t.min_nobjects = h.getBitsInt(32); // 1
t.first_page_offset = h.getBitsInt(32); // 2
@@ -374,7 +374,7 @@ QPDF::readHPageOffset(BitStream h)
std::vector<HPageOffsetEntry>& entries = t.entries;
entries.clear();
- int nitems = this->m->linp.npages;
+ int nitems = m->linp.npages;
load_vector_int(
h,
nitems,
@@ -424,7 +424,7 @@ QPDF::readHPageOffset(BitStream h)
void
QPDF::readHSharedObject(BitStream h)
{
- HSharedObject& t = this->m->shared_object_hints;
+ HSharedObject& t = m->shared_object_hints;
t.first_shared_obj = h.getBitsInt(32); // 1
t.first_shared_offset = h.getBitsInt(32); // 2
@@ -485,7 +485,7 @@ QPDF::checkLinearizationInternal()
// Check all values in linearization parameter dictionary
- LinParameters& p = this->m->linp;
+ LinParameters& p = m->linp;
// L: file size in bytes -- checked by isLinearized
@@ -506,7 +506,7 @@ QPDF::checkLinearizationInternal()
for (size_t i = 0; i < toS(npages); ++i) {
QPDFObjectHandle const& page = pages.at(i);
QPDFObjGen og(page.getObjGen());
- if (this->m->xref_table[og].getType() == 2) {
+ if (m->xref_table[og].getType() == 2) {
linearizationWarning(
"page dictionary for page " + std::to_string(i) +
" is compressed");
@@ -514,22 +514,22 @@ QPDF::checkLinearizationInternal()
}
// T: offset of whitespace character preceding xref entry for object 0
- this->m->file->seek(p.xref_zero_offset, SEEK_SET);
+ m->file->seek(p.xref_zero_offset, SEEK_SET);
while (true) {
char ch;
- this->m->file->read(&ch, 1);
+ m->file->read(&ch, 1);
if (!((ch == ' ') || (ch == '\r') || (ch == '\n'))) {
- this->m->file->seek(-1, SEEK_CUR);
+ m->file->seek(-1, SEEK_CUR);
break;
}
}
- if (this->m->file->tell() != this->m->first_xref_item_offset) {
+ if (m->file->tell() != m->first_xref_item_offset) {
QTC::TC("qpdf", "QPDF err /T mismatch");
linearizationWarning(
"space before first xref item (/T) mismatch "
"(computed = " +
- std::to_string(this->m->first_xref_item_offset) +
- "; file = " + std::to_string(this->m->file->tell()));
+ std::to_string(m->first_xref_item_offset) +
+ "; file = " + std::to_string(m->file->tell()));
}
// P: first page number -- Implementation note 124 says Acrobat
@@ -540,7 +540,7 @@ QPDF::checkLinearizationInternal()
// at the end of the containing xref section if any object streams
// are in use.
- if (this->m->uncompressed_after_compressed) {
+ if (m->uncompressed_after_compressed) {
linearizationWarning(
"linearized file contains an uncompressed object"
" after a compressed one in a cross-reference stream");
@@ -553,7 +553,7 @@ QPDF::checkLinearizationInternal()
// uncompressed.
{ // local scope
std::map<int, int> object_stream_data;
- for (auto const& iter: this->m->xref_table) {
+ for (auto const& iter: m->xref_table) {
QPDFObjGen const& og = iter.first;
QPDFXRefEntry const& entry = iter.second;
if (entry.getType() == 2) {
@@ -575,18 +575,18 @@ QPDF::checkLinearizationInternal()
// agree with pdlin. As of this writing, the test suite doesn't
// contain any files with threads.
- if (this->m->part6.empty()) {
+ if (m->part6.empty()) {
stopOnError("linearization part 6 unexpectedly empty");
}
qpdf_offset_t min_E = -1;
qpdf_offset_t max_E = -1;
- for (auto const& oh: this->m->part6) {
+ for (auto const& oh: m->part6) {
QPDFObjGen og(oh.getObjGen());
- if (this->m->obj_cache.count(og) == 0) {
+ if (m->obj_cache.count(og) == 0) {
// All objects have to have been dereferenced to be classified.
throw std::logic_error("linearization part6 object not in cache");
}
- ObjCache const& oc = this->m->obj_cache[og];
+ ObjCache const& oc = m->obj_cache[og];
min_E = std::max(min_E, oc.end_before_space);
max_E = std::max(max_E, oc.end_after_space);
}
@@ -605,21 +605,21 @@ QPDF::checkLinearizationInternal()
checkHPageOffset(pages, shared_idx_to_obj);
checkHOutlines();
- return !this->m->linearization_warnings;
+ return !m->linearization_warnings;
}
qpdf_offset_t
QPDF::maxEnd(ObjUser const& ou)
{
- if (this->m->obj_user_to_objects.count(ou) == 0) {
+ if (m->obj_user_to_objects.count(ou) == 0) {
stopOnError("no entry in object user table for requested object user");
}
qpdf_offset_t end = 0;
- for (auto const& og: this->m->obj_user_to_objects[ou]) {
- if (this->m->obj_cache.count(og) == 0) {
+ for (auto const& og: m->obj_user_to_objects[ou]) {
+ if (m->obj_cache.count(og) == 0) {
stopOnError("unknown object referenced in object user table");
}
- end = std::max(end, this->m->obj_cache[og].end_after_space);
+ end = std::max(end, m->obj_cache[og].end_after_space);
}
return end;
}
@@ -627,7 +627,7 @@ QPDF::maxEnd(ObjUser const& ou)
qpdf_offset_t
QPDF::getLinearizationOffset(QPDFObjGen const& og)
{
- QPDFXRefEntry entry = this->m->xref_table[og];
+ QPDFXRefEntry entry = m->xref_table[og];
qpdf_offset_t result = 0;
switch (entry.getType()) {
case 1:
@@ -667,18 +667,17 @@ QPDF::lengthNextN(int first_object, int n)
int length = 0;
for (int i = 0; i < n; ++i) {
QPDFObjGen og(first_object + i, 0);
- if (this->m->xref_table.count(og) == 0) {
+ if (m->xref_table.count(og) == 0) {
linearizationWarning(
"no xref table entry for " + std::to_string(first_object + i) +
" 0");
} else {
- if (this->m->obj_cache.count(og) == 0) {
+ if (m->obj_cache.count(og) == 0) {
stopOnError("found unknown object while"
" calculating length for linearization data");
}
- length +=
- toI(this->m->obj_cache[og].end_after_space -
- getLinearizationOffset(og));
+ length += toI(
+ m->obj_cache[og].end_after_space - getLinearizationOffset(og));
}
}
return length;
@@ -708,9 +707,9 @@ QPDF::checkHPageOffset(
int npages = toI(pages.size());
qpdf_offset_t table_offset =
- adjusted_offset(this->m->page_offset_hints.first_page_offset);
+ adjusted_offset(m->page_offset_hints.first_page_offset);
QPDFObjGen first_page_og(pages.at(0).getObjGen());
- if (this->m->xref_table.count(first_page_og) == 0) {
+ if (m->xref_table.count(first_page_og) == 0) {
stopOnError("supposed first page object is not known");
}
qpdf_offset_t offset = getLinearizationOffset(first_page_og);
@@ -721,17 +720,14 @@ QPDF::checkHPageOffset(
for (int pageno = 0; pageno < npages; ++pageno) {
QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen());
int first_object = page_og.getObj();
- if (this->m->xref_table.count(page_og) == 0) {
+ if (m->xref_table.count(page_og) == 0) {
stopOnError("unknown object in page offset hint table");
}
offset = getLinearizationOffset(page_og);
- HPageOffsetEntry& he =
- this->m->page_offset_hints.entries.at(toS(pageno));
- CHPageOffsetEntry& ce =
- this->m->c_page_offset_data.entries.at(toS(pageno));
- int h_nobjects =
- he.delta_nobjects + this->m->page_offset_hints.min_nobjects;
+ HPageOffsetEntry& he = m->page_offset_hints.entries.at(toS(pageno));
+ CHPageOffsetEntry& ce = m->c_page_offset_data.entries.at(toS(pageno));
+ int h_nobjects = he.delta_nobjects + m->page_offset_hints.min_nobjects;
if (h_nobjects != ce.nobjects) {
// This happens with pdlin when there are thumbnails.
linearizationWarning(
@@ -743,8 +739,8 @@ QPDF::checkHPageOffset(
// Use value for number of objects in hint table rather than
// computed value if there is a discrepancy.
int length = lengthNextN(first_object, h_nobjects);
- int h_length = toI(
- he.delta_page_length + this->m->page_offset_hints.min_page_length);
+ int h_length =
+ toI(he.delta_page_length + m->page_offset_hints.min_page_length);
if (length != h_length) {
// This condition almost certainly indicates a bad hint
// table or a bug in this code.
@@ -778,10 +774,10 @@ QPDF::checkHPageOffset(
for (size_t i = 0; i < toS(ce.nshared_objects); ++i) {
int idx = ce.shared_identifiers.at(i);
- if (idx >= this->m->c_shared_object_data.nshared_total) {
+ if (idx >= m->c_shared_object_data.nshared_total) {
stopOnError("index out of bounds for shared object hint table");
}
- int obj = this->m->c_shared_object_data.entries.at(toS(idx)).object;
+ int obj = m->c_shared_object_data.entries.at(toS(idx)).object;
computed_shared.insert(obj);
}
@@ -831,7 +827,7 @@ QPDF::checkHSharedObject(
// these whenever there are no shared objects not referenced by
// the first page (i.e., nshared_total == nshared_first_page).
- HSharedObject& so = this->m->shared_object_hints;
+ HSharedObject& so = m->shared_object_hints;
if (so.nshared_total < so.nshared_first_page) {
linearizationWarning("shared object hint table: ntotal < nfirst_page");
} else {
@@ -842,11 +838,11 @@ QPDF::checkHSharedObject(
for (int i = 0; i < so.nshared_total; ++i) {
if (i == so.nshared_first_page) {
QTC::TC("qpdf", "QPDF lin check shared past first page");
- if (this->m->part8.empty()) {
+ if (m->part8.empty()) {
linearizationWarning("part 8 is empty but nshared_total > "
"nshared_first_page");
} else {
- int obj = this->m->part8.at(0).getObjectID();
+ int obj = m->part8.at(0).getObjectID();
if (obj != so.first_shared_obj) {
linearizationWarning(
"first shared object number mismatch: "
@@ -859,7 +855,7 @@ QPDF::checkHSharedObject(
cur_object = so.first_shared_obj;
QPDFObjGen og(cur_object, 0);
- if (this->m->xref_table.count(og) == 0) {
+ if (m->xref_table.count(og) == 0) {
stopOnError("unknown object in shared object hint table");
}
qpdf_offset_t offset = getLinearizationOffset(og);
@@ -901,13 +897,12 @@ QPDF::checkHOutlines()
// wrong starting place). pdlin appears to generate correct
// values in those cases.
- if (this->m->c_outline_data.nobjects == this->m->outline_hints.nobjects) {
- if (this->m->c_outline_data.nobjects == 0) {
+ if (m->c_outline_data.nobjects == m->outline_hints.nobjects) {
+ if (m->c_outline_data.nobjects == 0) {
return;
}
- if (this->m->c_outline_data.first_object ==
- this->m->outline_hints.first_object) {
+ if (m->c_outline_data.first_object == m->outline_hints.first_object) {
// Check length and offset. Acrobat gets these wrong.
QPDFObjectHandle outlines = getRoot().getKey("/Outlines");
if (!outlines.isIndirect()) {
@@ -919,21 +914,21 @@ QPDF::checkHOutlines()
return;
}
QPDFObjGen og(outlines.getObjGen());
- if (this->m->xref_table.count(og) == 0) {
+ if (m->xref_table.count(og) == 0) {
stopOnError("unknown object in outlines hint table");
}
qpdf_offset_t offset = getLinearizationOffset(og);
ObjUser ou(ObjUser::ou_root_key, "/Outlines");
int length = toI(maxEnd(ou) - offset);
qpdf_offset_t table_offset =
- adjusted_offset(this->m->outline_hints.first_object_offset);
+ adjusted_offset(m->outline_hints.first_object_offset);
if (offset != table_offset) {
linearizationWarning(
"incorrect offset in outlines table: hint table = " +
std::to_string(table_offset) +
"; computed = " + std::to_string(offset));
}
- int table_length = this->m->outline_hints.group_length;
+ int table_length = m->outline_hints.group_length;
if (length != table_length) {
linearizationWarning(
"incorrect length in outlines table: hint table = " +
@@ -964,28 +959,28 @@ QPDF::showLinearizationData()
void
QPDF::dumpLinearizationDataInternal()
{
- *this->m->log->getInfo()
- << this->m->file->getName() << ": linearization data:\n\n";
-
- *this->m->log->getInfo()
- << "file_size: " << this->m->linp.file_size << "\n"
- << "first_page_object: " << this->m->linp.first_page_object << "\n"
- << "first_page_end: " << this->m->linp.first_page_end << "\n"
- << "npages: " << this->m->linp.npages << "\n"
- << "xref_zero_offset: " << this->m->linp.xref_zero_offset << "\n"
- << "first_page: " << this->m->linp.first_page << "\n"
- << "H_offset: " << this->m->linp.H_offset << "\n"
- << "H_length: " << this->m->linp.H_length << "\n"
- << "\n";
-
- *this->m->log->getInfo() << "Page Offsets Hint Table\n\n";
+ *m->log->getInfo() << m->file->getName() << ": linearization data:\n\n";
+
+ *m->log->getInfo() << "file_size: " << m->linp.file_size << "\n"
+ << "first_page_object: " << m->linp.first_page_object
+ << "\n"
+ << "first_page_end: " << m->linp.first_page_end << "\n"
+ << "npages: " << m->linp.npages << "\n"
+ << "xref_zero_offset: " << m->linp.xref_zero_offset
+ << "\n"
+ << "first_page: " << m->linp.first_page << "\n"
+ << "H_offset: " << m->linp.H_offset << "\n"
+ << "H_length: " << m->linp.H_length << "\n"
+ << "\n";
+
+ *m->log->getInfo() << "Page Offsets Hint Table\n\n";
dumpHPageOffset();
- *this->m->log->getInfo() << "\nShared Objects Hint Table\n\n";
+ *m->log->getInfo() << "\nShared Objects Hint Table\n\n";
dumpHSharedObject();
- if (this->m->outline_hints.nobjects > 0) {
- *this->m->log->getInfo() << "\nOutlines Hint Table\n\n";
- dumpHGeneric(this->m->outline_hints);
+ if (m->outline_hints.nobjects > 0) {
+ *m->log->getInfo() << "\nOutlines Hint Table\n\n";
+ dumpHGeneric(m->outline_hints);
}
}
@@ -995,8 +990,8 @@ QPDF::adjusted_offset(qpdf_offset_t offset)
// All offsets >= H_offset have to be increased by H_length
// since all hint table location values disregard the hint table
// itself.
- if (offset >= this->m->linp.H_offset) {
- return offset + this->m->linp.H_length;
+ if (offset >= m->linp.H_offset) {
+ return offset + m->linp.H_length;
}
return offset;
}
@@ -1004,8 +999,8 @@ QPDF::adjusted_offset(qpdf_offset_t offset)
void
QPDF::dumpHPageOffset()
{
- HPageOffset& t = this->m->page_offset_hints;
- *this->m->log->getInfo()
+ HPageOffset& t = m->page_offset_hints;
+ *m->log->getInfo()
<< "min_nobjects: " << t.min_nobjects << "\n"
<< "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n"
<< "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n"
@@ -1022,9 +1017,9 @@ QPDF::dumpHPageOffset()
<< "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n"
<< "shared_denominator: " << t.shared_denominator << "\n";
- for (size_t i1 = 0; i1 < toS(this->m->linp.npages); ++i1) {
+ for (size_t i1 = 0; i1 < toS(m->linp.npages); ++i1) {
HPageOffsetEntry& pe = t.entries.at(i1);
- *this->m->log->getInfo()
+ *m->log->getInfo()
<< "Page " << i1 << ":\n"
<< " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n"
<< " length: " << pe.delta_page_length + t.min_page_length
@@ -1036,10 +1031,10 @@ QPDF::dumpHPageOffset()
<< pe.delta_content_length + t.min_content_length << "\n"
<< " nshared_objects: " << pe.nshared_objects << "\n";
for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2) {
- *this->m->log->getInfo() << " identifier " << i2 << ": "
- << pe.shared_identifiers.at(i2) << "\n";
- *this->m->log->getInfo() << " numerator " << i2 << ": "
- << pe.shared_numerators.at(i2) << "\n";
+ *m->log->getInfo() << " identifier " << i2 << ": "
+ << pe.shared_identifiers.at(i2) << "\n";
+ *m->log->getInfo() << " numerator " << i2 << ": "
+ << pe.shared_numerators.at(i2) << "\n";
}
}
}
@@ -1047,30 +1042,30 @@ QPDF::dumpHPageOffset()
void
QPDF::dumpHSharedObject()
{
- HSharedObject& t = this->m->shared_object_hints;
- *this->m->log->getInfo()
- << "first_shared_obj: " << t.first_shared_obj << "\n"
- << "first_shared_offset: " << adjusted_offset(t.first_shared_offset)
- << "\n"
- << "nshared_first_page: " << t.nshared_first_page << "\n"
- << "nshared_total: " << t.nshared_total << "\n"
- << "nbits_nobjects: " << t.nbits_nobjects << "\n"
- << "min_group_length: " << t.min_group_length << "\n"
- << "nbits_delta_group_length: " << t.nbits_delta_group_length << "\n";
+ HSharedObject& t = m->shared_object_hints;
+ *m->log->getInfo() << "first_shared_obj: " << t.first_shared_obj << "\n"
+ << "first_shared_offset: "
+ << adjusted_offset(t.first_shared_offset) << "\n"
+ << "nshared_first_page: " << t.nshared_first_page << "\n"
+ << "nshared_total: " << t.nshared_total << "\n"
+ << "nbits_nobjects: " << t.nbits_nobjects << "\n"
+ << "min_group_length: " << t.min_group_length << "\n"
+ << "nbits_delta_group_length: "
+ << t.nbits_delta_group_length << "\n";
for (size_t i = 0; i < toS(t.nshared_total); ++i) {
HSharedObjectEntry& se = t.entries.at(i);
- *this->m->log->getInfo()
- << "Shared Object " << i << ":\n"
- << " group length: " << se.delta_group_length + t.min_group_length
- << "\n";
+ *m->log->getInfo() << "Shared Object " << i << ":\n"
+ << " group length: "
+ << se.delta_group_length + t.min_group_length
+ << "\n";
// PDF spec says signature present nobjects_minus_one are
// always 0, so print them only if they have a non-zero value.
if (se.signature_present) {
- *this->m->log->getInfo() << " signature present\n";
+ *m->log->getInfo() << " signature present\n";
}
if (se.nobjects_minus_one != 0) {
- *this->m->log->getInfo()
+ *m->log->getInfo()
<< " nobjects: " << se.nobjects_minus_one + 1 << "\n";
}
}
@@ -1079,12 +1074,11 @@ QPDF::dumpHSharedObject()
void
QPDF::dumpHGeneric(HGeneric& t)
{
- *this->m->log->getInfo()
- << "first_object: " << t.first_object << "\n"
- << "first_object_offset: " << adjusted_offset(t.first_object_offset)
- << "\n"
- << "nobjects: " << t.nobjects << "\n"
- << "group_length: " << t.group_length << "\n";
+ *m->log->getInfo() << "first_object: " << t.first_object << "\n"
+ << "first_object_offset: "
+ << adjusted_offset(t.first_object_offset) << "\n"
+ << "nobjects: " << t.nobjects << "\n"
+ << "group_length: " << t.group_length << "\n";
}
void
@@ -1097,7 +1091,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// this function. Note that actual offsets and lengths are not
// computed here, but anything related to object ordering is.
- if (this->m->object_to_obj_users.empty()) {
+ if (m->object_to_obj_users.empty()) {
// Note that we can't call optimize here because we don't know
// whether it should be called with or without allow changes.
throw std::logic_error(
@@ -1152,15 +1146,15 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// * outlines: part 6 or 9
- this->m->part4.clear();
- this->m->part6.clear();
- this->m->part7.clear();
- this->m->part8.clear();
- this->m->part9.clear();
- this->m->c_linp = LinParameters();
- this->m->c_page_offset_data = CHPageOffset();
- this->m->c_shared_object_data = CHSharedObject();
- this->m->c_outline_data = HGeneric();
+ m->part4.clear();
+ m->part6.clear();
+ m->part7.clear();
+ m->part8.clear();
+ m->part9.clear();
+ m->c_linp = LinParameters();
+ m->c_page_offset_data = CHPageOffset();
+ m->c_shared_object_data = CHSharedObject();
+ m->c_outline_data = HGeneric();
QPDFObjectHandle root = getRoot();
bool outlines_in_first_page = false;
@@ -1199,7 +1193,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
std::set<QPDFObjGen> lc_outlines;
std::set<QPDFObjGen> lc_root;
- for (auto& oiter: this->m->object_to_obj_users) {
+ for (auto& oiter: m->object_to_obj_users) {
QPDFObjGen const& og = oiter.first;
std::set<ObjUser>& ous = oiter.second;
@@ -1315,9 +1309,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// npages is the size of the existing pages vector, which has been
// created by traversing the pages tree, and as such is a
// reasonable size.
- this->m->c_linp.npages = npages;
- this->m->c_page_offset_data.entries =
- std::vector<CHPageOffsetEntry>(toS(npages));
+ m->c_linp.npages = npages;
+ m->c_page_offset_data.entries = std::vector<CHPageOffsetEntry>(toS(npages));
// Part 4: open document objects. We don't care about the order.
@@ -1325,9 +1318,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
stopOnError("found other than one root while"
" calculating linearization data");
}
- this->m->part4.push_back(getObject(*(lc_root.begin())));
+ m->part4.push_back(getObject(*(lc_root.begin())));
for (auto const& og: lc_open_document) {
- this->m->part4.push_back(getObject(og));
+ m->part4.push_back(getObject(og));
}
// Part 6: first page objects. Note: implementation note 124
@@ -1347,8 +1340,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
"object not in lc_first_page_private");
}
lc_first_page_private.erase(first_page_og);
- this->m->c_linp.first_page_object = pages.at(0).getObjectID();
- this->m->part6.push_back(pages.at(0));
+ m->c_linp.first_page_object = pages.at(0).getObjectID();
+ m->part6.push_back(pages.at(0));
// The PDF spec "recommends" an order for the rest of the objects,
// 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)
// hint tables.
for (auto const& og: lc_first_page_private) {
- this->m->part6.push_back(getObject(og));
+ m->part6.push_back(getObject(og));
}
for (auto const& og: lc_first_page_shared) {
- this->m->part6.push_back(getObject(og));
+ m->part6.push_back(getObject(og));
}
// Place the outline dictionary if it goes in the first page section.
if (outlines_in_first_page) {
- pushOutlinesToPart(this->m->part6, lc_outlines, object_stream_data);
+ pushOutlinesToPart(m->part6, lc_outlines, object_stream_data);
}
// 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)
// in garbage values for all the shared object identifiers on the
// first page.
- this->m->c_page_offset_data.entries.at(0).nobjects =
- toI(this->m->part6.size());
+ m->c_page_offset_data.entries.at(0).nobjects = toI(m->part6.size());
// Part 7: other pages' private objects
@@ -1391,23 +1383,23 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
std::to_string(i) + " not in lc_other_page_private");
}
lc_other_page_private.erase(page_og);
- this->m->part7.push_back(pages.at(i));
+ m->part7.push_back(pages.at(i));
// Place all non-shared objects referenced by this page,
// updating the page object count for the hint table.
- this->m->c_page_offset_data.entries.at(i).nobjects = 1;
+ m->c_page_offset_data.entries.at(i).nobjects = 1;
ObjUser ou(ObjUser::ou_page, toI(i));
- if (this->m->obj_user_to_objects.count(ou) == 0) {
+ if (m->obj_user_to_objects.count(ou) == 0) {
stopOnError("found unreferenced page while"
" calculating linearization data");
}
- for (auto const& og: this->m->obj_user_to_objects[ou]) {
+ for (auto const& og: m->obj_user_to_objects[ou]) {
if (lc_other_page_private.count(og)) {
lc_other_page_private.erase(og);
- this->m->part7.push_back(getObject(og));
- ++this->m->c_page_offset_data.entries.at(i).nobjects;
+ m->part7.push_back(getObject(og));
+ ++m->c_page_offset_data.entries.at(i).nobjects;
}
}
}
@@ -1423,7 +1415,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Order is unimportant.
for (auto const& og: lc_other_page_shared) {
- this->m->part8.push_back(getObject(og));
+ m->part8.push_back(getObject(og));
}
// Part 9: other objects
@@ -1437,7 +1429,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Place the pages tree.
std::set<QPDFObjGen> pages_ogs =
- this->m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")];
+ m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")];
if (pages_ogs.empty()) {
stopOnError("found empty pages tree while"
" calculating linearization data");
@@ -1445,7 +1437,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto const& og: pages_ogs) {
if (lc_other.count(og)) {
lc_other.erase(og);
- this->m->part9.push_back(getObject(og));
+ m->part9.push_back(getObject(og));
}
}
@@ -1460,7 +1452,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
QPDFObjGen thumb_og(thumb.getObjGen());
if (lc_thumbnail_private.count(thumb_og)) {
lc_thumbnail_private.erase(thumb_og);
- this->m->part9.push_back(thumb);
+ m->part9.push_back(thumb);
} else {
// No internal error this time...there's nothing to
// stop this object from having been referred to
@@ -1475,7 +1467,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto const& og: ogs) {
if (lc_thumbnail_private.count(og)) {
lc_thumbnail_private.erase(og);
- this->m->part9.push_back(getObject(og));
+ m->part9.push_back(getObject(og));
}
}
}
@@ -1488,24 +1480,24 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Place shared thumbnail objects
for (auto const& og: lc_thumbnail_shared) {
- this->m->part9.push_back(getObject(og));
+ m->part9.push_back(getObject(og));
}
// Place outlines unless in first page
if (!outlines_in_first_page) {
- pushOutlinesToPart(this->m->part9, lc_outlines, object_stream_data);
+ pushOutlinesToPart(m->part9, lc_outlines, object_stream_data);
}
// Place all remaining objects
for (auto const& og: lc_other) {
- this->m->part9.push_back(getObject(og));
+ m->part9.push_back(getObject(og));
}
// Make sure we got everything exactly once.
- size_t num_placed = this->m->part4.size() + this->m->part6.size() +
- this->m->part7.size() + this->m->part8.size() + this->m->part9.size();
- size_t num_wanted = this->m->object_to_obj_users.size();
+ size_t num_placed = m->part4.size() + m->part6.size() + m->part7.size() +
+ m->part8.size() + m->part9.size();
+ size_t num_wanted = m->object_to_obj_users.size();
if (num_placed != num_wanted) {
stopOnError(
"INTERNAL ERROR: QPDF::calculateLinearizationData: wrong "
@@ -1527,31 +1519,27 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// can map from object number only without regards to generation.
std::map<int, int> obj_to_index;
- this->m->c_shared_object_data.nshared_first_page =
- toI(this->m->part6.size());
- this->m->c_shared_object_data.nshared_total =
- this->m->c_shared_object_data.nshared_first_page +
- toI(this->m->part8.size());
+ m->c_shared_object_data.nshared_first_page = toI(m->part6.size());
+ m->c_shared_object_data.nshared_total =
+ m->c_shared_object_data.nshared_first_page + toI(m->part8.size());
- std::vector<CHSharedObjectEntry>& shared =
- this->m->c_shared_object_data.entries;
- for (auto& oh: this->m->part6) {
+ std::vector<CHSharedObjectEntry>& shared = m->c_shared_object_data.entries;
+ for (auto& oh: m->part6) {
int obj = oh.getObjectID();
obj_to_index[obj] = toI(shared.size());
shared.push_back(CHSharedObjectEntry(obj));
}
- QTC::TC("qpdf", "QPDF lin part 8 empty", this->m->part8.empty() ? 1 : 0);
- if (!this->m->part8.empty()) {
- this->m->c_shared_object_data.first_shared_obj =
- this->m->part8.at(0).getObjectID();
- for (auto& oh: this->m->part8) {
+ QTC::TC("qpdf", "QPDF lin part 8 empty", m->part8.empty() ? 1 : 0);
+ if (!m->part8.empty()) {
+ m->c_shared_object_data.first_shared_obj = m->part8.at(0).getObjectID();
+ for (auto& oh: m->part8) {
int obj = oh.getObjectID();
obj_to_index[obj] = toI(shared.size());
shared.push_back(CHSharedObjectEntry(obj));
}
}
- if (static_cast<size_t>(this->m->c_shared_object_data.nshared_total) !=
- this->m->c_shared_object_data.entries.size()) {
+ if (static_cast<size_t>(m->c_shared_object_data.nshared_total) !=
+ m->c_shared_object_data.entries.size()) {
stopOnError("shared object hint table has wrong number of entries");
}
@@ -1559,14 +1547,14 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// first page.
for (size_t i = 1; i < toS(npages); ++i) {
- CHPageOffsetEntry& pe = this->m->c_page_offset_data.entries.at(i);
+ CHPageOffsetEntry& pe = m->c_page_offset_data.entries.at(i);
ObjUser ou(ObjUser::ou_page, toI(i));
- if (this->m->obj_user_to_objects.count(ou) == 0) {
+ if (m->obj_user_to_objects.count(ou) == 0) {
stopOnError("found unreferenced page while"
" calculating linearization data");
}
- for (auto const& og: this->m->obj_user_to_objects[ou]) {
- if ((this->m->object_to_obj_users[og].size() > 1) &&
+ for (auto const& og: m->obj_user_to_objects[ou]) {
+ if ((m->object_to_obj_users[og].size() > 1) &&
(obj_to_index.count(og.getObj()) > 0)) {
int idx = obj_to_index[og.getObj()];
++pe.nshared_objects;
@@ -1592,16 +1580,16 @@ QPDF::pushOutlinesToPart(
QTC::TC(
"qpdf",
"QPDF lin outlines in part",
- ((&part == (&this->m->part6)) ? 0
- : (&part == (&this->m->part9)) ? 1
- : 9999)); // can't happen
- this->m->c_outline_data.first_object = outlines_og.getObj();
- this->m->c_outline_data.nobjects = 1;
+ ((&part == (&m->part6)) ? 0
+ : (&part == (&m->part9)) ? 1
+ : 9999)); // can't happen
+ m->c_outline_data.first_object = outlines_og.getObj();
+ m->c_outline_data.nobjects = 1;
lc_outlines.erase(outlines_og);
part.push_back(outlines);
for (auto const& og: lc_outlines) {
part.push_back(getObject(og));
- ++this->m->c_outline_data.nobjects;
+ ++m->c_outline_data.nobjects;
}
}
@@ -1615,11 +1603,11 @@ QPDF::getLinearizedParts(
std::vector<QPDFObjectHandle>& part9)
{
calculateLinearizationData(object_stream_data);
- part4 = this->m->part4;
- part6 = this->m->part6;
- part7 = this->m->part7;
- part8 = this->m->part8;
- part9 = this->m->part9;
+ part4 = m->part4;
+ part6 = m->part6;
+ part7 = m->part7;
+ part8 = m->part8;
+ part9 = m->part9;
}
static inline int
@@ -1668,7 +1656,7 @@ QPDF::calculateHPageOffset(
std::vector<QPDFObjectHandle> const& pages = getAllPages();
size_t npages = pages.size();
- CHPageOffset& cph = this->m->c_page_offset_data;
+ CHPageOffset& cph = m->c_page_offset_data;
std::vector<CHPageOffsetEntry>& cphe = cph.entries;
// Calculate minimum and maximum values for number of objects per
@@ -1681,7 +1669,7 @@ QPDF::calculateHPageOffset(
int max_length = min_length;
int max_shared = cphe.at(0).nshared_objects;
- HPageOffset& ph = this->m->page_offset_hints;
+ HPageOffset& ph = m->page_offset_hints;
std::vector<HPageOffsetEntry>& phe = ph.entries;
// npages is the size of the existing pages array.
phe = std::vector<HPageOffsetEntry>(npages);
@@ -1717,8 +1705,7 @@ QPDF::calculateHPageOffset(
ph.min_page_length = min_length;
ph.nbits_delta_page_length = nbits(max_length - min_length);
ph.nbits_nshared_objects = nbits(max_shared);
- ph.nbits_shared_identifier =
- nbits(this->m->c_shared_object_data.nshared_total);
+ ph.nbits_shared_identifier = nbits(m->c_shared_object_data.nshared_total);
ph.shared_denominator = 4; // doesn't matter
// It isn't clear how to compute content offset and content
@@ -1754,9 +1741,9 @@ QPDF::calculateHSharedObject(
std::map<int, qpdf_offset_t> const& lengths,
std::map<int, int> const& obj_renumber)
{
- CHSharedObject& cso = this->m->c_shared_object_data;
+ CHSharedObject& cso = m->c_shared_object_data;
std::vector<CHSharedObjectEntry>& csoe = cso.entries;
- HSharedObject& so = this->m->shared_object_hints;
+ HSharedObject& so = m->shared_object_hints;
std::vector<HSharedObjectEntry>& soe = so.entries;
soe.clear();
@@ -1804,13 +1791,13 @@ QPDF::calculateHOutline(
std::map<int, qpdf_offset_t> const& lengths,
std::map<int, int> const& obj_renumber)
{
- HGeneric& cho = this->m->c_outline_data;
+ HGeneric& cho = m->c_outline_data;
if (cho.nobjects == 0) {
return;
}
- HGeneric& ho = this->m->outline_hints;
+ HGeneric& ho = m->outline_hints;
ho.first_object = (*(obj_renumber.find(cho.first_object))).second;
ho.first_object_offset = (*(xref.find(ho.first_object))).second.getOffset();
@@ -1861,7 +1848,7 @@ write_vector_vector(
void
QPDF::writeHPageOffset(BitWriter& w)
{
- HPageOffset& t = this->m->page_offset_hints;
+ HPageOffset& t = m->page_offset_hints;
w.writeBitsInt(t.min_nobjects, 32); // 1
w.writeBitsInt(toI(t.first_page_offset), 32); // 2
@@ -1929,7 +1916,7 @@ QPDF::writeHPageOffset(BitWriter& w)
void
QPDF::writeHSharedObject(BitWriter& w)
{
- HSharedObject& t = this->m->shared_object_hints;
+ HSharedObject& t = m->shared_object_hints;
w.writeBitsInt(t.first_shared_obj, 32); // 1
w.writeBitsInt(toI(t.first_shared_offset), 32); // 2
@@ -2004,9 +1991,9 @@ QPDF::generateHintStream(
S = toI(c.getCount());
writeHSharedObject(w);
O = 0;
- if (this->m->outline_hints.nobjects > 0) {
+ if (m->outline_hints.nobjects > 0) {
O = toI(c.getCount());
- writeHGeneric(w, this->m->outline_hints);
+ writeHGeneric(w, m->outline_hints);
}
c.finish();