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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-05-27 20:14:56 +02:00
parent 4f30dfd198
commit 68d630c32a
2 changed files with 5 additions and 12 deletions

View File

@ -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()

View File

@ -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)
@ -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")