使用Pango将文本渲染为图像并使用FreeType字体的简单示例是什么?

9

我想使用Pango来呈现文本,但是我找不到不使用Cairo的示例代码。有人可以给我一个简单的Pango使用示例和FreeType后端吗?我大致认为它应该是这样工作的,但是正如您在代码中看到的那样,有些事情我还不理解。

// context and font stuff
PangoFontMap *fontmap = pango_ft2_font_map_new();
// do I have to initialize the fontmap?
PangoContext *context = pango_font_map_create_context(fontmap);
PangoFontDescription *desc = pango_font_description_new();
pango_font_description_set_style(desc, PANGO_STYLE_NORMAL); // not bold or italic
pango_font_description_set_size(desc, 12); // 12pt font
PangoFont *font = pango_context_load_font(context, desc);

// target bitmap
FT_Bitmap bitmap;
// how do I say how big the bitmap should be? write it into the struct?
FT_Bitmap_New(&bitmap);

// text
char *text = "Hello World";
PangoAttrList *attrs = pango_attr_list_new();
GList *items = pango_itemize(context, text, 0, strlen(text), attrs, NULL);
// do I have to initialize this?
PangoGlyphString *glyphs = pango_glyph_string_new();
pango_shape(text, strlen(text),
      /* PangoAnalysis here – where do I get that? */, glyphs);

pango_ft2_render(&bitmap, font, PangoGlyphString *glyphs,
      0, 0/*or does this have to be height-1?*/);
1个回答

3

14
答案不应只是指向外部资源。 - user877329

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接