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

PdfFont * PoDoFo::PdfFontCache::GetFont ( const char *  pszFontName,
bool  bBold,
bool  bItalic,
bool  bEmbedd,
EFontCreationFlags  eFontCreationFlags = eFontCreationFlags_AutoSelectBase14,
const PdfEncoding * const  pEncoding = PdfEncodingFactory::GlobalWinAnsiEncodingInstance(),
const char *  pszFileName = NULL 

Get a font from the cache. If the font does not yet exist, add it to the cache.

pszFontNamea valid fontname
bBoldif true search for a bold font
bItalicif true search for an italic font
bEmbeddif true a font for embedding into PDF will be created
eFontCreationFlagsspecial flag to specify how fonts should be created
pEncodingthe encoding of the font. The font will not take ownership of this object.
optional,:pszFileName path to a valid font file
a PdfFont object or NULL if the font could not be created or found.

Definition at line 230 of file PdfFontCache.cpp.

References CreateFontObject(), eFontCreationFlags_AutoSelectBase14, eFontCreationFlags_Type1Subsetting, PoDoFo::eLogSeverity_Critical, GetFontPath(), PoDoFo::PdfFont::IsBold(), PoDoFo::PdfFont::IsItalic(), PoDoFo::PdfError::LogMessage(), m_ftLibrary, m_pParent, PoDoFo::TFontCacheElement::m_sFontName, and m_vecFonts.

    PODOFO_ASSERT( pEncoding );

    PdfFont*          pFont = NULL;
    PdfFontMetrics*   pMetrics = NULL;
    std::pair<TISortedFontList,TCISortedFontList> it;

    it = std::equal_range( m_vecFonts.begin(), m_vecFonts.end(), 
                     TFontCacheElement( pszFontName, bBold, bItalic, pEncoding ) );

    if( it.first == it.second )
            if ( (eFontCreationFlags & eFontCreationFlags_AutoSelectBase14) 
             && PODOFO_Base14FontDef_FindBuiltinData(pszFontName))
                  pFont = CreateBase14Font(pszFontName,pEncoding,m_pParent);

                  if( pFont ) 
                        TFontCacheElement element;
                        element.m_pFont     = pFont;
                        element.m_bBold     = pFont->IsBold();
                        element.m_bItalic   = pFont->IsItalic();
                        element.m_sFontName = pszFontName;
                        element.m_pEncoding = pEncoding;

                        // Do a sorted insert, so no need to sort again
                        //rvecContainer.insert( itSorted, element ); 
                        m_vecFonts.insert( it.first, element );


            if (!pFont)
                  std::string sPath;
                  if ( pszFileName == NULL )
                        sPath = this->GetFontPath( pszFontName, bBold, bItalic );
                        sPath = pszFileName;
                  if( sPath.empty() )
#ifdef _WIN32
                        pFont = GetWin32Font( it.first, m_vecFonts, pszFontName, bBold, bItalic, bEmbedd, pEncoding );
#endif // _WIN32
                        bool bSubsetting = (eFontCreationFlags & eFontCreationFlags_Type1Subsetting) != 0;
                        pMetrics = new PdfFontMetricsFreetype( &m_ftLibrary, sPath.c_str() );
                        pFont    = this->CreateFontObject( it.first, m_vecFonts, pMetrics, 
                                       bEmbedd, bBold, bItalic, pszFontName, pEncoding, bSubsetting );

        pFont = (*it.first).m_pFont;

#ifndef WIN32
            if (!pFont)
              PdfError::LogMessage( eLogSeverity_Critical, "No path was found for the specified fontname: %s\n", pszFontName );

    return pFont;

Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index