*
*/
static void draw_text_pango(const char *text, size_t text_len,
- xcb_drawable_t drawable, int x, int y, int max_width) {
+ xcb_drawable_t drawable, int x, int y,
+ int max_width, bool is_markup) {
/* Create the Pango layout */
/* root_visual_type is cached in load_pango_font */
cairo_surface_t *surface = cairo_xcb_surface_create(conn, drawable,
pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
- pango_layout_set_text(layout, text, text_len);
+ if (is_markup)
+ pango_layout_set_markup(layout, text, text_len);
+ else
+ pango_layout_set_text(layout, text, text_len);
/* Do the drawing */
cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue);
pango_cairo_update_layout(cr, layout);
pango_layout_get_pixel_size(layout, NULL, &height);
- cairo_move_to(cr, x, y - (height - savedFont->height));
+ /* Center the piece of text vertically if its height is smaller than the
+ * cached font height, and just let "high" symbols fall out otherwise. */
+ int yoffset = (height < savedFont->height ? 0.5 : 1) * (height - savedFont->height);
+ cairo_move_to(cr, x, y - yoffset);
pango_cairo_show_layout(cr, layout);
/* Free resources */
* Calculate the text width using Pango rendering.
*
*/
-static int predict_text_width_pango(const char *text, size_t text_len) {
+static int predict_text_width_pango(const char *text, size_t text_len, bool is_markup) {
/* Create a dummy Pango layout */
/* root_visual_type is cached in load_pango_font */
cairo_surface_t *surface = cairo_xcb_surface_create(conn, root_screen->root, root_visual_type, 1, 1);
/* Get the font width */
gint width;
pango_layout_set_font_description(layout, savedFont->specific.pango_desc);
- pango_layout_set_text(layout, text, text_len);
+
+ if (is_markup)
+ pango_layout_set_markup(layout, text, text_len);
+ else
+ pango_layout_set_text(layout, text, text_len);
+
pango_cairo_update_layout(cr, layout);
pango_layout_get_pixel_size(layout, &width, NULL);
case FONT_TYPE_PANGO:
/* Render the text using Pango */
draw_text_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
- drawable, x, y, max_width);
+ drawable, x, y, max_width, i3string_is_markup(text));
return;
#endif
default:
case FONT_TYPE_PANGO:
/* Render the text using Pango */
draw_text_pango(text, strlen(text),
- drawable, x, y, max_width);
+ drawable, x, y, max_width, false);
return;
#endif
default:
cookie, &error);
if (reply == NULL) {
/* We return a safe estimate because a rendering error is better than
- * a crash. Plus, the user will see the error in his log. */
+ * a crash. Plus, the user will see the error in their log. */
fprintf(stderr, "Could not get text extents (X error code %d)\n",
error->error_code);
return savedFont->specific.xcb.info->max_bounds.character_width * text_len;
#if PANGO_SUPPORT
case FONT_TYPE_PANGO:
/* Calculate extents using Pango */
- return predict_text_width_pango(i3string_as_utf8(text), i3string_get_num_bytes(text));
+ return predict_text_width_pango(i3string_as_utf8(text), i3string_get_num_bytes(text),
+ i3string_is_markup(text));
#endif
default:
assert(false);