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>
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]).
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
);
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
,
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
);
59 pango_layout_get_pixel_size(layout
, NULL
, &font
->height
);
61 g_object_unref(layout
);
63 cairo_surface_destroy(surface
);
69 * \param font Font to delete.
72 draw_font_delete(font_t
**font
)
76 pango_font_description_free((*font
)->desc
);
81 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80