From 68d630c32a98061a907d5ba290cd388e051c6ab2 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 27 May 2012 20:14:56 +0200 Subject: [PATCH] Remove a pango hack Instead of creating unused cairo image surfaces, we create our temporary layouts now via the (PangoCairo) font map. Way less ugly. Signed-off-by: Uli Schlachter --- lib/beautiful.lua.in | 5 ++--- lib/wibox/widget/textbox.lua.in | 12 +++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/beautiful.lua.in b/lib/beautiful.lua.in index 8b7ddd5af..cf512fd10 100644 --- a/lib/beautiful.lua.in +++ b/lib/beautiful.lua.in @@ -44,9 +44,8 @@ local function load_font(name) -- load new font local desc = Pango.FontDescription.from_string(name) - -- Create a temporary surface that we need for computing the size :( - local surface = cairo.ImageSurface(cairo.Format.ARGB32, 1, 1) - local layout = PangoCairo.create_layout(cairo.Context(surface)) + local ctx = PangoCairo.font_map_get_default():create_context() + local layout = Pango.Layout.new(ctx) layout:set_font_description(desc) local width, height = layout:get_pixel_size() diff --git a/lib/wibox/widget/textbox.lua.in b/lib/wibox/widget/textbox.lua.in index e33bd4b73..b09987f60 100644 --- a/lib/wibox/widget/textbox.lua.in +++ b/lib/wibox/widget/textbox.lua.in @@ -48,13 +48,6 @@ function fit(box, width, height) return logical.width, logical.height end --- Return a pango layout which can be used if no cairo context is available -local function get_temp_layout() - local surface = cairo.ImageSurface(cairo.Format.ARGB32, 0, 0) - local cr = cairo.Context(surface) - return PangoCairo.create_layout(cr) -end - --- Set a textbox' text. -- @param text The text to set. This can contain pango markup (e.g. bold) function set_markup(box, text) @@ -131,8 +124,9 @@ local function new() end end - -- Spot the hack: Temporary surface to make pango happy - ret._layout = get_temp_layout() + local ctx = PangoCairo.font_map_get_default():create_context() + ret._layout = Pango.Layout.new(ctx) + ret:set_ellipsize("end") ret:set_wrap("word_char") ret:set_valign("center")