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);
- double ydpi = (double)root_screen->height_in_pixels * 25.4 / (double)root_screen->height_in_millimeters;
- PangoContext *pc = pango_cairo_create_context(cr);
- pango_cairo_context_set_resolution(pc, ydpi);
- PangoLayout *layout = pango_layout_new(pc);
+ PangoLayout *layout = create_layout_with_dpi(cr);
pango_layout_set_font_description(layout, font->specific.pango_desc);
/* Get the font height */
/* Free resources */
g_object_unref(layout);
- g_object_unref(pc);
cairo_destroy(cr);
cairo_surface_destroy(surface);
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);
- double ydpi = (double)root_screen->height_in_pixels * 25.4 / (double)root_screen->height_in_millimeters;
- PangoContext *pc = pango_cairo_create_context(cr);
- pango_cairo_context_set_resolution(pc, ydpi);
- PangoLayout *layout = pango_layout_new(pc);
+ PangoLayout *layout = create_layout_with_dpi(cr);
gint height;
pango_layout_set_font_description(layout, savedFont->specific.pango_desc);
/* Free resources */
g_object_unref(layout);
- g_object_unref(pc);
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
/* 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);
- double ydpi = (double)root_screen->height_in_pixels * 25.4 / (double)root_screen->height_in_millimeters;
- PangoContext *pc = pango_cairo_create_context(cr);
- pango_cairo_context_set_resolution(pc, ydpi);
- PangoLayout *layout = pango_layout_new(pc);
+ PangoLayout *layout = create_layout_with_dpi(cr);
/* Get the font width */
gint width;
/* Free resources */
g_object_unref(layout);
- g_object_unref(pc);
cairo_destroy(cr);
cairo_surface_destroy(surface);