- if (t->shadow) {
- c.color.red = 0;
- c.color.green = 0;
- c.color.blue = 0;
- c.color.alpha = t->tint | t->tint << 8; // transparent shadow
- c.pixel = BlackPixel(ob_display, ob_screen);
-
- XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->offset,
- t->font->xftfont->ascent + y + t->offset,
- (FcChar8*)t->string, strlen(t->string));
+ GString *text;
+ gint mw, em, mh;
+ size_t l;
+ gboolean shortened = FALSE;
+
+ /* center vertically */
+ y = area->y +
+ (area->height - RrFontHeight(t->font)) / 2;
+ /* the +2 and -4 leave a small blank edge on the sides */
+ x = area->x + 2;
+ w = area->width - 4;
+ h = area->height;
+
+ text = g_string_new(t->string);
+ l = g_utf8_strlen(text->str, -1);
+ font_measure_full(t->font, text->str, &mw, &mh);
+ while (l && mw > area->width) {
+ shortened = TRUE;
+ /* remove a character from the middle */
+ text = g_string_erase(text, l-- / 2, 1);
+ em = ELIPSES_LENGTH(t->font);
+ /* if the elipses are too large, don't show them at all */
+ if (em > area->width)
+ shortened = FALSE;
+ font_measure_full(t->font, text->str, &mw, &mh);
+ mw += em;
+ }
+ if (shortened) {
+ text = g_string_insert(text, (l + 1) / 2, ELIPSES);
+ l += 3;
+ }
+ if (!l) return;
+
+ switch (t->justify) {
+ case RR_JUSTIFY_LEFT:
+ break;
+ case RR_JUSTIFY_RIGHT:
+ x += (w - mw);
+ break;
+ case RR_JUSTIFY_CENTER:
+ x += (w - mw) / 2;
+ break;
+ }
+
+ l = strlen(text->str); /* number of bytes */
+
+ if (t->font->shadow) {
+ if (t->font->tint >= 0) {
+ c.color.red = 0;
+ c.color.green = 0;
+ c.color.blue = 0;
+ c.color.alpha = 0xffff * t->font->tint / 100;
+ c.pixel = BlackPixel(RrDisplay(t->font->inst),
+ RrScreen(t->font->inst));
+ } else {
+ c.color.red = 0xffff;
+ c.color.green = 0xffff;
+ c.color.blue = 0xffff;
+ c.color.alpha = 0xffff * -t->font->tint / 100;
+ c.pixel = WhitePixel(RrDisplay(t->font->inst),
+ RrScreen(t->font->inst));
+ }
+ XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->font->offset,
+ t->font->xftfont->ascent + y + t->font->offset,
+ (FcChar8*)text->str, l);