我想使用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?*/);
答案 0 :(得分:2)
我要看一下pango-view的源代码,"玩具"应用程序包含在pango中以展示其功能。它可以在所有pango模式中呈现