Commit 8ab52fa55808541a25dffa15532dd19b2e3084b0
1 parent
9f60a864
Combine writePCLm with writeStandard
Reduce code duplication
Showing
2 changed files
with
49 additions
and
79 deletions
include/qpdf/QPDFWriter.hh
| ... | ... | @@ -425,9 +425,10 @@ class QPDFWriter |
| 425 | 425 | void closeObject(int objid); |
| 426 | 426 | QPDFObjectHandle getTrimmedTrailer(); |
| 427 | 427 | void prepareFileForWrite(); |
| 428 | + void enqueueObjectsStandard(); | |
| 429 | + void enqueueObjectsPCLm(); | |
| 428 | 430 | void writeStandard(); |
| 429 | 431 | void writeLinearized(); |
| 430 | - void writePCLm(); | |
| 431 | 432 | void enqueuePart(std::vector<QPDFObjectHandle>& part); |
| 432 | 433 | void writeEncryptionDictionary(); |
| 433 | 434 | void writeHeader(); | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -2449,10 +2449,6 @@ QPDFWriter::write() |
| 2449 | 2449 | { |
| 2450 | 2450 | writeLinearized(); |
| 2451 | 2451 | } |
| 2452 | - else if (this->pclm) | |
| 2453 | - { | |
| 2454 | - writePCLm(); | |
| 2455 | - } | |
| 2456 | 2452 | else |
| 2457 | 2453 | { |
| 2458 | 2454 | writeStandard(); |
| ... | ... | @@ -3160,18 +3156,8 @@ QPDFWriter::writeLinearized() |
| 3160 | 3156 | } |
| 3161 | 3157 | |
| 3162 | 3158 | void |
| 3163 | -QPDFWriter::writeStandard() | |
| 3159 | +QPDFWriter::enqueueObjectsStandard() | |
| 3164 | 3160 | { |
| 3165 | - if (this->deterministic_id) | |
| 3166 | - { | |
| 3167 | - pushMD5Pipeline(); | |
| 3168 | - } | |
| 3169 | - | |
| 3170 | - // Start writing | |
| 3171 | - | |
| 3172 | - writeHeader(); | |
| 3173 | - writeString(this->extra_header_text); | |
| 3174 | - | |
| 3175 | 3161 | if (this->preserve_unreferenced_objects) |
| 3176 | 3162 | { |
| 3177 | 3163 | QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard"); |
| ... | ... | @@ -3197,61 +3183,11 @@ QPDFWriter::writeStandard() |
| 3197 | 3183 | { |
| 3198 | 3184 | enqueueObject(trailer.getKey(*iter)); |
| 3199 | 3185 | } |
| 3200 | - | |
| 3201 | - // Now start walking queue, output each object | |
| 3202 | - while (this->object_queue.size()) | |
| 3203 | - { | |
| 3204 | - QPDFObjectHandle cur_object = this->object_queue.front(); | |
| 3205 | - this->object_queue.pop_front(); | |
| 3206 | - writeObject(cur_object); | |
| 3207 | - } | |
| 3208 | - | |
| 3209 | - // Write out the encryption dictionary, if any | |
| 3210 | - if (this->encrypted) | |
| 3211 | - { | |
| 3212 | - writeEncryptionDictionary(); | |
| 3213 | - } | |
| 3214 | - | |
| 3215 | - // Now write out xref. next_objid is now the number of objects. | |
| 3216 | - qpdf_offset_t xref_offset = this->pipeline->getCount(); | |
| 3217 | - if (this->object_stream_to_objects.empty()) | |
| 3218 | - { | |
| 3219 | - // Write regular cross-reference table | |
| 3220 | - writeXRefTable(t_normal, 0, this->next_objid - 1, this->next_objid); | |
| 3221 | - } | |
| 3222 | - else | |
| 3223 | - { | |
| 3224 | - // Write cross-reference stream. | |
| 3225 | - int xref_id = this->next_objid++; | |
| 3226 | - writeXRefStream(xref_id, xref_id, xref_offset, t_normal, | |
| 3227 | - 0, this->next_objid - 1, this->next_objid); | |
| 3228 | - } | |
| 3229 | - writeString("startxref\n"); | |
| 3230 | - writeString(QUtil::int_to_string(xref_offset)); | |
| 3231 | - writeString("\n%%EOF\n"); | |
| 3232 | - | |
| 3233 | - if (this->deterministic_id) | |
| 3234 | - { | |
| 3235 | - QTC::TC("qpdf", "QPDFWriter standard deterministic ID", | |
| 3236 | - this->object_stream_to_objects.empty() ? 0 : 1); | |
| 3237 | - popPipelineStack(); | |
| 3238 | - assert(this->md5_pipeline == 0); | |
| 3239 | - } | |
| 3240 | 3186 | } |
| 3241 | 3187 | |
| 3242 | 3188 | void |
| 3243 | -QPDFWriter::writePCLm() | |
| 3189 | +QPDFWriter::enqueueObjectsPCLm() | |
| 3244 | 3190 | { |
| 3245 | - if (this->deterministic_id) | |
| 3246 | - { | |
| 3247 | - pushMD5Pipeline(); | |
| 3248 | - } | |
| 3249 | - | |
| 3250 | - // Start writing | |
| 3251 | - | |
| 3252 | - writeHeader(); | |
| 3253 | - writeString(this->extra_header_text); | |
| 3254 | - | |
| 3255 | 3191 | // Image transform stream content for page strip images. |
| 3256 | 3192 | // Each of this new stream has to come after every page image |
| 3257 | 3193 | // strip written in the pclm file. |
| ... | ... | @@ -3260,7 +3196,7 @@ QPDFWriter::writePCLm() |
| 3260 | 3196 | // enqueue all pages first |
| 3261 | 3197 | std::vector<QPDFObjectHandle> all = this->pdf.getAllPages(); |
| 3262 | 3198 | for (std::vector<QPDFObjectHandle>::iterator iter = all.begin(); |
| 3263 | - iter != all.end(); ++iter) | |
| 3199 | + iter != all.end(); ++iter) | |
| 3264 | 3200 | { |
| 3265 | 3201 | // enqueue page |
| 3266 | 3202 | enqueueObject(*iter); |
| ... | ... | @@ -3273,7 +3209,7 @@ QPDFWriter::writePCLm() |
| 3273 | 3209 | (*iter).getKey("/Resources").getKey("/XObject"); |
| 3274 | 3210 | std::set<std::string> keys = strips.getKeys(); |
| 3275 | 3211 | for (std::set<std::string>::iterator image = keys.begin(); |
| 3276 | - image != keys.end(); ++image) | |
| 3212 | + image != keys.end(); ++image) | |
| 3277 | 3213 | { |
| 3278 | 3214 | enqueueObject(strips.getKey(*image)); |
| 3279 | 3215 | enqueueObject(QPDFObjectHandle::newStream( |
| ... | ... | @@ -3284,28 +3220,59 @@ QPDFWriter::writePCLm() |
| 3284 | 3220 | // Put root in queue. |
| 3285 | 3221 | QPDFObjectHandle trailer = getTrimmedTrailer(); |
| 3286 | 3222 | enqueueObject(trailer.getKey("/Root")); |
| 3223 | +} | |
| 3224 | + | |
| 3225 | +void | |
| 3226 | +QPDFWriter::writeStandard() | |
| 3227 | +{ | |
| 3228 | + if (this->deterministic_id) | |
| 3229 | + { | |
| 3230 | + pushMD5Pipeline(); | |
| 3231 | + } | |
| 3232 | + | |
| 3233 | + // Start writing | |
| 3234 | + | |
| 3235 | + writeHeader(); | |
| 3236 | + writeString(this->extra_header_text); | |
| 3287 | 3237 | |
| 3288 | - // Now start walking queue, output each object | |
| 3238 | + if (this->pclm) | |
| 3239 | + { | |
| 3240 | + enqueueObjectsPCLm(); | |
| 3241 | + } | |
| 3242 | + else | |
| 3243 | + { | |
| 3244 | + enqueueObjectsStandard(); | |
| 3245 | + } | |
| 3246 | + | |
| 3247 | + // Now start walking queue, outputing each object. There shouldn't | |
| 3248 | + // really be any here, but this will catch anything that somehow | |
| 3249 | + // got missed. | |
| 3289 | 3250 | while (this->object_queue.size()) |
| 3290 | 3251 | { |
| 3291 | - QPDFObjectHandle cur_object = this->object_queue.front(); | |
| 3292 | - this->object_queue.pop_front(); | |
| 3293 | - writeObject(cur_object); | |
| 3252 | + QPDFObjectHandle cur_object = this->object_queue.front(); | |
| 3253 | + this->object_queue.pop_front(); | |
| 3254 | + writeObject(cur_object); | |
| 3255 | + } | |
| 3256 | + | |
| 3257 | + // Write out the encryption dictionary, if any | |
| 3258 | + if (this->encrypted) | |
| 3259 | + { | |
| 3260 | + writeEncryptionDictionary(); | |
| 3294 | 3261 | } |
| 3295 | 3262 | |
| 3296 | 3263 | // Now write out xref. next_objid is now the number of objects. |
| 3297 | 3264 | qpdf_offset_t xref_offset = this->pipeline->getCount(); |
| 3298 | 3265 | if (this->object_stream_to_objects.empty()) |
| 3299 | 3266 | { |
| 3300 | - // Write regular cross-reference table | |
| 3301 | - writeXRefTable(t_normal, 0, this->next_objid - 1, this->next_objid); | |
| 3267 | + // Write regular cross-reference table | |
| 3268 | + writeXRefTable(t_normal, 0, this->next_objid - 1, this->next_objid); | |
| 3302 | 3269 | } |
| 3303 | 3270 | else |
| 3304 | 3271 | { |
| 3305 | - // Write cross-reference stream. | |
| 3306 | - int xref_id = this->next_objid++; | |
| 3307 | - writeXRefStream(xref_id, xref_id, xref_offset, t_normal, | |
| 3308 | - 0, this->next_objid - 1, this->next_objid); | |
| 3272 | + // Write cross-reference stream. | |
| 3273 | + int xref_id = this->next_objid++; | |
| 3274 | + writeXRefStream(xref_id, xref_id, xref_offset, t_normal, | |
| 3275 | + 0, this->next_objid - 1, this->next_objid); | |
| 3309 | 3276 | } |
| 3310 | 3277 | writeString("startxref\n"); |
| 3311 | 3278 | writeString(QUtil::int_to_string(xref_offset)); |
| ... | ... | @@ -3313,6 +3280,8 @@ QPDFWriter::writePCLm() |
| 3313 | 3280 | |
| 3314 | 3281 | if (this->deterministic_id) |
| 3315 | 3282 | { |
| 3283 | + QTC::TC("qpdf", "QPDFWriter standard deterministic ID", | |
| 3284 | + this->object_stream_to_objects.empty() ? 0 : 1); | |
| 3316 | 3285 | popPipelineStack(); |
| 3317 | 3286 | assert(this->md5_pipeline == 0); |
| 3318 | 3287 | } | ... | ... |