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

PdfFont * PoDoFo::PdfFontCache::GetFontSubset ( const char *  pszFontName,
bool  bBold,
bool  bItalic,
const PdfEncoding * const  pEncoding = PdfEncodingFactory::GlobalWinAnsiEncodingInstance(),
const char *  pszFileName = NULL 

Get a fontsubset 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
pEncodingthe encoding of the font. All characters of the encoding will be included in this subset. 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 403 of file PdfFontCache.cpp.

References PoDoFo::PdfFontTTFSubset::AddCharacter(), PoDoFo::PdfEncoding::begin(), PoDoFo::PdfFontTTFSubset::BuildFont(), CreateFontObject(), PoDoFo::PdfFontTTFSubset::eFontFileType_TTF, PoDoFo::eLogSeverity_Critical, PoDoFo::PdfEncoding::end(), PoDoFo::ePdfError_InvalidFontFile, GetFontPath(), PoDoFo::PdfFontMetrics::GetFontType(), PoDoFo::PdfError::LogMessage(), m_ftLibrary, and PODOFO_RAISE_ERROR_INFO.

Referenced by PoDoFo::PdfDocument::CreateFontSubset().

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

    // WARNING: The characters are completely ignored right now!

    it = std::equal_range( m_vecFontSubsets.begin(), m_vecFontSubsets.end(), 
                     TFontCacheElement( pszFontName, bBold, bItalic, pEncoding ) );
    if( it.first == it.second )
        std::string sPath; 
        if( pszFileName == NULL ) 
            sPath = this->GetFontPath( pszFontName, bBold, bItalic );
            if( sPath.empty() )
#ifdef _WIN32
                // TODO: GetWin32Font
                PODOFO_ASSERT( 0 );
                PdfError::LogMessage( eLogSeverity_Critical, "No path was found for the specified fontname: %s\n", pszFontName );
                return NULL;
#endif // _WIN32
            sPath = pszFileName;
        pMetrics = new PdfFontMetricsFreetype( &m_ftLibrary, sPath.c_str() );
        if( !(pMetrics && pMetrics->GetFontType() == ePdfFontType_TrueType ) )
            PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Subsetting is only supported for TrueType fonts." );
        PdfInputDevice          input( sPath.c_str() );
        PdfRefCountedBuffer     buffer;
        PdfOutputDevice         output( &buffer );
        PdfFontTTFSubset        subset( &input, pMetrics, PdfFontTTFSubset::eFontFileType_TTF );
        PdfEncoding::const_iterator itChar
            = pEncoding->begin();
        while( itChar != pEncoding->end() )
            subset.AddCharacter( *itChar );
        subset.BuildFont( &output );
        // Delete metrics object, as it was only used so that PdfFontTTFSubset could
        // match unicode character points to glyph indeces
        delete pMetrics;
        // TODO: Do not hardcode unique basenames...
        pMetrics = new PdfFontMetricsFreetype( &m_ftLibrary, buffer, "ABCDEF+" );
        pFont = this->CreateFontObject( it.first, m_vecFontSubsets, pMetrics, 
                                        true, bBold, bItalic, pszFontName, pEncoding );
        pFont = (*it.first).m_pFont;
    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