2

I'm currently trying to create glyph bitmap which contains only outside border of the glyph, without any filling inside. Using FreeType library for this. Here is my code which is similar to example 2 code from FreeType reference:

Spans outlineSpans;
FT_Stroker stroker;
FT_Stroker_New(ft, &stroker);
FT_Stroker_Set(stroker, outlineWidth, round ? FT_STROKER_LINECAP_ROUND : FT_STROKER_LINECAP_SQUARE, round ? FT_STROKER_LINEJOIN_ROUND : FT_STROKER_LINEJOIN_BEVEL, 0);

FT_Glyph g;
FT_Get_Glyph(currentFace->glyph, &g);
FT_Glyph_StrokeBorder(&g, stroker, 0, 1);

FT_Raster_Params params;
memset(&params, 0, sizeof(params));
params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT;
params.gray_spans = RasterCallback;
params.user = &outlineSpans;
outlineSpans.clear();
FT_Outline *o = &reinterpret_cast<FT_OutlineGlyph>(g)->outline;
int err = FT_Outline_Render(ft, o, &params);

FT_Stroker_Done(stroker);
FT_Done_Glyph(g);

As result I get outlineSpans vector filled with spans for the whole glyph image, but I need only the "border" to be rasterized. CurrentFace->glyph contains the glyph which I loaded using FT_Load_Char(currentFace, *ch, FT_LOAD_NO_BITMAP)) What am I doing wrong? Thanks for any help, there is not so much documentation/examples about FreeType in the net.

user1687498
  • 61
  • 1
  • 7

1 Answers1

0

Sharing below the solution how you can do it with outline fonts since I have worked with that only, that might help you .

        FT_OutlineGlyph _oGlyph;
        struct Point{
            int x;
            int y;
        };

        vector<std::pair<int, int>> pointsPairVector;

        pointCount = _oGlyph->outline.n_points;

        for(int i = 0; i < pointCount; i++)
        {
            point.first = _oGlyph->outline.points[i].x;
            point.second = _oGlyph->outline.points[i].y;
            pointsPairVector.push_back(point)
        }
        //use Cairo to connect points in pointsPairVector
cbinder
  • 2,388
  • 2
  • 21
  • 36