aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFWriter.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-01-31 22:45:52 +0100
committerJay Berkenbilt <ejb@ql.org>2018-02-19 02:18:40 +0100
commitebd5ed63decb90e26ae9129164214f9d7d684621 (patch)
treea4d8960a1c9f270315f9c9c3fff884b0198d9087 /libqpdf/QPDFWriter.cc
parenta0fd8875aabb244d35e2ddf785f546c336ed9622 (diff)
downloadqpdf-ebd5ed63decb90e26ae9129164214f9d7d684621.tar.zst
Add option to save pass 1 of lineariziation
This is useful only for debugging the linearization code.
Diffstat (limited to 'libqpdf/QPDFWriter.cc')
-rw-r--r--libqpdf/QPDFWriter.cc35
1 files changed, 34 insertions, 1 deletions
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index 05446400..f7f834b5 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -357,6 +357,12 @@ QPDFWriter::setLinearization(bool val)
}
void
+QPDFWriter::setLinearizationPass1Filename(std::string const& filename)
+{
+ this->m->lin_pass1_filename = filename;
+}
+
+void
QPDFWriter::setPCLm(bool val)
{
this->m->pclm = val;
@@ -2957,11 +2963,24 @@ QPDFWriter::writeLinearized()
// Write file in two passes. Part numbers refer to PDF spec 1.4.
+ FILE* lin_pass1_file = 0;
for (int pass = 1; pass <= 2; ++pass)
{
if (pass == 1)
{
- pushDiscardFilter();
+ if (! this->m->lin_pass1_filename.empty())
+ {
+ lin_pass1_file =
+ QUtil::safe_fopen(
+ this->m->lin_pass1_filename.c_str(), "wb");
+ pushPipeline(
+ new Pl_StdioFile("linearization pass1", lin_pass1_file));
+ activatePipelineStack();
+ }
+ else
+ {
+ pushDiscardFilter();
+ }
if (this->m->deterministic_id)
{
pushMD5Pipeline();
@@ -3201,6 +3220,20 @@ QPDFWriter::writeLinearized()
// Restore hint offset
this->m->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
+ if (lin_pass1_file)
+ {
+ // Write some debugging information
+ fprintf(lin_pass1_file, "%% hint_offset=%s\n",
+ QUtil::int_to_string(hint_offset).c_str());
+ fprintf(lin_pass1_file, "%% hint_length=%s\n",
+ QUtil::int_to_string(hint_length).c_str());
+ fprintf(lin_pass1_file, "%% second_xref_offset=%s\n",
+ QUtil::int_to_string(second_xref_offset).c_str());
+ fprintf(lin_pass1_file, "%% second_xref_end=%s\n",
+ QUtil::int_to_string(second_xref_end).c_str());
+ fclose(lin_pass1_file);
+ lin_pass1_file = 0;
+ }
}
}
}