+ gint x,y,w,h;
+ XftColor c;
+ GString *text;
+ gint mw, mh;
+ size_t l;
+ gboolean shortened = FALSE;
+
+#ifdef USE_PANGO
+ PangoLayout *pl;
+ PangoLayoutLine *pll;
+ PangoContext *context;
+ GSList *p;
+
+ context = pango_xft_get_context (RrDisplay(t->font->inst), RrScreen(t->font->inst));
+ pl = pango_layout_new (context);
+#endif /* USE_PANGO */
+
+ /* 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);
+ /* if the elipses are too large, don't show them at all */
+ if (ELIPSES_LENGTH(t->font) > area->width)
+ shortened = FALSE;
+ font_measure_full(t->font, text->str, &mw, &mh);
+ mw += ELIPSES_LENGTH(t->font);
+ }
+ 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 */
+
+#ifdef USE_PANGO
+ pango_layout_set_text(pl, text->str, l);
+ pango_layout_set_font_description(pl, t->font->pango_font_description);
+ pango_layout_set_single_paragraph_mode(pl, TRUE);
+ pll = pango_layout_get_line(pl, 0);
+#endif /* USE_PANGO */
+
+ if (t->font->shadow) {
+#ifdef USE_PANGO
+ int x2 = x;
+#endif /* USE_PANGO */
+ 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));
+#ifndef USE_PANGO
+ }
+ XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->font->offset,
+ t->font->xftfont->ascent + y + t->font->offset,
+ (FcChar8*)text->str, l);
+ }
+#else /* USE_PANGO */
+ }
+
+ for (p = pll->runs; p != NULL; p = p->next)
+ {
+ PangoLayoutRun *run = p->data;
+ PangoFont *font = run->item->analysis.font;
+ PangoGlyphString *glyphs = run->glyphs;
+ PangoRectangle rect;
+
+ pango_glyph_string_extents (glyphs, font, NULL, &rect);
+ pango_xft_render (d, &c, font, glyphs, x2 + t->font->offset,
+ t->font->xftfont->ascent + y + t->font->offset);
+ x2 += rect.width / PANGO_SCALE;
+ }
+ }
+#endif /* USE_PANGO */
+ c.color.red = t->color->r | t->color->r << 8;
+ c.color.green = t->color->g | t->color->g << 8;
+ c.color.blue = t->color->b | t->color->b << 8;
+ c.color.alpha = 0xff | 0xff << 8; /* fully opaque text */
+ c.pixel = t->color->pixel;
+
+#ifndef USE_PANGO
+ XftDrawStringUtf8(d, &c, t->font->xftfont, x,
+ t->font->xftfont->ascent + y,
+ (FcChar8*)text->str, l);
+#else /* USE_PANGO */
+ for (p = pll->runs; p != NULL; p = p->next)
+ {
+ PangoLayoutRun *run = p->data;
+ PangoFont *font = run->item->analysis.font;
+ PangoGlyphString *glyphs = run->glyphs;
+ PangoRectangle rect;
+
+ pango_glyph_string_extents (glyphs, font, NULL, &rect);
+ pango_xft_render (d, &c, font, glyphs, x, t->font->xftfont->ascent + y);
+ x += rect.width / PANGO_SCALE;
+ }
+
+ // pango_layout_line_unref(pll);
+ g_object_unref(pl);
+ g_object_unref(context);
+#endif /* USE_PANGO */
+
+ g_string_free(text, TRUE);
+ return;