2

我目前正在尝试创建仅包含字形外边框的字形位图,内部没有任何填充。为此使用 FreeType 库。这是我的代码,类似于 FreeType 参考中的示例 2 代码:

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);

结果,我得到outlineSpans了填充整个字形图像的跨度的矢量,但我只需要栅格化“边框”。 CurrentFace->glyph包含我使用FT_Load_Char(currentFace, *ch, FT_LOAD_NO_BITMAP)) 我做错了什么加载的字形?感谢您的帮助,网上没有太多关于 FreeType 的文档/示例。

4

1 回答 1

0

在解决方案下方分享如何使用轮廓字体进行操作,因为我只使用过轮廓字体,这可能会对您有所帮助。

        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
于 2013-11-13T09:12:03.827 回答