From ad2bc9d183ab9cc8b72902cf5ef0f94feef7a213 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 6 Oct 2010 14:18:11 +0200 Subject: [PATCH] beautiful: Track the font for oopango Signed-off-by: Uli Schlachter --- lib/beautiful.lua.in | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/beautiful.lua.in b/lib/beautiful.lua.in index 222eb104..72afa294 100644 --- a/lib/beautiful.lua.in +++ b/lib/beautiful.lua.in @@ -17,7 +17,9 @@ local util = require("awful.util") local capi = { screen = screen, - awesome = awesome + awesome = awesome, + oocairo = oocairo, + oopango = oopango } --- Theme library. @@ -25,6 +27,29 @@ module("beautiful") -- Local data local theme +local font +local font_height + +function get_font() + return font +end + +function get_font_height() + return font_height +end + +local function set_font(f) + font = capi.oopango.font_description_from_string(f) + + -- Create a temporary surface that we need for computing the size :( + local surface = capi.oocairo.image_surface_create("argb32", 1, 1) + local cr = capi.oocairo.context_create(surface) + local layout = capi.oopango.cairo.layout_create(cr) + layout:set_font_description(font) + + local width, height = layout:get_pixel_size() + font_height = height +end --- Init function, should be runned at the beginning of configuration file. -- @param path The theme file path. @@ -51,7 +76,7 @@ function init(path) util.spawn(theme.wallpaper_cmd[util.cycle(#theme.wallpaper_cmd, s)], false, s) end end - if theme.font then capi.awesome.font = theme.font end + if theme.font then set_font(theme.font) end if theme.fg_normal then capi.awesome.fg = theme.fg_normal end if theme.bg_normal then capi.awesome.bg = theme.bg_normal end else @@ -68,6 +93,9 @@ function get() return theme end +-- Set the default font +set_font("sans 8") + setmetatable(_M, { __index = function(t, k) return theme[k] end }) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80