freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft] Font-Metrics, FreeType and Qt.


From: address@hidden
Subject: [ft] Font-Metrics, FreeType and Qt.
Date: Thu, 30 Jul 2009 17:41:25 -0400
User-agent: Thunderbird 2.0.0.19 (X11/20081209)

Gang:

The story goes something like this...

Qt on X11 uses FontConfig and FreeType for text rendering.
The general ascent/descent/height metrics for most faces
(provided by FreeType) appear overstated to the point where
the text looks double spaced. (I am referring to text rendered
in list-boxes and pop-up windows etc.)

The code below is a wicked hack which uses apparent FreeType
glyph sizes to compute better estimates of the ascent/descent/height.
The result is an app which I am now able to release.

Bill

--------------------------
Remember, this is not just *a* hack. It is a *WICKED* hack,
but we do what we have to do to get the job done with the
tools, knowledge and time we have...

#   define HACK1 1                      /* Increase height */
#   define HACK2 2                      /* Shift position. */

    //        Bitmap based character height.
    int
    MyCharHeight( FT_Face face, FT_ULong char_code ) {
        int height = 0;
        int load_error = FT_Load_Char(face,char_code,FT_LOAD_RENDER);
        if( load_error == 0 )
            height = face->glyph->bitmap.rows;
        return height;
    }

    void
    MyComputeMetrics( FT_Face face, int *ascent, int *dscent ) {
        FT_Size_Metrics metrics = face->size->metrics;
        *ascent = metrics.ascender;
        *dscent = metrics.descender;

        int h_height = MyCharHeight(face,'h');
        if( h_height > 0 && (h_height+HACK1+HACK2)*64 < *ascent )
            *ascent = (h_height+HACK1+HACK2)*64;    // Looks like a better 
number.

        int y_height = MyCharHeight(face,'y');
        int x_height = MyCharHeight(face,'x');
        int y_desc = y_height - x_height;
        if( y_desc > 0 && (-y_desc-HACK1+HACK2)*64 > *dscent )
            *dscent = (-y_desc-HACK1+HACK2)*64;     // Looks like a better 
number.
    }

----------------
Used like this in qfontengine_ft.cpp just after QFontEngineFT::init extracts
the metrics from FreeType.

        int ascent, dscent;
        MyComputeMetrics( face, &ascent, &dscent );
        metrics.ascender  = ascent;
        metrics.descender = dscent;
        metrics.height = qRound( 1.2 * (metrics.ascender - metrics.descender) );





reply via email to

[Prev in Thread] Current Thread [Next in Thread]