GtkDrawingArea提供了在widget中做图的功能。
参考GTK+的文档,connect to "expose_event"。在回调函数中通过gdk_draw_xxx 系列函数做图。
但是基于DirectFb的gdk没有实现gdk_draw_text()函数。不过我们可以通过gdk_draw_glyphs()来绘制文本。
gboolean
expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
PangoContext *context;
PangoFontDescription *desc;
PangoFont *font;
PangoGlyphString* glyphString;
GList* items;
context = gtk_widget_get_pango_context( widget );
desc = pango_font_description_from_string("Sans");
if( desc != NULL )
{
pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
pango_font_description_set_size (desc, 24 * PANGO_SCALE);
pango_context_set_font_description( context, desc );
font = pango_context_load_font( context, desc );
items = pango_itemize( context, "hellohello", 0, 10, NULL, NULL);
PangoItem *item = (PangoItem *) (items->data);
本文介绍如何使用GtkDrawingArea和Pango库在GTK+应用中绘制文本。通过实例展示了如何设置字体、大小并利用gdk_draw_glyphs()函数完成文本绘制的过程。
3183

被折叠的 条评论
为什么被折叠?



