change codename
[awesome.git] / font.c
blob3c40e0f14fcdbc7dbd2f5d87cbd4e0f86f535cde
1 /*
2 * font.c - font functions
4 * Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <cairo/cairo-xcb.h>
23 #include <pango/pangocairo.h>
25 #include "font.h"
26 #include "screen.h"
27 #include "globalconf.h"
28 #include "common/xutil.h"
30 /** Create a new Pango font.
31 * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]).
32 * \return A new font.
34 font_t *
35 draw_font_new(const char *fontname)
37 cairo_surface_t *surface;
38 xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
39 cairo_t *cr;
40 PangoLayout *layout;
41 font_t *font = p_new(font_t, 1);
43 /* Create a dummy cairo surface, cairo context and pango layout in
44 * order to get font informations */
45 surface = cairo_xcb_surface_create(globalconf.connection,
46 globalconf.default_screen,
47 globalconf.screens.tab[0].visual,
48 s->width_in_pixels,
49 s->height_in_pixels);
51 cr = cairo_create(surface);
52 layout = pango_cairo_create_layout(cr);
54 /* Get the font description used to set text on a PangoLayout */
55 font->desc = pango_font_description_from_string(fontname);
56 pango_layout_set_font_description(layout, font->desc);
58 /* Get height */
59 pango_layout_get_pixel_size(layout, NULL, &font->height);
61 g_object_unref(layout);
62 cairo_destroy(cr);
63 cairo_surface_destroy(surface);
65 return font;
68 /** Delete a font.
69 * \param font Font to delete.
71 void
72 draw_font_delete(font_t **font)
74 if(*font)
76 pango_font_description_free((*font)->desc);
77 p_delete(font);
81 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80