Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

void PoDoFo::PdfMemStream::FlateCompress (  )

This function compresses any currently set stream using the FlateDecode(ZIP) algorithm. JPEG compressed streams will not be compressed again using this function. Entries to the filter dictionary will be added if necessary.

Definition at line 124 of file PdfMemStream.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfArray::begin(), PoDoFo::PdfArray::end(), FlateCompressStreamData(), PoDoFo::PdfVariant::GetArray(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfObject::GetIndirectKey(), PoDoFo::PdfVariant::GetName(), PoDoFo::PdfDictionary::HasKey(), PoDoFo::PdfVariant::IsArray(), PoDoFo::PdfVariant::IsName(), and PoDoFo::PdfArray::push_back().

{
    PdfObject*        pObj;
    PdfVariant        vFilter( PdfName("FlateDecode" ) );
    PdfVariant        vFilterList;
    PdfArray          tFilters;

    PdfArray::const_iterator tciFilters;
    
    if( !m_lLength )
        return; // ePdfError_ErrOk

    // TODO: Handle DecodeParms
    if( m_pParent->GetDictionary().HasKey( "Filter" ) )
    {
        pObj = m_pParent->GetIndirectKey( "Filter" );

        if( pObj->IsName() )
        {
            if( pObj->GetName() != "DCTDecode" && pObj->GetName() != "FlateDecode" )
            {
                tFilters.push_back( vFilter );
                tFilters.push_back( *pObj );
            }
        }
        else if( pObj->IsArray() )
        {
            tciFilters = pObj->GetArray().begin();

            while( tciFilters != pObj->GetArray().end() )
            {
                if( (*tciFilters).IsName() )
                {
                    // do not compress DCTDecoded are already FlateDecoded streams again
                    if( (*tciFilters).GetName() == "DCTDecode" || (*tciFilters).GetName() == "FlateDecode" )
                    {
                        return;
                    }
                }

                ++tciFilters;
            }

            tFilters.push_back( vFilter );

            tciFilters = pObj->GetArray().begin();

            while( tciFilters != pObj->GetArray().end() )
            {
                tFilters.push_back( (*tciFilters) );
                
                ++tciFilters;
            }
        }
        else
            return;

        vFilterList = PdfVariant( tFilters );
        m_pParent->GetDictionary().AddKey( "Filter", vFilterList );

        FlateCompressStreamData(); // throws an exception on error
    }
    else
    {
        m_pParent->GetDictionary().AddKey( "Filter", PdfName( "FlateDecode" ) );
        FlateCompressStreamData();
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index