From 1442687830dfa27d9b33963ef32b88121b993189 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 7 Sep 2009 17:51:40 +0200 Subject: [PATCH] font: split out of draw Signed-off-by: Julien Danjou --- CMakeLists.txt | 1 + client.h | 1 + draw.c | 51 ------------------------------- draw.h | 9 ------ font.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ font.h | 37 +++++++++++++++++++++++ globalconf.h | 3 +- screen.h | 1 + widget.h | 1 + window.h | 3 +- 10 files changed, 126 insertions(+), 62 deletions(-) create mode 100644 font.c create mode 100644 font.h diff --git a/CMakeLists.txt b/CMakeLists.txt index af17cab1..58182cc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ set(AWE_SRCS ${SOURCE_DIR}/window.c ${SOURCE_DIR}/image.c ${SOURCE_DIR}/draw.c + ${SOURCE_DIR}/font.c ${SOURCE_DIR}/color.c ${SOURCE_DIR}/timer.c ${SOURCE_DIR}/common/buffer.c diff --git a/client.h b/client.h index ab5f6765..66eb260c 100644 --- a/client.h +++ b/client.h @@ -25,6 +25,7 @@ #include "mouse.h" #include "stack.h" #include "strut.h" +#include "draw.h" #include "common/luaobject.h" #define CLIENT_SELECT_INPUT_EVENT_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY \ diff --git a/draw.c b/draw.c index 9623e84e..48ff00b0 100644 --- a/draw.c +++ b/draw.c @@ -89,57 +89,6 @@ draw_iso2utf8(const char *iso, size_t len, char **dest, ssize_t *dlen) return true; } -/** Create a new Pango font. - * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]). - * \return A new font. - */ -font_t * -draw_font_new(const char *fontname) -{ - cairo_surface_t *surface; - xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen); - cairo_t *cr; - PangoLayout *layout; - font_t *font = p_new(font_t, 1); - - /* Create a dummy cairo surface, cairo context and pango layout in - * order to get font informations */ - surface = cairo_xcb_surface_create(globalconf.connection, - globalconf.default_screen, - globalconf.screens.tab[0].visual, - s->width_in_pixels, - s->height_in_pixels); - - cr = cairo_create(surface); - layout = pango_cairo_create_layout(cr); - - /* Get the font description used to set text on a PangoLayout */ - font->desc = pango_font_description_from_string(fontname); - pango_layout_set_font_description(layout, font->desc); - - /* Get height */ - pango_layout_get_pixel_size(layout, NULL, &font->height); - - g_object_unref(layout); - cairo_destroy(cr); - cairo_surface_destroy(surface); - - return font; -} - -/** Delete a font. - * \param font Font to delete. - */ -void -draw_font_delete(font_t **font) -{ - if(*font) - { - pango_font_description_free((*font)->desc); - p_delete(font); - } -} - /** Initialize a draw_text_context_t with text data. * \param data The draw text context to init. * \param str The text string to render. diff --git a/draw.h b/draw.h index 29260d0e..f57ad241 100644 --- a/draw.h +++ b/draw.h @@ -67,12 +67,6 @@ struct area_t #define AREA_RIGHT(a) ((a).x + (a).width) #define AREA_BOTTOM(a) ((a).y + (a).height) -typedef struct -{ - PangoFontDescription *desc; - int height; -} font_t; - typedef struct { xcb_pixmap_t pixmap; @@ -112,9 +106,6 @@ draw_context_wipe(draw_context_t *ctx) } } -font_t *draw_font_new(const char *); -void draw_font_delete(font_t **); - bool draw_iso2utf8(const char *, size_t, char **, ssize_t *); /** Convert a string to UTF-8. diff --git a/font.c b/font.c new file mode 100644 index 00000000..3c40e0f1 --- /dev/null +++ b/font.c @@ -0,0 +1,81 @@ +/* + * font.c - font functions + * + * Copyright © 2007-2009 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include + +#include "font.h" +#include "screen.h" +#include "globalconf.h" +#include "common/xutil.h" + +/** Create a new Pango font. + * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]). + * \return A new font. + */ +font_t * +draw_font_new(const char *fontname) +{ + cairo_surface_t *surface; + xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen); + cairo_t *cr; + PangoLayout *layout; + font_t *font = p_new(font_t, 1); + + /* Create a dummy cairo surface, cairo context and pango layout in + * order to get font informations */ + surface = cairo_xcb_surface_create(globalconf.connection, + globalconf.default_screen, + globalconf.screens.tab[0].visual, + s->width_in_pixels, + s->height_in_pixels); + + cr = cairo_create(surface); + layout = pango_cairo_create_layout(cr); + + /* Get the font description used to set text on a PangoLayout */ + font->desc = pango_font_description_from_string(fontname); + pango_layout_set_font_description(layout, font->desc); + + /* Get height */ + pango_layout_get_pixel_size(layout, NULL, &font->height); + + g_object_unref(layout); + cairo_destroy(cr); + cairo_surface_destroy(surface); + + return font; +} + +/** Delete a font. + * \param font Font to delete. + */ +void +draw_font_delete(font_t **font) +{ + if(*font) + { + pango_font_description_free((*font)->desc); + p_delete(font); + } +} + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/font.h b/font.h new file mode 100644 index 00000000..56f112db --- /dev/null +++ b/font.h @@ -0,0 +1,37 @@ +/* + * font.h - font functions header + * + * Copyright © 2009 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_FONT_H +#define AWESOME_FONT_H + +#include + +typedef struct +{ + PangoFontDescription *desc; + int height; +} font_t; + +font_t *draw_font_new(const char *); +void draw_font_delete(font_t **); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/globalconf.h b/globalconf.h index 0ae0d81a..f0b9ec93 100644 --- a/globalconf.h +++ b/globalconf.h @@ -31,7 +31,8 @@ #include #include "key.h" -#include "draw.h" +#include "color.h" +#include "font.h" #include "common/xembed.h" typedef struct wibox_t wibox_t; diff --git a/screen.h b/screen.h index 7ecb1a8e..104e4325 100644 --- a/screen.h +++ b/screen.h @@ -23,6 +23,7 @@ #define AWESOME_SCREEN_H #include "globalconf.h" +#include "draw.h" struct a_screen { diff --git a/widget.h b/widget.h index dcdec1eb..0f13b296 100644 --- a/widget.h +++ b/widget.h @@ -23,6 +23,7 @@ #define AWESOME_WIDGET_H #include "button.h" +#include "draw.h" #include "common/tokenize.h" typedef widget_t *(widget_constructor_t)(widget_t *); diff --git a/window.h b/window.h index 62225584..b2051860 100644 --- a/window.h +++ b/window.h @@ -1,7 +1,7 @@ /* * window.h - window handling functions header * - * Copyright © 2007-2008 Julien Danjou + * Copyright © 2007-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #define AWESOME_WINDOW_H #include "globalconf.h" +#include "draw.h" void window_state_set(xcb_window_t, long); xcb_get_property_cookie_t window_state_get_unchecked(xcb_window_t);