Esempio n. 1
0
PdfAnnotation* PdfPage::GetAnnotation( int index )
{
    PdfAnnotation* pAnnot;
    PdfReference   ref;

    PdfObject*     pObj   = this->GetAnnotationsArray( false );

    if( !(pObj && pObj->IsArray()) )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
    }
    
    if( index < 0 && static_cast<unsigned int>(index) >= pObj->GetArray().size() )
    {
        PODOFO_RAISE_ERROR( ePdfError_ValueOutOfRange );
    }

    ref    = pObj->GetArray()[index].GetReference();
    pAnnot = m_mapAnnotations[ref];
    if( !pAnnot )
    {
        pObj = m_pObject->GetOwner()->GetObject( ref );
        if( !pObj )
        {
            PdfError::DebugMessage( "Error looking up object %i %i R\n", ref.ObjectNumber(), ref.GenerationNumber() );
            PODOFO_RAISE_ERROR( ePdfError_NoObject );
        }
     
        pAnnot = new PdfAnnotation( pObj, this );
        m_mapAnnotations[ref] = pAnnot;
    }

    return pAnnot;
}
Esempio n. 2
0
void PdfXRef::AddObject( const PdfReference & rRef, pdf_uint64 offset, bool bUsed )
{
    TIVecXRefBlock     it = m_vecBlocks.begin();
    PdfXRef::TXRefItem item( rRef, offset );
    bool               bInsertDone = false;

    while( it != m_vecBlocks.end() )
    {
        if( (*it).InsertItem( item, bUsed ) )
        {
            bInsertDone = true;
            break;
        }

        ++it;
    }

    if( !bInsertDone ) 
    {
        PdfXRefBlock block;
        block.m_nFirst = rRef.ObjectNumber();
        block.m_nCount = 1;
        if( bUsed )
            block.items.push_back( item );
        else
            block.freeItems.push_back( rRef );

        m_vecBlocks.push_back( block );
        std::sort( m_vecBlocks.begin(), m_vecBlocks.end() );
    }
}
void PdfVecObjects::AddFreeObject( const PdfReference & rReference )
{
    std::pair<TIPdfReferenceList,TIPdfReferenceList> it = 
        std::equal_range( m_lstFreeObjects.begin(), m_lstFreeObjects.end(), rReference, ReferenceComparatorPredicate() );

    if( it.first != it.second && !m_lstFreeObjects.empty() ) 
    {
        // Be sure that no reference is added twice to free list
        PdfError::DebugMessage( "Adding %d to freelist, is already contained !!", rReference.ObjectNumber() );
        return;
    }
    else
    {
        // When append free objects from external doc we need plus one number objects
        SetObjectCount( rReference );

        // Insert so that list stays sorted
        m_lstFreeObjects.insert( it.first, rReference );
    }
}