switcher: use pango for cjk support
This commit is contained in:
parent
1f690824fd
commit
058f9a26a7
21
switcher.lua
21
switcher.lua
|
@ -38,9 +38,10 @@ local function with_alpha(col, alpha)
|
||||||
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
||||||
end
|
end
|
||||||
|
|
||||||
local label_font_family = api.beautiful.get_font(
|
|
||||||
api.beautiful.mono_font or api.beautiful.font):get_family()
|
|
||||||
local tablist_font_size = api.dpi(15)
|
local tablist_font_size = api.dpi(15)
|
||||||
|
local tablist_font_desc = api.beautiful.get_merged_font(
|
||||||
|
api.beautiful.mono_font or api.beautiful.font, tablist_font_size)
|
||||||
local font_color = with_alpha(api.gears.color(api.beautiful.fg_normal), 1)
|
local font_color = with_alpha(api.gears.color(api.beautiful.fg_normal), 1)
|
||||||
local label_size = api.dpi(30)
|
local label_size = api.dpi(30)
|
||||||
local border_color = with_alpha(api.gears.color(api.beautiful.border_focus), 0.75)
|
local border_color = with_alpha(api.gears.color(api.beautiful.border_focus), 0.75)
|
||||||
|
@ -87,9 +88,8 @@ local function start(c)
|
||||||
|
|
||||||
if i == c.machi_region and tablist ~= nil then
|
if i == c.machi_region and tablist ~= nil then
|
||||||
|
|
||||||
cr:select_font_face(label_font_family, "normal", "normal")
|
local pl = api.lgi.Pango.Layout.create(cr)
|
||||||
cr:set_font_face(cr:get_font_face())
|
pl:set_font_description(tablist_font_desc)
|
||||||
cr:set_font_size(tablist_font_size)
|
|
||||||
|
|
||||||
local vpadding = api.dpi(10)
|
local vpadding = api.dpi(10)
|
||||||
local height = vpadding
|
local height = vpadding
|
||||||
|
@ -97,7 +97,12 @@ local function start(c)
|
||||||
|
|
||||||
for index, tc in ipairs(tablist) do
|
for index, tc in ipairs(tablist) do
|
||||||
local label = tc.name
|
local label = tc.name
|
||||||
local ext = cr:text_extents(label)
|
pl:set_text(label)
|
||||||
|
local w, h
|
||||||
|
w, h = pl:get_size()
|
||||||
|
w = w / api.lgi.Pango.SCALE
|
||||||
|
h = h / api.lgi.Pango.SCALE
|
||||||
|
local ext = { width = w, height = h, x_bearing = 0, y_bearing = 0 }
|
||||||
exts[#exts + 1] = ext
|
exts[#exts + 1] = ext
|
||||||
height = height + ext.height + vpadding
|
height = height + ext.height + vpadding
|
||||||
end
|
end
|
||||||
|
@ -117,10 +122,10 @@ local function start(c)
|
||||||
cr:set_source(fill_color_hl)
|
cr:set_source(fill_color_hl)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
end
|
end
|
||||||
|
pl:set_text(label)
|
||||||
cr:move_to(x_offset - ext.width / 2 - ext.x_bearing, y_offset - ext.y_bearing)
|
cr:move_to(x_offset - ext.width / 2 - ext.x_bearing, y_offset - ext.y_bearing)
|
||||||
cr:text_path(label)
|
|
||||||
cr:set_source(font_color)
|
cr:set_source(font_color)
|
||||||
cr:fill()
|
cr:show_layout(pl)
|
||||||
|
|
||||||
y_offset = y_offset + ext.height + vpadding
|
y_offset = y_offset + ext.height + vpadding
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue