On Mon, Sep 6, 2010 at 23:34 +0200, Julien Cristau wrote:
> On Mon, Sep 6, 2010 at 17:56:19 +0200, Johann Felix Soden wrote:
>
> > .../{support_uncompression => support_compression} | 69
> > +--
>
> Care to provide a diff between the old and new patches? (I'm lazy, and
> debdiff doesn't know to do that.)
>
No problem, the diff between support_uncompression and
support_compression is attached.
Regards,
Johann Felix Soden
diff -u b/pdftk/pdftk.cc b/pdftk/pdftk.cc
--- b/pdftk/pdftk.cc
+++ b/pdftk/pdftk.cc
@@ -159,8 +159,22 @@
}
}
-void uncompress_stream(itext::PRStream* stream)
+void change_compression_stream(itext::PRStream* stream, bool compress_mode )
{
+ if( compress_mode )
+ {
+
+ try {
+ stream->setData( itext::PdfReader::getStreamBytes( stream ), compress_mode );
+ }
+ catch (itext::exceptions::UnsupportedPdfException * err ) { // unknow filter detected
+ // ignore this
+ }
+ return;
+ }
+
+ // - uncompress -
+
try { // try first itext own way
stream->setData( itext::PdfReader::getStreamBytes( stream ) );
stream->remove( itext::PdfName::FILTER );
@@ -242,16 +256,16 @@
}
-void uncompress_dictionary( itext::PdfDictionary *dict, itext::PdfReader *reader )
+void change_compression_dictionary( itext::PdfDictionary *dict, itext::PdfReader *reader, bool compress_mode )
{
if( !dict )
return;
// prevent circuit references
- static set already_uncompressed;
- if( already_uncompressed.find(dict) != already_uncompressed.end() )
+ static set already_handled;
+ if( already_handled.find(dict) != already_handled.end() )
return;
- already_uncompressed.insert(dict);
+ already_handled.insert(dict);
java::util::Iterator * keys=dict->getKeys()->iterator();
while( keys->hasNext() ) {
@@ -265,18 +279,19 @@
if( !obj || obj == dict )
continue;
if( obj->isDictionary() )
- uncompress_dictionary( (itext::PdfDictionary*)obj,reader );
+ change_compression_dictionary( (itext::PdfDictionary*)obj, reader, compress_mode );
if( obj->isStream() )
- uncompress_stream( (itext::PRStream*) obj );
+ change_compression_stream( (itext::PRStream*) obj, compress_mode );
}
}
-void uncompress( itext::PdfReader * reader )
+void change_compression( itext::PdfReader * reader, bool compress_mode )
{
int pages = reader->getNumberOfPages();
+ itext::Document::Document::compress = compress_mode;
itext::PdfDictionary *catalog = reader->getCatalog();
- uncompress_dictionary( catalog, reader );
+ change_compression_dictionary( catalog, reader, compress_mode );
for( int i=1; igetXrefSize(); i++ )
{
@@ -284,14 +299,14 @@
if(!obj)
continue;
if( obj->isDictionary() )
- uncompress_dictionary( (itext::PdfDictionary*)obj, reader );
+ change_compression_dictionary( (itext::PdfDictionary*)obj, reader, compress_mode );
if( obj->isStream() )
- uncompress_stream( (itext::PRStream*)obj );
+ change_compression_stream( (itext::PRStream*)obj, compress_mode );
}
for( int i = 1; i <= pages; i++ )
{
- reader->setPageContent( i, reader->getPageContent( i ), 0 );
+ reader->setPageContent( i, reader->getPageContent( i ));
}
}
@@ -651,6 +666,7 @@
return filt_uncompress_k;
}
else if( strcmp( ss_copy, "compress" )== 0 ) {
+ itext::Document::Document::compress=true;
return filt_compress_k;
}
else if( strcmp( ss_copy, "flatten" )== 0 ) {
@@ -2280,11 +2296,12 @@
//
if( m_output_uncompress_b ) {
- uncompress(input_reader_p);
+ change_compression(input_reader_p, false );
add_mark_to_page( input_reader_p, it->m_page_num, output_page_count+ 1 );
writer_p->setCompressionLevel(0);
}
else if( m_output_compress_b ) {
+ change_compression(input_reader_p, true );
remove_mark_from_page( input_reader_p, it->m_page_num );
writer_p->setCompressionLevel(9);
}
@@ -2358,13 +2375,14 @@
// un/compress output streams?
if( m_output_uncompress_b ) {
+ change_compression( input_reader_p, false );
// Absent from itext-2.1.4
// writer_p->filterStreams= true;
// writer_p->compressStreams= false;
writer_p->setCompressionLevel(0);
- uncompress(input_reader_p);
}
else if( m_output_compress_b ) {
+ change_compression( input_reader_p, true );
// Absent from itext-2.1.4
// writer_p->filterStreams= false;
// writer_p->compressStreams= true;
@@ -2600,7 +2618,7 @@
// un/compress output streams?
if( m_output_uncompress_b ) {
- uncompress(input_reader_p);
+ change_compression( input_reader_p, false );
add_marks_to_pages( input_reader_p );
// Absent from itext-2.1.4
// writer_p->filterStreams= true;
@@ -2608,6 +2626,7 @@
writer_p->setCompressionLevel(0);
}
else if( m_output_compress_b ) {
+ change_compression( input_reader_p, true );
remove_marks_from_pages( input_reader_p );
// Abse