+ 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;
+ }