Hi guys.

I've noticed that array form of "DecodeParms" entry in a stream
dictionary cannot be processed even in the latest revision of PoDoFo.
There is a patch attached to improve PdfFilterFactory::CreateDecodeStream
a bit and assign selected dictionary from the array to a given filter
according its order.

Regards,
Dmitry
Index: podofo/trunk/src/base/PdfFilter.cpp
===================================================================
--- podofo/trunk/src/base/PdfFilter.cpp (revision 1933)
+++ podofo/trunk/src/base/PdfFilter.cpp (working copy)
@@ -338,25 +338,53 @@
 }
 
 PdfOutputStream* PdfFilterFactory::CreateDecodeStream( const TVecFilters & 
filters, PdfOutputStream* pStream,
-                                                       const PdfDictionary* 
pDictionary ) 
+                                                       const PdfDictionary* 
pDictionary )
 {
+    PdfFilteredDecodeStream* pFilter;
+    const PdfDictionary *pdict;
     TVecFilters::const_reverse_iterator it = filters.rbegin();
+    const PdfArray *parms_arr;
+    PdfArray::const_reverse_iterator parms_it;
 
     PODOFO_RAISE_LOGIC_IF( !filters.size(), "Cannot create an DecodeStream 
from an empty list of filters" );
 
-    // TODO: support arrays and indirect objects here and the short name /DP
-    if( pDictionary && pDictionary->HasKey( "DecodeParms" ) && 
pDictionary->GetKey( "DecodeParms" )->IsDictionary() )
-        pDictionary = &(pDictionary->GetKey( "DecodeParms" )->GetDictionary());
+    pdict = pDictionary;
 
-    PdfFilteredDecodeStream* pFilter = new PdfFilteredDecodeStream( pStream, 
*it, false, pDictionary );
-    ++it;
+    // TODO: support indirect objects here and the short form /DP instead of 
/DecodeParms
+    parms_arr = NULL;
+    if ( pdict && pdict->HasKey("DecodeParms") && 
pdict->GetKey("DecodeParms")->IsDictionary() ) {
+        pdict = &(pdict->GetKey("DecodeParms")->GetDictionary());
+    } else if ( pdict && pdict->HasKey("DecodeParms") && 
pdict->GetKey("DecodeParms")->IsArray() ) {
+        parms_arr = &(pdict->GetKey("DecodeParms")->GetArray());
+        parms_it = parms_arr->rbegin();
+    } else {
+        /* Keep pdict as is */;
+    }
 
-    while( it != filters.rend() ) 
-    {
-        pFilter = new PdfFilteredDecodeStream( pFilter, *it, true, pDictionary 
);
+    if ( parms_arr != NULL ) {
+        if (parms_it->IsDictionary()) {
+            pFilter = new PdfFilteredDecodeStream(
+                    pStream, *it, false, &(parms_it->GetDictionary()));
+        } else {
+            pFilter = new PdfFilteredDecodeStream(pStream, *it, false, pdict);
+        }
         ++it;
+        ++parms_it;
+    } else {
+        pFilter = new PdfFilteredDecodeStream(pStream, *it, false, pdict);
+        ++it;
     }
 
+    while ( it != filters.rend() ) {
+        if ( (parms_arr != NULL) && (parms_it != parms_arr->rend()) && 
parms_it->IsDictionary() ) {
+            pFilter = new PdfFilteredDecodeStream(
+                    pFilter, *it, true, &(parms_it->GetDictionary()));
+        } else {
+            pFilter = new PdfFilteredDecodeStream(pFilter, *it, true, pdict);
+        }
+        ++it;
+        ++parms_it;
+    }
     return pFilter;
 }
 
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to