]> Dogcows Code - chaz/openbox/commitdiff
add shortcuts for text rendering. it underlines the first character in the string...
authorDana Jansens <danakj@orodu.net>
Wed, 25 Apr 2007 01:32:43 +0000 (01:32 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 25 Apr 2007 01:32:43 +0000 (01:32 +0000)
render/font.c
render/render.h

index 266a00861a367f081f509a04fc493d3aeb6ebc00..a0e622d55364deac81a5f66f50690127173bc649 100644 (file)
@@ -175,6 +175,8 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     XftColor c;
     gint mw;
     PangoRectangle rect;
     XftColor c;
     gint mw;
     PangoRectangle rect;
+    gchar *text;
+    PangoAttrList* attrs = NULL;
 
     /* center the text vertically
        We do this centering based on the 'baseline' since different fonts have
 
     /* center the text vertically
        We do this centering based on the 'baseline' since different fonts have
@@ -188,9 +190,37 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     w = area->width - 4;
     h = area->height;
 
     w = area->width - 4;
     h = area->height;
 
-    pango_layout_set_text(t->font->layout, t->string, -1);
+    /* * * set up the layout * * */
+
+    text = g_strdup(t->string);
+
+    if (t->shortcut) {
+        gchar *i;
+        gchar *lowertext;
+
+        lowertext = g_utf8_strdown(text, -1);
+        i = g_utf8_strchr(lowertext, -1, t->shortcut);
+        if (i != NULL) {
+            PangoAttribute *a;
+
+            a = pango_attr_underline_new(PANGO_UNDERLINE_LOW);
+            a->start_index = i - lowertext;
+            a->end_index = i - lowertext +
+                g_unichar_to_utf8(t->shortcut, NULL);
+
+            attrs = pango_attr_list_new();
+            pango_attr_list_insert(attrs, a);
+        }
+        g_free(lowertext);
+    }
+
+    pango_layout_set_text(t->font->layout, text, -1);
     pango_layout_set_width(t->font->layout, w * PANGO_SCALE);
 
     pango_layout_set_width(t->font->layout, w * PANGO_SCALE);
 
+    g_free(text);
+
+    /* * * end of setting up the layout * * */
+
     pango_layout_get_pixel_extents(t->font->layout, NULL, &rect);
     mw = rect.width;
 
     pango_layout_get_pixel_extents(t->font->layout, NULL, &rect);
     mw = rect.width;
 
@@ -213,6 +243,9 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
         c.color.blue = t->shadow_color->b | t->shadow_color->b << 8;
         c.color.alpha = 0xffff * t->shadow_alpha / 255;
         c.pixel = t->shadow_color->pixel;
         c.color.blue = t->shadow_color->b | t->shadow_color->b << 8;
         c.color.alpha = 0xffff * t->shadow_alpha / 255;
         c.pixel = t->shadow_color->pixel;
+
+        pango_layout_set_attributes(t->font->layout, NULL);
+
         /* see below... */
         pango_xft_render_layout_line
             (d, &c, pango_layout_get_line(t->font->layout, 0),
         /* see below... */
         pango_xft_render_layout_line
             (d, &c, pango_layout_get_line(t->font->layout, 0),
@@ -226,6 +259,9 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     c.color.alpha = 0xff | 0xff << 8; /* fully opaque text */
     c.pixel = t->color->pixel;
 
     c.color.alpha = 0xff | 0xff << 8; /* fully opaque text */
     c.pixel = t->color->pixel;
 
+    pango_layout_set_attributes(t->font->layout, attrs);
+    if (attrs != NULL) pango_attr_list_unref(attrs);
+
     /* layout_line() uses y to specify the baseline
        The line doesn't need to be freed, it's a part of the layout */
     pango_xft_render_layout_line
     /* layout_line() uses y to specify the baseline
        The line doesn't need to be freed, it's a part of the layout */
     pango_xft_render_layout_line
index 7beef9c9f3cc12822099e2f429e7aedd2d0c5bf1..26de9e481dc621839cb8cf404fef22a60144cc4f 100644 (file)
@@ -126,6 +126,7 @@ struct _RrTextureText {
     gint shadow_offset_y;
     RrColor *shadow_color;
     gchar shadow_alpha;
     gint shadow_offset_y;
     RrColor *shadow_color;
     gchar shadow_alpha;
+    gunichar shortcut; /*!< Underline this character */
 };
 
 struct _RrPixmapMask {
 };
 
 struct _RrPixmapMask {
This page took 0.031679 seconds and 4 git commands to generate.