[Top][All Lists]

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

[ft] Freetype outline rendering artifacts

From: Антон Бычков
Subject: [ft] Freetype outline rendering artifacts
Date: Wed, 31 May 2017 12:26:04 +0300


I've got a problem rasterizing glyph outlines to a bitmap.
Some letters ('a', 'b', 'e' for example) have artifacts near their center

Take a look at the screenshot:
An outline is rendered into both the green and the alpha texture channels.
Glyph itself is rendered into the red channel, which makes pixels
overlapped with outline yellow.
The texture is rendered over the blue background.

The artifacts appear when I render with high font size to outline ratio.
For example, on the above screenshot font size is set to 40 and outline
width set to 10. If outline is set to just several pixels, everything is ok.

How can I fix this?

Here is the code used for rendering:

void OutlineRasterizer::Init(uint32_t code, float size)
    m_code = code;
    m_size = size;

                   (int)(size * 64.0f),

    auto glyph_index = FT_Get_Char_Index(m_face, m_code);
    auto error = FT_Load_Glyph(m_face,          /* handle to face object */
                          glyph_index,   /* glyph index           */
                          FT_LOAD_DEFAULT);  /* load flags, see below */

    FT_Get_Glyph(m_face->glyph, &m_glyph);

    FT_Glyph_StrokeBorder(&m_glyph, m_stroker, 0, 1);
    FT_Glyph_Get_CBox(m_glyph, FT_GLYPH_BBOX_GRIDFIT, &m_bbox);

    FT_Outline *outline =

    int width = GetBitmapWidth();
    int rows = GetBitmapHeight();

    m_rasterized.resize(width * rows);

    //outline->flags |= FT_OUTLINE_HIGH_PRECISION;

    FT_Bitmap bmp;
    bmp.buffer =;
    bmp.width = (int)width;
    bmp.rows = (int)rows;
    bmp.pitch = (int)width;
    bmp.pixel_mode = FT_PIXEL_MODE_GRAY;
    bmp.num_grays = 256;

    FT_Raster_Params params;
    memset(&params, 0, sizeof (params));
    params.source = outline; = &bmp;
    params.flags = FT_RASTER_FLAG_AA;
    FT_Outline_Translate(outline, -m_bbox.xMin, -m_bbox.yMin);
    FT_Outline_Render(m_library, outline, &params);

reply via email to

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