diff options
Diffstat (limited to 'src/glibext/gbuffersegment.c')
-rw-r--r-- | src/glibext/gbuffersegment.c | 130 |
1 files changed, 126 insertions, 4 deletions
diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c index 3d9e5a9..1ebb543 100644 --- a/src/glibext/gbuffersegment.c +++ b/src/glibext/gbuffersegment.c @@ -200,7 +200,7 @@ static void g_buffer_segment_class_init(GBufferSegmentClass *class) void define_rendering_pattern(GtkStyleContext *ctx, const char *name, rendering_pattern_t *pattern) { - GdkRGBA *tmp_color; + GdkRGBA *tmp_color; /* Description d'une couleur */ PangoFontDescription *font_desc; /* Description d'une police */ gtk_style_context_save(ctx); @@ -219,10 +219,10 @@ static void g_buffer_segment_class_init(GBufferSegmentClass *class) case PANGO_STYLE_NORMAL: pattern->slant = CAIRO_FONT_SLANT_NORMAL; break; - case PANGO_STYLE_OBLIQUE: + case PANGO_STYLE_ITALIC: pattern->slant = CAIRO_FONT_SLANT_ITALIC; break; - case PANGO_STYLE_ITALIC: + case PANGO_STYLE_OBLIQUE: pattern->slant = CAIRO_FONT_SLANT_OBLIQUE; break; } @@ -303,7 +303,7 @@ GBufferSegment *g_buffer_segment_new(RenderingTagType type, const char *text, si result = g_object_new(G_TYPE_BUFFER_SEGMENT, NULL); - result->text = strdup(text); + result->text = strndup(text, length); result->hash = fnv_64a_hash(text); class = G_BUFFER_SEGMENT_GET_CLASS(result); @@ -640,3 +640,125 @@ void g_buffer_segment_draw(GBufferSegment *segment, cairo_t *cairo, gint *x, gin *x += segment->x_advance; } + + +/****************************************************************************** +* * +* Paramètres : ctx = éléments à disposition pour l'exportation. * +* type = type d'exportation attendue. * +* * +* Description : Exporte tous les styles utilisés par des segments. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_buffer_segment_export_style(buffer_export_context *ctx, BufferExportType type) +{ + GBufferSegment *dummy; /* Segment servant de sujet */ + GBufferSegmentClass *class; /* Classe des segments */ + size_t i; /* Boucle de parcours */ + const rendering_pattern_t *pattern; /* Modèle à transcrire */ + + dummy = g_object_new(G_TYPE_BUFFER_SEGMENT, NULL); + class = G_BUFFER_SEGMENT_GET_CLASS(dummy); + + for (i = 0; i < RTT_COUNT; i++) + { + pattern = &class->patterns[i]; + + switch (type) + { + case BET_HTML: + + dprintf(ctx->fd, ".%s {\n", _segment_names[i]); + + if (pattern->foreground.has_color) + dprintf(ctx->fd, "\tcolor: #%02hhx%02hhx%02hhx;\n", + (unsigned char)(pattern->foreground.color.red * 255), + (unsigned char)(pattern->foreground.color.green * 255), + (unsigned char)(pattern->foreground.color.blue * 255)); + + switch (pattern->slant) + { + case CAIRO_FONT_SLANT_ITALIC: + dprintf(ctx->fd, "\tfont-style: italic;\n"); + break; + case CAIRO_FONT_SLANT_OBLIQUE: + dprintf(ctx->fd, "\tfont-style: oblique;\n"); + break; + default: + dprintf(ctx->fd, "\tfont-style: normal;\n"); + break; + } + + switch (pattern->weight) + { + case CAIRO_FONT_WEIGHT_BOLD: + dprintf(ctx->fd, "\tfont-weight: bold;\n"); + break; + default: + dprintf(ctx->fd, "\tfont-weight: normal;\n"); + break; + } + + dprintf(ctx->fd, "}\n"); + + break; + + default: + break; + + } + + } + + g_object_unref(G_OBJECT(dummy)); + +} + + +/****************************************************************************** +* * +* Paramètres : segment = fragment de texte à manipuler. * +* ctx = éléments à disposition pour l'exportation. * +* type = type d'exportation attendue. * +* * +* Description : Exporte le fragment de texte représenté. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_buffer_segment_export(const GBufferSegment *segment, buffer_export_context *ctx, BufferExportType type) +{ + GBufferSegmentClass *class; /* Classe des segments */ + size_t index; /* Indice du modèle de rendu */ + + switch (type) + { + case BET_HTML: + class = G_BUFFER_SEGMENT_GET_CLASS(segment); + index = (segment->pattern - class->patterns); + dprintf(ctx->fd, "<SPAN class=\"%s\">", _segment_names[index]); + break; + default: + break; + } + + dprintf(ctx->fd, "%s", segment->text); + + switch (type) + { + case BET_HTML: + dprintf(ctx->fd, "</SPAN>"); + break; + default: + break; + } + +} |