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

PdfFont * PoDoFo::PdfFontCache::GetFont ( PdfObject pObject )

Get a font from the cache. If the font does not yet exist, add it to the cache. This font is created from an existing object.

Parameters:
pObjecta PdfObject that is a font
Returns:
a PdfFont object or NULL if the font could not be created or found.

Definition at line 187 of file PdfFontCache.cpp.

References PoDoFo::PdfFontFactory::CreateFont(), PoDoFo::PdfFont::GetFontMetrics(), PoDoFo::PdfFontMetrics::GetFontname(), PoDoFo::PdfFont::IsBold(), PoDoFo::PdfFont::IsItalic(), m_ftLibrary, PoDoFo::TFontCacheElement::m_sFontName, m_vecFonts, and PoDoFo::PdfObject::Reference().

Referenced by PoDoFo::PdfDocument::CreateFont(), and PoDoFo::PdfMemDocument::GetFont().

{
    TCISortedFontList it = m_vecFonts.begin();
    const PdfReference & ref = pObject->Reference(); 

    // Search if the object is a cached normal font
    while( it != m_vecFonts.end() )
    {
        if( (*it).m_pFont->GetObject()->Reference() == ref ) 
            return (*it).m_pFont;

        ++it;
    }

    // Search if the object is a cached font subset
    it = m_vecFontSubsets.begin();
    while( it != m_vecFontSubsets.end() )
    {
        if( (*it).m_pFont->GetObject()->Reference() == ref ) 
            return (*it).m_pFont;

        ++it;
    }

    // Create a new font
    PdfFont* pFont = PdfFontFactory::CreateFont( &m_ftLibrary, pObject );
    if( pFont ) 
    {
        TFontCacheElement element;
        element.m_pFont     = pFont;
        element.m_bBold     = pFont->IsBold();
        element.m_bItalic   = pFont->IsItalic();
        element.m_sFontName = pFont->GetFontMetrics()->GetFontname();
        element.m_pEncoding = NULL;
        m_vecFonts  .push_back( element );
        
        // Now sort the font list
        std::sort( m_vecFonts.begin(), m_vecFonts.end() );
    }
    
    return pFont;
}

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