Skip to content

Commit

Permalink
Remove a pango hack
Browse files Browse the repository at this point in the history
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 <psychon@znc.in>
  • Loading branch information
psychon committed May 27, 2012
1 parent 4f30dfd commit 68d630c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
5 changes: 2 additions & 3 deletions lib/beautiful.lua.in
Expand Up @@ -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()
Expand Down
12 changes: 3 additions & 9 deletions lib/wibox/widget/textbox.lua.in
Expand Up @@ -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. <b>bold</b>)
function set_markup(box, text)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 68d630c

Please sign in to comment.