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

void PoDoFo::PdfPagesTree::InsertPageIntoNode ( PdfObject pNode,
const PdfObjectList &  rlstParents,
int  nIndex,
PdfObject pPage 
) [private]

Insert a page object into a pages node

Parameters:
pNodethe pages node whete pPage is to be inserted
rlstParentslist of all (future) parent pages nodes in the pages tree of pPage
nIndexindex where pPage is to be inserted in pNode's kids array
pPagethe page object which is to be inserted

Definition at line 430 of file PdfPagesTree.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfArray::begin(), ChangePagesCount(), PoDoFo::PdfArray::end(), PoDoFo::ePdfError_InvalidHandle, PoDoFo::PdfVariant::GetArray(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfArray::GetSize(), PODOFO_RAISE_ERROR, PoDoFo::PdfArray::push_back(), and PoDoFo::PdfObject::Reference().

Referenced by InsertPage().

{
    if( !pParent || !pPage ) 
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    // 1. Add the reference of the new page to the kids array of pParent
    // 2. Increase count of every node in lstParents (which also includes pParent)
    // 3. Add Parent key to the page

    // 1. Add reference
    const PdfArray oldKids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray();
    PdfArray::const_iterator it = oldKids.begin();
    PdfArray newKids;

    newKids.reserve( oldKids.GetSize() + 1 );

    if( nIndex < 0 ) 
    {
        newKids.push_back( pPage->Reference() );
    }

    int i = 0;
    while( it != oldKids.end() ) 
    {
        newKids.push_back( *it );

        if( i == nIndex ) 
            newKids.push_back( pPage->Reference() );

        ++i;
        ++it;
    }

    /*
    PdfVariant var2( newKids );
    std::string str2;
    var2.ToString(str2);
    printf("newKids= %s\n", str2.c_str() );
    */

    pParent->GetDictionary().AddKey( PdfName("Kids"), newKids );
 
    // 2. increase count
    PdfObjectList::const_reverse_iterator itParents = rlstParents.rbegin();
    while( itParents != rlstParents.rend() )
    {
        this->ChangePagesCount( *itParents, 1 );

        ++itParents;
    } 

    // 3. add parent key to the page
    pPage->GetDictionary().AddKey( PdfName("Parent"), pParent->Reference() );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index