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

void PoDoFo::PdfWriter::ReorderObjectsLinearized ( PdfObject pLinearize,
NonPublic::PdfHintStream pHint,
PdfPage pPage,
PdfObject **  ppLast 
) [private]

Reorder and renumber all object as required for linearized PDF files. This function is very slow.

pLinearizelinearization dictionary
pHintprimary hint stream dictionary
pPagefirst page to display in the document
ppLastthe pointer will be initialized to the last object belonging to the first page

Definition at line 360 of file PdfWriter.cpp.

References PoDoFo::PdfVecObjects::begin(), PoDoFo::PdfVecObjects::end(), FindCatalogDependencies(), PoDoFo::PdfVecObjects::GetBack(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfVecObjects::GetIndex(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfVecObjects::GetObject(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfVecObjects::GetObjectDependencies(), PoDoFo::PdfVariant::GetReference(), PoDoFo::PdfVecObjects::GetSize(), m_vecObjects, PoDoFo::PdfVecObjects::push_back(), PoDoFo::PdfObject::Reference(), PoDoFo::PdfVecObjects::RemoveObject(), and PoDoFo::PdfVecObjects::RenumberObjects().

    TPdfReferenceList   lstLinearizedGroup;
    TPdfReferenceSet    setLinearizedGroup;
    TCIPdfReferenceList it;
    TIVecObjects        itObjects;
    PdfObject*          pRoot;
    PdfObject*          pTmp = NULL;
    size_t        index, i;

    // get the dependend objects that are required to display
    // the first page. I.e. get all objects that have to be written
    // at the start of the file.
    // Add all depencies to lstLinearizedGroup
    m_vecObjects->GetObjectDependencies( pPage->GetObject(), &lstLinearizedGroup );

    // get the root dictionary, it has to be written at the top of the file too.
    pRoot = m_vecObjects->GetObject( m_pTrailer->GetDictionary().GetKey( "Root" )->GetReference() );
    // add the root dictionary
    lstLinearizedGroup.push_back( pRoot->Reference() );
    // add the first page itself
    lstLinearizedGroup.push_back( pPage->GetObject()->Reference() );

    // add several dependencies of the root dictionary
    this->FindCatalogDependencies( pRoot, "ViewerPreferences", &lstLinearizedGroup, true );
    this->FindCatalogDependencies( pRoot, "PageMode", &lstLinearizedGroup, true );
    this->FindCatalogDependencies( pRoot, "Threads", &lstLinearizedGroup, false );
    this->FindCatalogDependencies( pRoot, "OpenAction", &lstLinearizedGroup, true );
    this->FindCatalogDependencies( pRoot, "AcroForm", &lstLinearizedGroup, false );
    this->FindCatalogDependencies( pRoot, "Encrypt", &lstLinearizedGroup, true );

    // add the hint stream
    lstLinearizedGroup.push_back( pHint->GetObject()->Reference() );
    // add the linearization dictionary
    lstLinearizedGroup.push_back( pLinearize->Reference() );

    // move all objects which are required to display the first page
    // at the front of the vector of objects.
    // We only swap objects inside of the vector to avoid reallocations.
    // This is a fast operation therefore
    i  = m_vecObjects->GetSize()-1;
    it = lstLinearizedGroup.begin();

    while( it != lstLinearizedGroup.end() )
        index = m_vecObjects->GetIndex( *it );

        if( index < i ) 
            pTmp                   = (*m_vecObjects)[index];
            (*m_vecObjects)[index] = (*m_vecObjects)[i];
            (*m_vecObjects)[i]     = pTmp;


    // Renumber all objects according to their position in the vector.
    // This is the slowest (only slow) operation when creating a 
    // linearized PDF file. Garbage collection goes along with this step.
    std::copy( lstLinearizedGroup.begin(), lstLinearizedGroup.end(), std::inserter(setLinearizedGroup, setLinearizedGroup.begin()) );
    m_vecObjects->RenumberObjects( m_pTrailer, &setLinearizedGroup );

    // reorder the objects in the file
    itObjects = m_vecObjects->begin();
    itObjects += m_vecObjects->GetSize() - setLinearizedGroup.size();
    m_vecObjects->RemoveObject( itObjects );

    while( itObjects != m_vecObjects->end() )
        m_vecLinearized.push_back( *itObjects );
        // reset the owner
        (*itObjects)->SetOwner( m_vecObjects );
        m_vecObjects->RemoveObject( itObjects ); 
    *ppLast = m_vecLinearized.GetBack();

Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index