mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-31 14:01:59 +00:00
Update some code manually to get better formatting results
Add comments to force line breaks, parenthesize function arguments that are contatenated strings, etc. -- these kinds of changes improve clang-format's results and also cause emacs cc-mode to match clang-format. After this type of change, most of the time, when clang-format and emacs disagree, clang-format is better.
This commit is contained in:
parent
12f1eb15ca
commit
77e889495f
2
TODO
2
TODO
@ -51,7 +51,7 @@ Use clang-format-15.
|
|||||||
done
|
done
|
||||||
|
|
||||||
* Carefully inspect the diff. There are some places where a comment to
|
* Carefully inspect the diff. There are some places where a comment to
|
||||||
force a line break might be in order.
|
force a line break might be in order. Document use of // line-break
|
||||||
|
|
||||||
* Update README-maintainer about formatting. Mention
|
* Update README-maintainer about formatting. Mention
|
||||||
|
|
||||||
|
@ -45,25 +45,29 @@ process(
|
|||||||
|
|
||||||
// Create an indirect object for the built-in Helvetica font. This
|
// Create an indirect object for the built-in Helvetica font. This
|
||||||
// uses the qpdf literal syntax introduced in qpdf 10.6.
|
// uses the qpdf literal syntax introduced in qpdf 10.6.
|
||||||
auto f1 = q.makeIndirectObject("<<"
|
auto f1 = q.makeIndirectObject(
|
||||||
" /Type /Font"
|
// force line-break
|
||||||
" /Subtype /Type1"
|
"<<"
|
||||||
" /Name /F1"
|
" /Type /Font"
|
||||||
" /BaseFont /Helvetica"
|
" /Subtype /Type1"
|
||||||
" /Encoding /WinAnsiEncoding"
|
" /Name /F1"
|
||||||
">>"_qpdf);
|
" /BaseFont /Helvetica"
|
||||||
|
" /Encoding /WinAnsiEncoding"
|
||||||
|
">>"_qpdf);
|
||||||
|
|
||||||
// Create a resources dictionary with fonts. This uses the new
|
// Create a resources dictionary with fonts. This uses the new
|
||||||
// parse introduced in qpdf 10.2 that takes a QPDF* and allows
|
// parse introduced in qpdf 10.2 that takes a QPDF* and allows
|
||||||
// indirect object references.
|
// indirect object references.
|
||||||
auto resources = q.makeIndirectObject(QPDFObjectHandle::parse(
|
auto resources = q.makeIndirectObject(
|
||||||
&q,
|
// line-break
|
||||||
"<<"
|
QPDFObjectHandle::parse(
|
||||||
" /Font <<"
|
&q,
|
||||||
" /F1 " +
|
("<<"
|
||||||
f1.unparse() +
|
" /Font <<"
|
||||||
" >>"
|
" /F1 " +
|
||||||
">>"));
|
f1.unparse() +
|
||||||
|
" >>"
|
||||||
|
">>")));
|
||||||
|
|
||||||
// Create a file spec.
|
// Create a file spec.
|
||||||
std::string key = QUtil::path_basename(attachment);
|
std::string key = QUtil::path_basename(attachment);
|
||||||
@ -108,45 +112,45 @@ process(
|
|||||||
apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf);
|
apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf);
|
||||||
auto annot = q.makeIndirectObject(QPDFObjectHandle::parse(
|
auto annot = q.makeIndirectObject(QPDFObjectHandle::parse(
|
||||||
&q,
|
&q,
|
||||||
"<<"
|
("<<"
|
||||||
" /AP <<"
|
" /AP <<"
|
||||||
" /N " +
|
" /N " +
|
||||||
ap.unparse() +
|
ap.unparse() +
|
||||||
" >>"
|
" >>"
|
||||||
" /Contents " +
|
" /Contents " +
|
||||||
QPDFObjectHandle::newUnicodeString(attachment).unparse() +
|
QPDFObjectHandle::newUnicodeString(attachment).unparse() + " /FS " +
|
||||||
" /FS " + fs.getObjectHandle().unparse() + " /NM " +
|
fs.getObjectHandle().unparse() + " /NM " +
|
||||||
QPDFObjectHandle::newUnicodeString(attachment).unparse() +
|
QPDFObjectHandle::newUnicodeString(attachment).unparse() +
|
||||||
" /Rect [ 72 700 92 720 ]"
|
" /Rect [ 72 700 92 720 ]"
|
||||||
" /Subtype /FileAttachment"
|
" /Subtype /FileAttachment"
|
||||||
" /Type /Annot"
|
" /Type /Annot"
|
||||||
">>"));
|
">>")));
|
||||||
|
|
||||||
// Generate contents for the page.
|
// Generate contents for the page.
|
||||||
auto contents = QPDFObjectHandle::newStream(
|
auto contents = QPDFObjectHandle::newStream(
|
||||||
&q,
|
&q,
|
||||||
"q\n"
|
("q\n"
|
||||||
"BT\n"
|
"BT\n"
|
||||||
" 102 700 Td\n"
|
" 102 700 Td\n"
|
||||||
" /F1 16 Tf\n"
|
" /F1 16 Tf\n"
|
||||||
" (Here is an attachment.) Tj\n"
|
" (Here is an attachment.) Tj\n"
|
||||||
"ET\n"
|
"ET\n"
|
||||||
"Q\n");
|
"Q\n"));
|
||||||
|
|
||||||
// Create the page object.
|
// Create the page object.
|
||||||
auto page = QPDFObjectHandle::parse(
|
auto page = QPDFObjectHandle::parse(
|
||||||
&q,
|
&q,
|
||||||
"<<"
|
("<<"
|
||||||
" /Annots [ " +
|
" /Annots [ " +
|
||||||
annot.unparse() +
|
annot.unparse() +
|
||||||
" ]"
|
" ]"
|
||||||
" /Contents " +
|
" /Contents " +
|
||||||
contents.unparse() +
|
contents.unparse() +
|
||||||
" /MediaBox [0 0 612 792]"
|
" /MediaBox [0 0 612 792]"
|
||||||
" /Resources " +
|
" /Resources " +
|
||||||
resources.unparse() +
|
resources.unparse() +
|
||||||
" /Type /Page"
|
" /Type /Page"
|
||||||
">>");
|
">>"));
|
||||||
|
|
||||||
// Add the page.
|
// Add the page.
|
||||||
q.addPage(page, true);
|
q.addPage(page, true);
|
||||||
|
@ -180,11 +180,13 @@ add_page(
|
|||||||
size_t width = p->getWidth();
|
size_t width = p->getWidth();
|
||||||
size_t height = p->getHeight();
|
size_t height = p->getHeight();
|
||||||
QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf);
|
QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf);
|
||||||
auto image_dict = "<<"
|
auto image_dict =
|
||||||
" /Type /XObject"
|
// line-break
|
||||||
" /Subtype /Image"
|
"<<"
|
||||||
" /BitsPerComponent 8"
|
" /Type /XObject"
|
||||||
">>"_qpdf;
|
" /Subtype /Image"
|
||||||
|
" /BitsPerComponent 8"
|
||||||
|
">>"_qpdf;
|
||||||
image_dict.replaceKey("/ColorSpace", newName(color_space));
|
image_dict.replaceKey("/ColorSpace", newName(color_space));
|
||||||
image_dict.replaceKey("/Width", newInteger(width));
|
image_dict.replaceKey("/Width", newInteger(width));
|
||||||
image_dict.replaceKey("/Height", newInteger(height));
|
image_dict.replaceKey("/Height", newInteger(height));
|
||||||
@ -352,13 +354,15 @@ create_pdf(char const* filename)
|
|||||||
|
|
||||||
// Add an indirect object to contain a font descriptor for the
|
// Add an indirect object to contain a font descriptor for the
|
||||||
// built-in Helvetica font.
|
// built-in Helvetica font.
|
||||||
QPDFObjectHandle font = pdf.makeIndirectObject("<<"
|
QPDFObjectHandle font = pdf.makeIndirectObject(
|
||||||
" /Type /Font"
|
// line-break
|
||||||
" /Subtype /Type1"
|
"<<"
|
||||||
" /Name /F1"
|
" /Type /Font"
|
||||||
" /BaseFont /Helvetica"
|
" /Subtype /Type1"
|
||||||
" /Encoding /WinAnsiEncoding"
|
" /Name /F1"
|
||||||
">>"_qpdf);
|
" /BaseFont /Helvetica"
|
||||||
|
" /Encoding /WinAnsiEncoding"
|
||||||
|
">>"_qpdf);
|
||||||
|
|
||||||
std::vector<std::string> color_spaces;
|
std::vector<std::string> color_spaces;
|
||||||
color_spaces.push_back("/DeviceCMYK");
|
color_spaces.push_back("/DeviceCMYK");
|
||||||
|
@ -47,8 +47,10 @@ BitStream::getBitsSigned(size_t nbits)
|
|||||||
int
|
int
|
||||||
BitStream::getBitsInt(size_t nbits)
|
BitStream::getBitsInt(size_t nbits)
|
||||||
{
|
{
|
||||||
return static_cast<int>(QIntC::to_uint(
|
return static_cast<int>(
|
||||||
read_bits(this->p, this->bit_offset, this->bits_available, nbits)));
|
// line-break
|
||||||
|
QIntC::to_uint(
|
||||||
|
read_bits(this->p, this->bit_offset, this->bits_available, nbits)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -96,9 +96,9 @@ void
|
|||||||
FileInputSource::seek(qpdf_offset_t offset, int whence)
|
FileInputSource::seek(qpdf_offset_t offset, int whence)
|
||||||
{
|
{
|
||||||
QUtil::os_wrapper(
|
QUtil::os_wrapper(
|
||||||
std::string("seek to ") + this->m->filename + ", offset " +
|
(std::string("seek to ") + this->m->filename + ", offset " +
|
||||||
QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) +
|
QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) +
|
||||||
")",
|
")"),
|
||||||
QUtil::seek(this->m->file, offset, whence));
|
QUtil::seek(this->m->file, offset, whence));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +120,8 @@ FileInputSource::read(char* buffer, size_t length)
|
|||||||
this->m->filename,
|
this->m->filename,
|
||||||
"",
|
"",
|
||||||
this->last_offset,
|
this->last_offset,
|
||||||
std::string("read ") + QUtil::uint_to_string(length) +
|
(std::string("read ") + QUtil::uint_to_string(length) +
|
||||||
" bytes");
|
" bytes"));
|
||||||
} else if (length > 0) {
|
} else if (length > 0) {
|
||||||
this->seek(0, SEEK_END);
|
this->seek(0, SEEK_END);
|
||||||
this->last_offset = this->tell();
|
this->last_offset = this->tell();
|
||||||
|
@ -121,9 +121,12 @@ InputSource::findFirst(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search for the first character.
|
// Search for the first character.
|
||||||
if ((p = static_cast<char*>(memchr(
|
if ((p = static_cast<char*>(
|
||||||
p, start_chars[0], bytes_read - QIntC::to_size(p - buf)))) !=
|
// line-break
|
||||||
0) {
|
memchr(
|
||||||
|
p,
|
||||||
|
start_chars[0],
|
||||||
|
bytes_read - QIntC::to_size(p - buf)))) != 0) {
|
||||||
if (p == buf) {
|
if (p == buf) {
|
||||||
QTC::TC("libtests", "InputSource found match at buf[0]");
|
QTC::TC("libtests", "InputSource found match at buf[0]");
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,14 @@ warn(QPDF* qpdf, QPDFObjectHandle& node, std::string const& msg)
|
|||||||
// ABI: in qpdf 11, change to a reference.
|
// ABI: in qpdf 11, change to a reference.
|
||||||
|
|
||||||
if (qpdf) {
|
if (qpdf) {
|
||||||
qpdf->warn(QPDFExc(
|
qpdf->warn(
|
||||||
qpdf_e_damaged_pdf,
|
// line-break
|
||||||
qpdf->getFilename(),
|
QPDFExc(
|
||||||
get_description(node),
|
qpdf_e_damaged_pdf,
|
||||||
0,
|
qpdf->getFilename(),
|
||||||
msg));
|
get_description(node),
|
||||||
|
0,
|
||||||
|
msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,8 +124,8 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward)
|
|||||||
warn(
|
warn(
|
||||||
impl.qpdf,
|
impl.qpdf,
|
||||||
pe.node,
|
pe.node,
|
||||||
"skipping over invalid kid at index " +
|
("skipping over invalid kid at index " +
|
||||||
QUtil::int_to_string(pe.kid_number));
|
QUtil::int_to_string(pe.kid_number)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = QPDFObjectHandle::newNull();
|
result = QPDFObjectHandle::newNull();
|
||||||
@ -179,8 +181,8 @@ NNTreeIterator::increment(bool backward)
|
|||||||
warn(
|
warn(
|
||||||
impl.qpdf,
|
impl.qpdf,
|
||||||
this->node,
|
this->node,
|
||||||
"item " + QUtil::int_to_string(this->item_number) +
|
("item " + QUtil::int_to_string(this->item_number) +
|
||||||
" has the wrong type");
|
" has the wrong type"));
|
||||||
} else {
|
} else {
|
||||||
found_valid_key = true;
|
found_valid_key = true;
|
||||||
}
|
}
|
||||||
@ -708,9 +710,9 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
|
|||||||
warn(
|
warn(
|
||||||
impl.qpdf,
|
impl.qpdf,
|
||||||
node,
|
node,
|
||||||
"converting kid number " +
|
("converting kid number " +
|
||||||
QUtil::int_to_string(kid_number) +
|
QUtil::int_to_string(kid_number) +
|
||||||
" to an indirect object");
|
" to an indirect object"));
|
||||||
next = impl.qpdf->makeIndirectObject(next);
|
next = impl.qpdf->makeIndirectObject(next);
|
||||||
kids.setArrayItem(kid_number, next);
|
kids.setArrayItem(kid_number, next);
|
||||||
} else {
|
} else {
|
||||||
@ -718,8 +720,8 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
|
|||||||
warn(
|
warn(
|
||||||
impl.qpdf,
|
impl.qpdf,
|
||||||
node,
|
node,
|
||||||
"kid number " + QUtil::int_to_string(kid_number) +
|
("kid number " + QUtil::int_to_string(kid_number) +
|
||||||
" is not an indirect object");
|
" is not an indirect object"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node = next;
|
node = next;
|
||||||
@ -732,8 +734,8 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
|
|||||||
warn(
|
warn(
|
||||||
impl.qpdf,
|
impl.qpdf,
|
||||||
node,
|
node,
|
||||||
"name/number tree node has neither non-empty " +
|
("name/number tree node has neither non-empty " +
|
||||||
impl.details.itemsKey() + " nor /Kids");
|
impl.details.itemsKey() + " nor /Kids"));
|
||||||
failed = true;
|
failed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -876,8 +878,8 @@ NNTreeImpl::compareKeyItem(
|
|||||||
error(
|
error(
|
||||||
qpdf,
|
qpdf,
|
||||||
this->oh,
|
this->oh,
|
||||||
"item at index " + QUtil::int_to_string(2 * idx) +
|
("item at index " + QUtil::int_to_string(2 * idx) +
|
||||||
" is not the right type");
|
" is not the right type"));
|
||||||
}
|
}
|
||||||
return details.compareKeys(key, items.getArrayItem(2 * idx));
|
return details.compareKeys(key, items.getArrayItem(2 * idx));
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,9 @@ static void
|
|||||||
jpeg_pipeline_dest(
|
jpeg_pipeline_dest(
|
||||||
j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next)
|
j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next)
|
||||||
{
|
{
|
||||||
cinfo->dest =
|
cinfo->dest = static_cast<struct jpeg_destination_mgr*>(
|
||||||
static_cast<struct jpeg_destination_mgr*>((*cinfo->mem->alloc_small)(
|
// line-break
|
||||||
|
(*cinfo->mem->alloc_small)(
|
||||||
reinterpret_cast<j_common_ptr>(cinfo),
|
reinterpret_cast<j_common_ptr>(cinfo),
|
||||||
JPOOL_PERMANENT,
|
JPOOL_PERMANENT,
|
||||||
sizeof(dct_pipeline_dest)));
|
sizeof(dct_pipeline_dest)));
|
||||||
@ -239,10 +240,12 @@ term_buffer_source(j_decompress_ptr)
|
|||||||
static void
|
static void
|
||||||
jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer)
|
jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer)
|
||||||
{
|
{
|
||||||
cinfo->src = reinterpret_cast<jpeg_source_mgr*>((*cinfo->mem->alloc_small)(
|
cinfo->src = reinterpret_cast<jpeg_source_mgr*>(
|
||||||
reinterpret_cast<j_common_ptr>(cinfo),
|
// line-break
|
||||||
JPOOL_PERMANENT,
|
(*cinfo->mem->alloc_small)(
|
||||||
sizeof(jpeg_source_mgr)));
|
reinterpret_cast<j_common_ptr>(cinfo),
|
||||||
|
JPOOL_PERMANENT,
|
||||||
|
sizeof(jpeg_source_mgr)));
|
||||||
|
|
||||||
jpeg_source_mgr* src = cinfo->src;
|
jpeg_source_mgr* src = cinfo->src;
|
||||||
src->init_source = init_buffer_source;
|
src->init_source = init_buffer_source;
|
||||||
|
@ -44,8 +44,10 @@ void
|
|||||||
Pl_QPDFTokenizer::finish()
|
Pl_QPDFTokenizer::finish()
|
||||||
{
|
{
|
||||||
this->m->buf.finish();
|
this->m->buf.finish();
|
||||||
auto input = PointerHolder<InputSource>(new BufferInputSource(
|
auto input = PointerHolder<InputSource>(
|
||||||
"tokenizer data", this->m->buf.getBuffer(), true));
|
// line-break
|
||||||
|
new BufferInputSource(
|
||||||
|
"tokenizer data", this->m->buf.getBuffer(), true));
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
QPDFTokenizer::Token token = this->m->tokenizer.readToken(
|
QPDFTokenizer::Token token = this->m->tokenizer.readToken(
|
||||||
@ -59,8 +61,10 @@ Pl_QPDFTokenizer::finish()
|
|||||||
// Read the space after the ID.
|
// Read the space after the ID.
|
||||||
char ch = ' ';
|
char ch = ' ';
|
||||||
input->read(&ch, 1);
|
input->read(&ch, 1);
|
||||||
this->m->filter->handleToken(QPDFTokenizer::Token(
|
this->m->filter->handleToken(
|
||||||
QPDFTokenizer::tt_space, std::string(1, ch)));
|
// line-break
|
||||||
|
QPDFTokenizer::Token(
|
||||||
|
QPDFTokenizer::tt_space, std::string(1, ch)));
|
||||||
QTC::TC("qpdf", "Pl_QPDFTokenizer found ID");
|
QTC::TC("qpdf", "Pl_QPDFTokenizer found ID");
|
||||||
this->m->tokenizer.expectInlineImage(input);
|
this->m->tokenizer.expectInlineImage(input);
|
||||||
}
|
}
|
||||||
|
160
libqpdf/QPDF.cc
160
libqpdf/QPDF.cc
@ -31,22 +31,24 @@
|
|||||||
// it, and the C API relies on its being static as well.
|
// it, and the C API relies on its being static as well.
|
||||||
std::string const QPDF::qpdf_version(QPDF_VERSION);
|
std::string const QPDF::qpdf_version(QPDF_VERSION);
|
||||||
|
|
||||||
static char const* EMPTY_PDF = "%PDF-1.3\n"
|
static char const* EMPTY_PDF = (
|
||||||
"1 0 obj\n"
|
// force line break
|
||||||
"<< /Type /Catalog /Pages 2 0 R >>\n"
|
"%PDF-1.3\n"
|
||||||
"endobj\n"
|
"1 0 obj\n"
|
||||||
"2 0 obj\n"
|
"<< /Type /Catalog /Pages 2 0 R >>\n"
|
||||||
"<< /Type /Pages /Kids [] /Count 0 >>\n"
|
"endobj\n"
|
||||||
"endobj\n"
|
"2 0 obj\n"
|
||||||
"xref\n"
|
"<< /Type /Pages /Kids [] /Count 0 >>\n"
|
||||||
"0 3\n"
|
"endobj\n"
|
||||||
"0000000000 65535 f \n"
|
"xref\n"
|
||||||
"0000000009 00000 n \n"
|
"0 3\n"
|
||||||
"0000000058 00000 n \n"
|
"0000000000 65535 f \n"
|
||||||
"trailer << /Size 3 /Root 1 0 R >>\n"
|
"0000000009 00000 n \n"
|
||||||
"startxref\n"
|
"0000000058 00000 n \n"
|
||||||
"110\n"
|
"trailer << /Size 3 /Root 1 0 R >>\n"
|
||||||
"%%EOF\n";
|
"startxref\n"
|
||||||
|
"110\n"
|
||||||
|
"%%EOF\n");
|
||||||
|
|
||||||
class InvalidInputSource: public InputSource
|
class InvalidInputSource: public InputSource
|
||||||
{
|
{
|
||||||
@ -292,10 +294,12 @@ QPDF::processMemoryFile(
|
|||||||
char const* password)
|
char const* password)
|
||||||
{
|
{
|
||||||
processInputSource(
|
processInputSource(
|
||||||
PointerHolder<InputSource>(new BufferInputSource(
|
PointerHolder<InputSource>(
|
||||||
description,
|
// line-break
|
||||||
new Buffer(QUtil::unsigned_char_pointer(buf), length),
|
new BufferInputSource(
|
||||||
true)),
|
description,
|
||||||
|
new Buffer(QUtil::unsigned_char_pointer(buf), length),
|
||||||
|
true)),
|
||||||
password);
|
password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,10 +757,10 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
std::string("reported number of objects (") +
|
(std::string("reported number of objects (") +
|
||||||
QUtil::int_to_string(size) +
|
QUtil::int_to_string(size) +
|
||||||
") is not one plus the highest object number (" +
|
") is not one plus the highest object number (" +
|
||||||
QUtil::int_to_string(max_obj) + ")"));
|
QUtil::int_to_string(max_obj) + ")")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We no longer need the deleted_objects table, so go ahead and
|
// We no longer need the deleted_objects table, so go ahead and
|
||||||
@ -1145,8 +1149,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"xref stream",
|
"xref stream",
|
||||||
xref_offset,
|
xref_offset,
|
||||||
"Cross-reference stream's /Index's item " +
|
("Cross-reference stream's /Index's item " +
|
||||||
QUtil::int_to_string(i) + " is not an integer");
|
QUtil::int_to_string(i) + " is not an integer"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QTC::TC("qpdf", "QPDF xref /Index is array", n_index == 2 ? 0 : 1);
|
QTC::TC("qpdf", "QPDF xref /Index is array", n_index == 2 ? 0 : 1);
|
||||||
@ -1165,11 +1169,11 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"xref stream",
|
"xref stream",
|
||||||
xref_offset,
|
xref_offset,
|
||||||
"Cross-reference stream claims to contain"
|
("Cross-reference stream claims to contain"
|
||||||
" too many entries: " +
|
" too many entries: " +
|
||||||
QUtil::int_to_string(indx.at(i)) + " " +
|
QUtil::int_to_string(indx.at(i)) + " " +
|
||||||
QUtil::uint_to_string(max_num_entries) + " " +
|
QUtil::uint_to_string(max_num_entries) + " " +
|
||||||
QUtil::uint_to_string(num_entries));
|
QUtil::uint_to_string(num_entries)));
|
||||||
}
|
}
|
||||||
num_entries += toS(indx.at(i));
|
num_entries += toS(indx.at(i));
|
||||||
}
|
}
|
||||||
@ -1187,10 +1191,10 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"xref stream",
|
"xref stream",
|
||||||
xref_offset,
|
xref_offset,
|
||||||
"Cross-reference stream data has the wrong size;"
|
("Cross-reference stream data has the wrong size;"
|
||||||
" expected = " +
|
" expected = " +
|
||||||
QUtil::uint_to_string(expected_size) +
|
QUtil::uint_to_string(expected_size) +
|
||||||
"; actual = " + QUtil::uint_to_string(actual_size));
|
"; actual = " + QUtil::uint_to_string(actual_size)));
|
||||||
if (expected_size > actual_size) {
|
if (expected_size > actual_size) {
|
||||||
throw x;
|
throw x;
|
||||||
} else {
|
} else {
|
||||||
@ -1484,8 +1488,10 @@ QPDF::getAllObjects()
|
|||||||
iter != this->m->obj_cache.end();
|
iter != this->m->obj_cache.end();
|
||||||
++iter) {
|
++iter) {
|
||||||
QPDFObjGen const& og = (*iter).first;
|
QPDFObjGen const& og = (*iter).first;
|
||||||
result.push_back(QPDFObjectHandle::Factory::newIndirect(
|
result.push_back(
|
||||||
this, og.getObj(), og.getGen()));
|
// line-break
|
||||||
|
QPDFObjectHandle::Factory::newIndirect(
|
||||||
|
this, og.getObj(), og.getGen()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1860,8 +1866,8 @@ QPDF::readObjectAtOffset(
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
this->m->last_object_description,
|
this->m->last_object_description,
|
||||||
offset,
|
offset,
|
||||||
std::string("expected ") + QUtil::int_to_string(exp_objid) +
|
(std::string("expected ") + QUtil::int_to_string(exp_objid) +
|
||||||
" " + QUtil::int_to_string(exp_generation) + " obj");
|
" " + QUtil::int_to_string(exp_generation) + " obj"));
|
||||||
if (try_recovery) {
|
if (try_recovery) {
|
||||||
// Will be retried below
|
// Will be retried below
|
||||||
throw e;
|
throw e;
|
||||||
@ -2003,8 +2009,8 @@ QPDF::resolve(int objid, int generation)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"",
|
"",
|
||||||
this->m->file->getLastOffset(),
|
this->m->file->getLastOffset(),
|
||||||
"loop detected resolving object " + QUtil::int_to_string(objid) +
|
("loop detected resolving object " + QUtil::int_to_string(objid) +
|
||||||
" " + QUtil::int_to_string(generation)));
|
" " + QUtil::int_to_string(generation))));
|
||||||
return PointerHolder<QPDFObject>(new QPDF_Null);
|
return PointerHolder<QPDFObject>(new QPDF_Null);
|
||||||
}
|
}
|
||||||
ResolveRecorder rr(this, og);
|
ResolveRecorder rr(this, og);
|
||||||
@ -2040,9 +2046,9 @@ QPDF::resolve(int objid, int generation)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
"object " + QUtil::int_to_string(objid) + "/" +
|
("object " + QUtil::int_to_string(objid) + "/" +
|
||||||
QUtil::int_to_string(generation) +
|
QUtil::int_to_string(generation) +
|
||||||
" has unexpected xref entry type");
|
" has unexpected xref entry type"));
|
||||||
}
|
}
|
||||||
} catch (QPDFExc& e) {
|
} catch (QPDFExc& e) {
|
||||||
warn(e);
|
warn(e);
|
||||||
@ -2052,9 +2058,9 @@ QPDF::resolve(int objid, int generation)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
"object " + QUtil::int_to_string(objid) + "/" +
|
("object " + QUtil::int_to_string(objid) + "/" +
|
||||||
QUtil::int_to_string(generation) +
|
QUtil::int_to_string(generation) +
|
||||||
": error reading object: " + e.what()));
|
": error reading object: " + e.what())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->m->obj_cache.count(og) == 0) {
|
if (this->m->obj_cache.count(og) == 0) {
|
||||||
@ -2069,8 +2075,8 @@ QPDF::resolve(int objid, int generation)
|
|||||||
if (!result->hasDescription()) {
|
if (!result->hasDescription()) {
|
||||||
result->setDescription(
|
result->setDescription(
|
||||||
this,
|
this,
|
||||||
"object " + QUtil::int_to_string(objid) + " " +
|
("object " + QUtil::int_to_string(objid) + " " +
|
||||||
QUtil::int_to_string(generation));
|
QUtil::int_to_string(generation)));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2090,8 +2096,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
this->m->last_object_description,
|
this->m->last_object_description,
|
||||||
this->m->file->getLastOffset(),
|
this->m->file->getLastOffset(),
|
||||||
"supposed object stream " +
|
("supposed object stream " +
|
||||||
QUtil::int_to_string(obj_stream_number) + " is not a stream");
|
QUtil::int_to_string(obj_stream_number) + " is not a stream"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For linearization data in the object, use the data from the
|
// For linearization data in the object, use the data from the
|
||||||
@ -2110,8 +2116,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
this->m->last_object_description,
|
this->m->last_object_description,
|
||||||
this->m->file->getLastOffset(),
|
this->m->file->getLastOffset(),
|
||||||
"supposed object stream " +
|
("supposed object stream " +
|
||||||
QUtil::int_to_string(obj_stream_number) + " has wrong type"));
|
QUtil::int_to_string(obj_stream_number) + " has wrong type")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(dict.getKey("/N").isInteger() && dict.getKey("/First").isInteger())) {
|
if (!(dict.getKey("/N").isInteger() && dict.getKey("/First").isInteger())) {
|
||||||
@ -2120,8 +2126,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
|||||||
this->m->file->getName(),
|
this->m->file->getName(),
|
||||||
this->m->last_object_description,
|
this->m->last_object_description,
|
||||||
this->m->file->getLastOffset(),
|
this->m->file->getLastOffset(),
|
||||||
"object stream " + QUtil::int_to_string(obj_stream_number) +
|
("object stream " + QUtil::int_to_string(obj_stream_number) +
|
||||||
" has incorrect keys");
|
" has incorrect keys"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = dict.getKey("/N").getIntValueAsInt();
|
int n = dict.getKey("/N").getIntValueAsInt();
|
||||||
@ -2130,10 +2136,12 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
|||||||
std::map<int, int> offsets;
|
std::map<int, int> offsets;
|
||||||
|
|
||||||
PointerHolder<Buffer> bp = obj_stream.getStreamData(qpdf_dl_specialized);
|
PointerHolder<Buffer> bp = obj_stream.getStreamData(qpdf_dl_specialized);
|
||||||
auto input = PointerHolder<InputSource>(new BufferInputSource(
|
auto input = PointerHolder<InputSource>(
|
||||||
this->m->file->getName() + " object stream " +
|
// line-break
|
||||||
QUtil::int_to_string(obj_stream_number),
|
new BufferInputSource(
|
||||||
bp.get()));
|
(this->m->file->getName() + " object stream " +
|
||||||
|
QUtil::int_to_string(obj_stream_number)),
|
||||||
|
bp.get()));
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
QPDFTokenizer::Token tnum = readToken(input);
|
QPDFTokenizer::Token tnum = readToken(input);
|
||||||
@ -2428,8 +2436,10 @@ QPDF::replaceForeignIndirectObjects(
|
|||||||
result = QPDFObjectHandle::newArray();
|
result = QPDFObjectHandle::newArray();
|
||||||
int n = foreign.getArrayNItems();
|
int n = foreign.getArrayNItems();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
result.appendItem(replaceForeignIndirectObjects(
|
result.appendItem(
|
||||||
foreign.getArrayItem(i), obj_copier, false));
|
// line-break
|
||||||
|
replaceForeignIndirectObjects(
|
||||||
|
foreign.getArrayItem(i), obj_copier, false));
|
||||||
}
|
}
|
||||||
} else if (foreign.isDictionary()) {
|
} else if (foreign.isDictionary()) {
|
||||||
QTC::TC("qpdf", "QPDF replace dictionary");
|
QTC::TC("qpdf", "QPDF replace dictionary");
|
||||||
@ -2800,22 +2810,26 @@ QPDF::pipeStreamData(
|
|||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
if (!suppress_warnings) {
|
if (!suppress_warnings) {
|
||||||
QTC::TC("qpdf", "QPDF decoding error warning");
|
QTC::TC("qpdf", "QPDF decoding error warning");
|
||||||
qpdf_for_warning.warn(QPDFExc(
|
qpdf_for_warning.warn(
|
||||||
qpdf_e_damaged_pdf,
|
// line-break
|
||||||
file->getName(),
|
QPDFExc(
|
||||||
"",
|
|
||||||
file->getLastOffset(),
|
|
||||||
"error decoding stream data for object " +
|
|
||||||
QUtil::int_to_string(objid) + " " +
|
|
||||||
QUtil::int_to_string(generation) + ": " + e.what()));
|
|
||||||
if (will_retry) {
|
|
||||||
qpdf_for_warning.warn(QPDFExc(
|
|
||||||
qpdf_e_damaged_pdf,
|
qpdf_e_damaged_pdf,
|
||||||
file->getName(),
|
file->getName(),
|
||||||
"",
|
"",
|
||||||
file->getLastOffset(),
|
file->getLastOffset(),
|
||||||
"stream will be re-processed without"
|
("error decoding stream data for object " +
|
||||||
" filtering to avoid data loss"));
|
QUtil::int_to_string(objid) + " " +
|
||||||
|
QUtil::int_to_string(generation) + ": " + e.what())));
|
||||||
|
if (will_retry) {
|
||||||
|
qpdf_for_warning.warn(
|
||||||
|
// line-break
|
||||||
|
QPDFExc(
|
||||||
|
qpdf_e_damaged_pdf,
|
||||||
|
file->getName(),
|
||||||
|
"",
|
||||||
|
file->getLastOffset(),
|
||||||
|
"stream will be re-processed without"
|
||||||
|
" filtering to avoid data loss"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1110,8 +1110,10 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
|
|||||||
} else if (ap.second.isDictionary()) {
|
} else if (ap.second.isDictionary()) {
|
||||||
for (auto& ap2 : ap.second.ditems()) {
|
for (auto& ap2 : ap.second.ditems()) {
|
||||||
if (ap2.second.isStream()) {
|
if (ap2.second.isStream()) {
|
||||||
streams.push_back(replace_stream(
|
streams.push_back(
|
||||||
ap.second, ap2.first, ap2.second));
|
// line-break
|
||||||
|
replace_stream(
|
||||||
|
ap.second, ap2.first, ap2.second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,8 +208,10 @@ QPDFCrypto_openssl::rijndael_init(
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
|
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
|
||||||
check_openssl(EVP_CipherInit_ex(
|
check_openssl(
|
||||||
cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt));
|
// line-break
|
||||||
|
EVP_CipherInit_ex(
|
||||||
|
cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt));
|
||||||
check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0));
|
check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,6 +913,8 @@ QPDFFormFieldObjectHelper::generateTextAppearance(
|
|||||||
opt.at(i) = (*encoder)(opt.at(i), '?');
|
opt.at(i) = (*encoder)(opt.at(i), '?');
|
||||||
}
|
}
|
||||||
|
|
||||||
AS.addTokenFilter(PointerHolder<QPDFObjectHandle::TokenFilter>(
|
AS.addTokenFilter(
|
||||||
new ValueSetter(DA, V, opt, tf, bbox)));
|
// line-break
|
||||||
|
PointerHolder<QPDFObjectHandle::TokenFilter>(
|
||||||
|
new ValueSetter(DA, V, opt, tf, bbox)));
|
||||||
}
|
}
|
||||||
|
@ -2519,10 +2519,12 @@ QPDFJob::handlePageSpecs(
|
|||||||
|
|
||||||
// Read original pages from the PDF, and parse the page range
|
// Read original pages from the PDF, and parse the page range
|
||||||
// associated with this occurrence of the file.
|
// associated with this occurrence of the file.
|
||||||
parsed_specs.push_back(QPDFPageData(
|
parsed_specs.push_back(
|
||||||
page_spec.filename,
|
// line-break
|
||||||
page_spec_qpdfs[page_spec.filename],
|
QPDFPageData(
|
||||||
page_spec.range));
|
page_spec.filename,
|
||||||
|
page_spec_qpdfs[page_spec.filename],
|
||||||
|
page_spec.range));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<unsigned long long, bool> remove_unreferenced;
|
std::map<unsigned long long, bool> remove_unreferenced;
|
||||||
@ -2581,9 +2583,11 @@ QPDFJob::handlePageSpecs(
|
|||||||
for (size_t j = 0; j < m->collate; ++j) {
|
for (size_t j = 0; j < m->collate; ++j) {
|
||||||
if (cur_page + j < page_data.selected_pages.size()) {
|
if (cur_page + j < page_data.selected_pages.size()) {
|
||||||
got_pages = true;
|
got_pages = true;
|
||||||
new_parsed_specs.push_back(QPDFPageData(
|
new_parsed_specs.push_back(
|
||||||
page_data,
|
// line-break
|
||||||
page_data.selected_pages.at(cur_page + j)));
|
QPDFPageData(
|
||||||
|
page_data,
|
||||||
|
page_data.selected_pages.at(cur_page + j)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2684,9 +2688,9 @@ QPDFJob::handlePageSpecs(
|
|||||||
pdf.getFilename(),
|
pdf.getFilename(),
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
"Exception caught while fixing copied"
|
("Exception caught while fixing copied"
|
||||||
" annotations. This may be a qpdf bug. " +
|
" annotations. This may be a qpdf bug. " +
|
||||||
std::string("Exception: ") + e.what()));
|
std::string("Exception: ") + e.what())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3060,8 +3064,9 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w)
|
|||||||
w.forcePDFVersion(version, extension_level);
|
w.forcePDFVersion(version, extension_level);
|
||||||
}
|
}
|
||||||
if (m->progress && m->outfilename) {
|
if (m->progress && m->outfilename) {
|
||||||
w.registerProgressReporter(
|
w.registerProgressReporter(PointerHolder<QPDFWriter::ProgressReporter>(
|
||||||
PointerHolder<QPDFWriter::ProgressReporter>(new ProgressReporter(
|
// line-break
|
||||||
|
new ProgressReporter(
|
||||||
*(this->m->cout),
|
*(this->m->cout),
|
||||||
this->m->message_prefix,
|
this->m->message_prefix,
|
||||||
m->outfilename.get())));
|
m->outfilename.get())));
|
||||||
|
@ -257,8 +257,8 @@ QPDFObjectHandle::setObjectDescriptionFromInput(
|
|||||||
{
|
{
|
||||||
object.setObjectDescription(
|
object.setObjectDescription(
|
||||||
context,
|
context,
|
||||||
input->getName() + ", " + description + " at offset " +
|
(input->getName() + ", " + description + " at offset " +
|
||||||
QUtil::int_to_string(offset));
|
QUtil::int_to_string(offset)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -1018,8 +1018,8 @@ QPDFObjectHandle::getKey(std::string const& key)
|
|||||||
if (this->obj->getDescription(qpdf, description)) {
|
if (this->obj->getDescription(qpdf, description)) {
|
||||||
result.setObjectDescription(
|
result.setObjectDescription(
|
||||||
qpdf,
|
qpdf,
|
||||||
description + " -> null returned from getting key " + key +
|
(description + " -> null returned from getting key " + key +
|
||||||
" from non-Dictionary");
|
" from non-Dictionary"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user