gpt4 book ai didi

c - 使用 Pango 将文本呈现为使用 FreeType 字体的图像的简单示例是什么?

转载 作者:太空狗 更新时间:2023-10-29 15:38:47 24 4
gpt4 key购买 nike

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

// 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?*/);

最佳答案

我会看一下 pango-view 的源代码,这是 pango 中包含的“玩具”应用程序,用于展示其功能。它可以在所有 pango 模式下呈现

关于c - 使用 Pango 将文本呈现为使用 FreeType 字体的图像的简单示例是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18384069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com