summaryrefslogtreecommitdiff
path: root/src/glibext/gbuffersegment.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-04-18 22:30:19 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-04-18 22:30:19 (GMT)
commitfb12cfc1727ba949b70a48ee042a2aec9ebbb407 (patch)
treee2c7300262312d77c9f57657e5238d269b7189c0 /src/glibext/gbuffersegment.c
parentef29fbc801e23f547b9ee7666b713bcf32d7e787 (diff)
Defined attributes for printing binary content using GLib.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@153 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/glibext/gbuffersegment.c')
-rw-r--r--src/glibext/gbuffersegment.c96
1 files changed, 92 insertions, 4 deletions
diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c
index bcafa97..0714e9c 100644
--- a/src/glibext/gbuffersegment.c
+++ b/src/glibext/gbuffersegment.c
@@ -28,7 +28,9 @@
-
+/* Utilisation du champ pixel des couleurs cachées */
+#define COLOR_NOT_SET 0
+#define COLOR_SET 1
/* Fragment de caractères aux propriétés communes (instance) */
@@ -36,6 +38,10 @@ struct _GBufferSegment
{
GObject parent; /* A laisser en premier */
+ PangoAttrList *attribs; /* Propriétés du rendu */
+
+ GdkColor cache_fg; /* Couleur d'impression */
+
PangoGlyphString *glyphs; /* Caractères traités */
PangoFont *font; /* Police utilisée à l'analyse */
@@ -176,6 +182,9 @@ static bool ascii_glyph_table_init(GBufferSegmentClass *class, PangoContext *con
static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *context, PangoAttrList *attribs, const char *text, size_t length)
{
PangoGlyphString *glyphs; /* Caractères traités */
+ bool must_use_pango; /* Passage par Pango obligé ? */
+ PangoAttrIterator *iterator; /* Guide de parcours */
+ PangoAttribute *attrib; /* Attribut générique */
GList *item_list;
PangoItem *item;
@@ -199,6 +208,29 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont
+
+
+ /* Existe-t-il des attributs particuliers ? */
+
+ must_use_pango = false;
+
+ iterator = pango_attr_list_get_iterator(attribs);
+
+ attrib = pango_attr_iterator_get(iterator, PANGO_ATTR_WEIGHT);
+ must_use_pango |= (attrib != NULL);
+
+ pango_attr_iterator_destroy(iterator);
+
+ if (must_use_pango)
+ goto not_ascii;
+
+
+
+
+
+
+
+
/**
* Petite astuce empruntée à Vim...
* (cf. src/gui_gtk_x11.c, fonction gui_gtk2_draw_string()).
@@ -229,6 +261,10 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont
log_clusters[i] = i;
}
+ segment->font = class->ascii_font;
+
+ pango_glyph_string_extents(glyphs, class->ascii_font, NULL, &segment->logical);
+
goto next;
not_ascii:
@@ -243,7 +279,9 @@ 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 ! */
+ segment->font = item->analysis.font;/* TODO : ref ! */
+
+ pango_glyph_string_extents(glyphs, item->analysis.font, NULL, &segment->logical);
next:
@@ -252,7 +290,7 @@ static void g_buffer_segment_prepare(GBufferSegment *segment, PangoContext *cont
//pango_shape(text, length, &item->analysis, glyphs);
- pango_glyph_string_extents(glyphs, class->ascii_font, NULL, &segment->logical);
+ //pango_glyph_string_extents(glyphs, class->ascii_font, NULL, &segment->logical);
segment->logical.y /= PANGO_SCALE;
segment->logical.width /= PANGO_SCALE;
@@ -338,8 +376,11 @@ GBufferSegment *g_buffer_segment_new(PangoContext *context, PangoAttrList *attri
result = g_object_new(G_TYPE_BUFFER_SEGMENT, NULL);
//result = g_new(GBufferSegment, 1);
+ result->attribs = pango_attr_list_ref(attribs);
+
g_buffer_segment_prepare(result, context, attribs, text, length);
+ g_buffer_segment_cache_colors(result);
return result;
@@ -367,6 +408,46 @@ gint g_buffer_segment_get_width(const GBufferSegment *segment)
/******************************************************************************
* *
+* Paramètres : segment = fragment de texte à manipuler. *
+* *
+* Description : (Re)charge les couleurs à partir de la liste d'attributs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_buffer_segment_cache_colors(GBufferSegment *segment)
+{
+ PangoAttrIterator *iterator; /* Guide de parcours */
+ PangoAttribute *attrib; /* Attribut générique */
+ PangoAttrColor *color_attrib; /* Propriété de couleur */
+
+ iterator = pango_attr_list_get_iterator(segment->attribs);
+
+ /* Couleur d'impression */
+
+ attrib = pango_attr_iterator_get(iterator, PANGO_ATTR_FOREGROUND);
+ segment->cache_fg.pixel = (attrib != NULL ? COLOR_SET : COLOR_NOT_SET);
+
+ if (segment->cache_fg.pixel == COLOR_SET)
+ {
+ color_attrib = (PangoAttrColor *)attrib;
+
+ segment->cache_fg.red = color_attrib->color.red;
+ segment->cache_fg.green = color_attrib->color.green;
+ segment->cache_fg.blue = color_attrib->color.blue;
+
+ }
+
+ pango_attr_iterator_destroy(iterator);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : segment = fragment de texte à manipuler. *
* drawable = surface de rendu où travailler. *
* gc = contexte graphique à utiliser pour les pinceaux. *
@@ -383,7 +464,14 @@ gint g_buffer_segment_get_width(const GBufferSegment *segment)
void g_buffer_segment_draw(GBufferSegment *segment, GdkDrawable *drawable, GdkGC *gc, gint *x, gint y)
{
- gdk_draw_glyphs(drawable, gc, G_BUFFER_SEGMENT_GET_CLASS(segment)->ascii_font,
+ /* Couleur d'impression */
+
+ if (segment->cache_fg.pixel == COLOR_SET)
+ gdk_gc_set_rgb_fg_color(gc, &segment->cache_fg);
+
+ /* Impression du texte */
+
+ gdk_draw_glyphs(drawable, gc, segment->font,
*x, y - segment->logical.y, segment->glyphs);
*x += segment->logical.width;