Use pango to render text in the editor.

This commit is contained in:
Xinhao Yuan 2021-02-27 16:48:41 -05:00
parent 945ba92ef5
commit 5d02447da5
1 changed files with 11 additions and 11 deletions

View File

@ -146,9 +146,6 @@ function module.create(data)
local function start_interactive(screen, embed_args) local function start_interactive(screen, embed_args)
local label_font_family = beautiful.get_font(
beautiful.font):get_family()
local label_size = dpi(30)
local info_size = dpi(60) local info_size = dpi(60)
-- colors are in rgba -- colors are in rgba
local border_color = with_alpha( local border_color = with_alpha(
@ -236,7 +233,7 @@ function module.create(data)
end end
if #open_areas == 0 and not pending_op then if #open_areas == 0 and not pending_op then
current_info = current_info .. " (enter to apply)" current_info = current_info .. "\n(enter to apply)"
end end
return true return true
else else
@ -321,19 +318,22 @@ function module.create(data)
end end
end end
cr:select_font_face(label_font_family, "normal", "normal") local pl = lgi.Pango.Layout.create(cr)
cr:set_font_size(info_size) pl:set_font_description(beautiful.get_merged_font(beautiful.font, info_size))
cr:set_font_face(cr:get_font_face()) pl:set_alignment("CENTER")
msg = current_info pl:set_text(current_info)
ext = cr:text_extents(msg) local w, h = pl:get_size()
w = w / lgi.Pango.SCALE
h = h / lgi.Pango.SCALE
local ext = { width = w, height = h, x_bearing = 0, y_bearing = 0 }
cr:move_to(width / 2 - ext.width / 2 - ext.x_bearing, height / 2 - ext.height / 2 - ext.y_bearing) cr:move_to(width / 2 - ext.width / 2 - ext.x_bearing, height / 2 - ext.height / 2 - ext.y_bearing)
cr:text_path(msg)
cr:set_source_rgba(1, 1, 1, 1) cr:set_source_rgba(1, 1, 1, 1)
cr:show_layout(pl)
cr:fill() cr:fill()
cr:move_to(width / 2 - ext.width / 2 - ext.x_bearing, height / 2 - ext.height / 2 - ext.y_bearing) cr:move_to(width / 2 - ext.width / 2 - ext.x_bearing, height / 2 - ext.height / 2 - ext.y_bearing)
cr:text_path(msg)
cr:set_source_rgba(0, 0, 0, 1) cr:set_source_rgba(0, 0, 0, 1)
cr:set_line_width(2.0) cr:set_line_width(2.0)
cr:layout_path(pl)
cr:stroke() cr:stroke()
end end