diff options
Diffstat (limited to 'src/glibext/gbuffersegment.c')
-rw-r--r-- | src/glibext/gbuffersegment.c | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c index 9510fa2..861c7cb 100644 --- a/src/glibext/gbuffersegment.c +++ b/src/glibext/gbuffersegment.c @@ -55,7 +55,7 @@ struct _GBufferSegment GdkColor *cache_used_fg; /* Couleur d'impression utile */ PangoGlyphString *glyphs; /* Caractères traités */ - PangoFont *font; /* Police utilisée à l'analyse */ + PangoFontDescription *desc; /* Description de police */ PangoRectangle logical; /* Dimension du texte */ @@ -127,7 +127,7 @@ static bool ascii_glyph_table_init(GBufferSegmentClass *class, PangoContext *con if (class->ascii_ready) { PangoItem *item; - int width; + //int width; item = (PangoItem *)list->data; //width = gui.char_width * PANGO_SCALE; @@ -159,10 +159,10 @@ static bool ascii_glyph_table_init(GBufferSegmentClass *class, PangoContext *con } - g_list_foreach(list, (GFunc)&pango_item_free, NULL); - g_list_free(list); + //g_list_foreach(list, (GFunc)&pango_item_free, NULL); + //g_list_free(list); - pango_attr_list_unref(attribs); + //pango_attr_list_unref(attribs); } @@ -201,11 +201,11 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont GList *item_list; PangoItem *item; - PangoRectangle logical; + //PangoRectangle logical; - char *max; - char *iter; + const char *max; + const char *iter; GBufferSegmentClass *class; @@ -215,6 +215,12 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont gint *log_clusters; PangoGlyphInfo *ref; + PangoFont *font; /* Modèle de police */ + PangoFontDescription *desc; /* Description de cette police */ + + + + glyphs = pango_glyph_string_new(); @@ -255,6 +261,8 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont max = text + length; + goto not_ascii; + for (iter = text; iter < max; iter++) if (*iter & 0x80) goto not_ascii; @@ -272,13 +280,11 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont for (i = 0; i < length; i++) { - info[i] = ref[text[i]]; + info[i] = ref[(unsigned int)text[i]]; log_clusters[i] = i; } - segment->font = class->ascii_font; - - pango_glyph_string_extents(glyphs, class->ascii_font, NULL, &segment->logical); + font = class->ascii_font; goto next; @@ -294,13 +300,14 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont item = (PangoItem *)item_list->data; pango_shape(text, length, &item->analysis, glyphs); - segment->font = item->analysis.font;/* TODO : ref ! */ - - pango_glyph_string_extents(glyphs, item->analysis.font, NULL, &segment->logical); - + font = item->analysis.font; next: + desc = pango_font_describe(font); + segment->desc = pango_font_description_copy(desc); + + pango_glyph_string_extents(glyphs, font, NULL, &segment->logical); //pango_shape(text, length, &item->analysis, glyphs); @@ -371,8 +378,7 @@ static void g_buffer_segment_init(GBufferSegment *segment) /****************************************************************************** * * -* Paramètres : context = contexte Pango pour l'analyse des caractères. * -* attribs = propriétés de la zone de texte. * +* Paramètres : attribs = propriétés de la zone de texte. * * text = chaîne de caractères à traiter. * * length = quantité de ces caractères. * * * @@ -384,19 +390,18 @@ static void g_buffer_segment_init(GBufferSegment *segment) * * ******************************************************************************/ -GBufferSegment *g_buffer_segment_new(PangoContext *context, PangoAttrList *attribs, const char *text, size_t length) +GBufferSegment *g_buffer_segment_new(PangoAttrList *attribs, const char *text, size_t length) { GBufferSegment *result; /* Composant à retourner */ result = g_object_new(G_TYPE_BUFFER_SEGMENT, NULL); - //result = g_new(GBufferSegment, 1); result->text = strdup(text); result->hash = fnv_64a_hash(text); result->attribs = pango_attr_list_ref(attribs); - g_buffer_segment_prepare(result, context, attribs, text, length); + g_buffer_segment_prepare(result, get_global_pango_context(), attribs, text, length); g_buffer_segment_cache_colors(result); @@ -556,11 +561,11 @@ void g_buffer_segment_set_style(GBufferSegment *segment, SegRenderingStyle style /****************************************************************************** * * -* Paramètres : segment = fragment de texte à manipuler. * -* drawable = surface de rendu où travailler. * -* gc = contexte graphique à utiliser pour les pinceaux. * -* x = abscisse du point d'impression (à maj). [OUT] * -* y = ordonnée du point d'impression. * +* Paramètres : segment = fragment de texte à manipuler. * +* cairo = contexte graphique à utiliser pour les pinceaux. * +* fcache = gestionnaire des polices pour l'impression. * +* x = abscisse du point d'impression (à maj). [OUT] * +* y = ordonnée du point d'impression. * * * * Description : Imprime le fragment de texte représenté. * * * @@ -570,27 +575,41 @@ void g_buffer_segment_set_style(GBufferSegment *segment, SegRenderingStyle style * * ******************************************************************************/ -void g_buffer_segment_draw(GBufferSegment *segment, GdkDrawable *drawable, GdkGC *gc, gint *x, gint y) +void g_buffer_segment_draw(GBufferSegment *segment, cairo_t *cairo, GFontCache *fcache, gint *x, gint y) { + PangoFont *font; /* Police d'impression */ + + /* FIXME */ + g_buffer_segment_prepare(segment, get_global_pango_context(), + segment->attribs, segment->text, strlen(segment->text)); + /* Fond du texte */ if (segment->style != SRS_CLASSIC) { - gdk_gc_set_rgb_fg_color(gc, &segment->cache_bg); + cairo_set_source_rgb(cairo, + segment->cache_bg.red / 65535.0, + segment->cache_bg.green / 65535.0, + segment->cache_bg.blue / 65535.0); - gdk_draw_rectangle(drawable, gc, TRUE, - *x, y, segment->logical.width, segment->logical.height); + cairo_rectangle(cairo, *x, y, segment->logical.width, segment->logical.height); + cairo_fill(cairo); } /* Couleur d'impression */ if (segment->cache_fg.pixel == COLOR_SET) - gdk_gc_set_rgb_fg_color(gc, segment->cache_used_fg); + cairo_set_source_rgb(cairo, + segment->cache_used_fg->red / 65535.0, + segment->cache_used_fg->green / 65535.0, + segment->cache_used_fg->blue / 65535.0); /* Impression du texte */ - gdk_draw_glyphs(drawable, gc, segment->font, - *x, y - segment->logical.y, segment->glyphs); + cairo_move_to(cairo, *x, y - segment->logical.y); + + font = g_font_cache_lookup(fcache, segment->desc); + pango_cairo_show_glyph_string(cairo, font, segment->glyphs); *x += segment->logical.width; |