* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
*
*/
#include <assert.h>
static double pango_font_green;
static double pango_font_blue;
+static PangoLayout *create_layout_with_dpi(cairo_t *cr) {
+ PangoLayout *layout;
+ PangoContext *context;
+
+ context = pango_cairo_create_context(cr);
+ const double dpi = (double)root_screen->height_in_pixels * 25.4 /
+ (double)root_screen->height_in_millimeters;
+ LOG("X11 root window dictates %f DPI\n", dpi);
+ pango_cairo_context_set_resolution(context, dpi);
+ layout = pango_layout_new(context);
+ g_object_unref(context);
+
+ return layout;
+}
+
/*
* Loads a Pango font description into an i3Font structure. Returns true
* on success, false otherwise.
/* Create a dummy Pango layout to compute the font height */
cairo_surface_t *surface = cairo_xcb_surface_create(conn, root_screen->root, root_visual_type, 1, 1);
cairo_t *cr = cairo_create(surface);
- PangoLayout *layout = pango_cairo_create_layout(cr);
+ PangoLayout *layout = create_layout_with_dpi(cr);
pango_layout_set_font_description(layout, font->specific.pango_desc);
/* Get the font height */
cairo_surface_t *surface = cairo_xcb_surface_create(conn, drawable,
root_visual_type, x + max_width, y + savedFont->height);
cairo_t *cr = cairo_create(surface);
- PangoLayout *layout = pango_cairo_create_layout(cr);
+ PangoLayout *layout = create_layout_with_dpi(cr);
+ gint height;
+
pango_layout_set_font_description(layout, savedFont->specific.pango_desc);
pango_layout_set_width(layout, max_width * PANGO_SCALE);
pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
+ 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);
- cairo_move_to(cr, x, y);
- pango_layout_set_text(layout, text, text_len);
pango_cairo_update_layout(cr, layout);
+ pango_layout_get_pixel_size(layout, NULL, &height);
+ cairo_move_to(cr, x, y - (height - savedFont->height));
pango_cairo_show_layout(cr, layout);
/* Free resources */
/* 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);
cairo_t *cr = cairo_create(surface);
- PangoLayout *layout = pango_cairo_create_layout(cr);
+ PangoLayout *layout = create_layout_with_dpi(cr);
/* Get the font width */
gint width;
#if PANGO_SUPPORT
/* Try to load a pango font if specified */
if (strlen(pattern) > strlen("pango:") && !strncmp(pattern, "pango:", strlen("pango:"))) {
- pattern += strlen("pango:");
- if (load_pango_font(&font, pattern))
+ const char *font_pattern = pattern + strlen("pango:");
+ if (load_pango_font(&font, font_pattern)) {
+ font.pattern = sstrdup(pattern);
return font;
+ }
} else if (strlen(pattern) > strlen("xft:") && !strncmp(pattern, "xft:", strlen("xft:"))) {
- pattern += strlen("xft:");
- if (load_pango_font(&font, pattern))
+ const char *font_pattern = pattern + strlen("xft:");
+ if (load_pango_font(&font, font_pattern)) {
+ font.pattern = sstrdup(pattern);
return font;
+ }
}
#endif
}
}
+ font.pattern = sstrdup(pattern);
LOG("Using X font %s\n", pattern);
/* Get information (height/name) for this font */
*
*/
void free_font(void) {
+ free(savedFont->pattern);
switch (savedFont->type) {
case FONT_TYPE_NONE:
/* Nothing to do */