aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-08-22 02:56:14 +0200
committerJay Berkenbilt <ejb@ql.org>2017-08-22 03:05:48 +0200
commit8ab52fa55808541a25dffa15532dd19b2e3084b0 (patch)
treecd1a313efc9b995c2dce3bc0d55448101124bba0 /libqpdf
parent9f60a864a0bade2c1aaab54906c290614609fded (diff)
downloadqpdf-8ab52fa55808541a25dffa15532dd19b2e3084b0.tar.zst
Combine writePCLm with writeStandard
Reduce code duplication
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFWriter.cc125
1 files changed, 47 insertions, 78 deletions
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index a57d71f5..318c2fb7 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -2449,10 +2449,6 @@ QPDFWriter::write()
{
writeLinearized();
}
- else if (this->pclm)
- {
- writePCLm();
- }
else
{
writeStandard();
@@ -3160,18 +3156,8 @@ QPDFWriter::writeLinearized()
}
void
-QPDFWriter::writeStandard()
+QPDFWriter::enqueueObjectsStandard()
{
- if (this->deterministic_id)
- {
- pushMD5Pipeline();
- }
-
- // Start writing
-
- writeHeader();
- writeString(this->extra_header_text);
-
if (this->preserve_unreferenced_objects)
{
QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard");
@@ -3197,61 +3183,11 @@ QPDFWriter::writeStandard()
{
enqueueObject(trailer.getKey(*iter));
}
-
- // Now start walking queue, output each object
- while (this->object_queue.size())
- {
- QPDFObjectHandle cur_object = this->object_queue.front();
- this->object_queue.pop_front();
- writeObject(cur_object);
- }
-
- // Write out the encryption dictionary, if any
- if (this->encrypted)
- {
- writeEncryptionDictionary();
- }
-
- // Now write out xref. next_objid is now the number of objects.
- qpdf_offset_t xref_offset = this->pipeline->getCount();
- if (this->object_stream_to_objects.empty())
- {
- // Write regular cross-reference table
- writeXRefTable(t_normal, 0, this->next_objid - 1, this->next_objid);
- }
- else
- {
- // Write cross-reference stream.
- int xref_id = this->next_objid++;
- writeXRefStream(xref_id, xref_id, xref_offset, t_normal,
- 0, this->next_objid - 1, this->next_objid);
- }
- writeString("startxref\n");
- writeString(QUtil::int_to_string(xref_offset));
- writeString("\n%%EOF\n");
-
- if (this->deterministic_id)
- {
- QTC::TC("qpdf", "QPDFWriter standard deterministic ID",
- this->object_stream_to_objects.empty() ? 0 : 1);
- popPipelineStack();
- assert(this->md5_pipeline == 0);
- }
}
void
-QPDFWriter::writePCLm()
+QPDFWriter::enqueueObjectsPCLm()
{
- if (this->deterministic_id)
- {
- pushMD5Pipeline();
- }
-
- // Start writing
-
- writeHeader();
- writeString(this->extra_header_text);
-
// Image transform stream content for page strip images.
// Each of this new stream has to come after every page image
// strip written in the pclm file.
@@ -3260,7 +3196,7 @@ QPDFWriter::writePCLm()
// enqueue all pages first
std::vector<QPDFObjectHandle> all = this->pdf.getAllPages();
for (std::vector<QPDFObjectHandle>::iterator iter = all.begin();
- iter != all.end(); ++iter)
+ iter != all.end(); ++iter)
{
// enqueue page
enqueueObject(*iter);
@@ -3273,7 +3209,7 @@ QPDFWriter::writePCLm()
(*iter).getKey("/Resources").getKey("/XObject");
std::set<std::string> keys = strips.getKeys();
for (std::set<std::string>::iterator image = keys.begin();
- image != keys.end(); ++image)
+ image != keys.end(); ++image)
{
enqueueObject(strips.getKey(*image));
enqueueObject(QPDFObjectHandle::newStream(
@@ -3284,28 +3220,59 @@ QPDFWriter::writePCLm()
// Put root in queue.
QPDFObjectHandle trailer = getTrimmedTrailer();
enqueueObject(trailer.getKey("/Root"));
+}
+
+void
+QPDFWriter::writeStandard()
+{
+ if (this->deterministic_id)
+ {
+ pushMD5Pipeline();
+ }
+
+ // Start writing
+
+ writeHeader();
+ writeString(this->extra_header_text);
- // Now start walking queue, output each object
+ if (this->pclm)
+ {
+ enqueueObjectsPCLm();
+ }
+ else
+ {
+ enqueueObjectsStandard();
+ }
+
+ // Now start walking queue, outputing each object. There shouldn't
+ // really be any here, but this will catch anything that somehow
+ // got missed.
while (this->object_queue.size())
{
- QPDFObjectHandle cur_object = this->object_queue.front();
- this->object_queue.pop_front();
- writeObject(cur_object);
+ QPDFObjectHandle cur_object = this->object_queue.front();
+ this->object_queue.pop_front();
+ writeObject(cur_object);
+ }
+
+ // Write out the encryption dictionary, if any
+ if (this->encrypted)
+ {
+ writeEncryptionDictionary();
}
// Now write out xref. next_objid is now the number of objects.
qpdf_offset_t xref_offset = this->pipeline->getCount();
if (this->object_stream_to_objects.empty())
{
- // Write regular cross-reference table
- writeXRefTable(t_normal, 0, this->next_objid - 1, this->next_objid);
+ // Write regular cross-reference table
+ writeXRefTable(t_normal, 0, this->next_objid - 1, this->next_objid);
}
else
{
- // Write cross-reference stream.
- int xref_id = this->next_objid++;
- writeXRefStream(xref_id, xref_id, xref_offset, t_normal,
- 0, this->next_objid - 1, this->next_objid);
+ // Write cross-reference stream.
+ int xref_id = this->next_objid++;
+ writeXRefStream(xref_id, xref_id, xref_offset, t_normal,
+ 0, this->next_objid - 1, this->next_objid);
}
writeString("startxref\n");
writeString(QUtil::int_to_string(xref_offset));
@@ -3313,6 +3280,8 @@ QPDFWriter::writePCLm()
if (this->deterministic_id)
{
+ QTC::TC("qpdf", "QPDFWriter standard deterministic ID",
+ this->object_stream_to_objects.empty() ? 0 : 1);
popPipelineStack();
assert(this->md5_pipeline == 0);
}