+ GString *text;
+ gint mw;
+#ifndef USE_PANGO
+ gint mh;
+ size_t l;
+ gboolean shortened = FALSE;
+#else
+ PangoLayout *pl;
+ PangoRectangle rect;
+
+ pl = pango_layout_new (context);
+#endif /* USE_PANGO */
+
+ /* center vertically
+ * for xft we pass the top edge of the text for positioning... */
+#ifndef USE_PANGO
+ y = area->y +
+ (area->height - RrFontHeight(t->font)) / 2;
+#else
+ /* but for pango we pass the baseline, since different fonts have
+ * different top edges. It looks stupid when the baseline of "normal"
+ * text jumps up and down when a "strange" character is just added
+ * to the end of the text */
+ y = area->y +
+ font_calculate_baseline(t->font, area->height);
+#endif
+ /* 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);
+#ifndef USE_PANGO
+ 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;
+
+ l = strlen(text->str); /* number of bytes */
+
+#else
+ pango_layout_set_text(pl, text->str, -1);
+ pango_layout_set_font_description(pl, t->font->pango_font_description);
+ pango_layout_set_single_paragraph_mode(pl, TRUE);
+ pango_layout_set_width(pl, w * PANGO_SCALE);
+ pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_MIDDLE);
+ /* This doesn't work with layout_line() of course */
+/* pango_layout_set_alignment(pl, (PangoAlignment)(t->justify)); */
+ pango_layout_get_pixel_extents(pl, NULL, &rect);
+ mw = rect.width;
+
+#endif /* USE_PANGO */
+
+ 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;
+ }
+
+ 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));
+ }
+#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 */
+ /* see below... */
+ pango_xft_render_layout_line(d, &c, pango_layout_get_line(pl, 0),
+ (x + t->font->offset) * PANGO_SCALE,
+ (y + t->font->offset) * PANGO_SCALE);
+#endif /* USE_PANGO */
+ }