Exemplo n.º 1
0
void    plWinFontCache::LoadCustomFonts( const char *dir )
{
    delete [] fCustFontDir;
    fCustFontDir = ( dir != nil ) ? hsStrcpy( dir ) : nil;

    ILoadCustomFonts();
}
Exemplo n.º 2
0
HFONT   plWinFontCache::IMakeFont( const char *face, int height, int weight, bool italic, uint32_t quality )
{
    plFontRecord    myRec;
    int             i;


    // Find a cached name for us
    for( i = 0; i < fFontNameCache.GetCount(); i++ )
    {
        if( strcmp( face, fFontNameCache[ i ] ) == 0 )
            break;
    }

    if( i == fFontNameCache.GetCount() )
        fFontNameCache.Append( hsStrcpy( face ) );

    myRec.fFace = fFontNameCache[ i ];
    myRec.fHeight = height;
    myRec.fWeight = weight;
    myRec.fItalic = italic;
    myRec.fQuality = quality;

    myRec.fFont = CreateFont( height, 0, 0, 0, weight, italic ? TRUE : FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
                            CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, face );

    if( myRec.fFont != nil )
    {
//#ifdef HS_DEBUGGING
#if 1
        LOGFONT fontInfo;

        if( GetObject( myRec.fFont, sizeof( fontInfo ), &fontInfo ) )
        {
            const char *err = nil;

            if( fontInfo.lfQuality != quality )         
                err = "Quality of created font does not match";
            if( fontInfo.lfHeight != height )
                err = "Height of created font does not match";
            if( fontInfo.lfWeight != weight )
                err = "Weight of created font does not match";
            if( static_cast<bool>(fontInfo.lfItalic) != italic )
                err = "Italic-ness of created font does not match";
            if( stricmp( fontInfo.lfFaceName, face ) != 0 )
                err = "Face of created font does not match";

            if( err != nil )
            {
                static bool triedClearing = false;

                if( fontInfo.lfQuality != quality )         
                {
                    plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() failed to return proper font (%s). Using what was given...", err );
                }
                else
                {
                    plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() failed to return proper font (%s). %s", err, triedClearing ? "" : "Clearing cache and retrying..." );
                    if( !triedClearing )
                    {
                        triedClearing = true;

                        // Didn't work, so get rid of it
                        DeleteObject( myRec.fFont );

                        // Clear all fonts and try again
                        Clear();
                        
                        // Make sure we reload our custom fonts tho
                        ILoadCustomFonts();
                        
                        // Try again
                        HFONT font = IMakeFont( face, height, weight, italic, quality );
                        
                        triedClearing = false;

                        return font;
                    }
                }
            }
        }
#endif

        fFontCache.Append( myRec );
    }
    else
    {
        plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() call FAILED (face: %s, size: %d %s %s)", face, -height, weight == FW_BOLD ? "bold" : "", italic ? "italic" : "" );
    }

    return myRec.fFont;
}
Exemplo n.º 3
0
void plFontCache::LoadCustomFonts( const plFileName &dir )
{
    fCustFontDir = dir;
    ILoadCustomFonts();
}