add glyph fallbacks

if glyph is not found in specified fontface, fallback fonts are checked
on by one until a glyph is found.
pull/124/head
chrox 11 years ago
parent 4c32e95358
commit bbfa6428aa

@ -31,6 +31,11 @@ Font = {
-- font for info messages
infofont = "droid/DroidSans.ttf",
},
fallbacks = {
[1] = "freefont/FreeSans.ttf",
[2] = "droid/DroidSans.ttf",
[3] = "droid/DroidSansFallback.ttf",
},
fontdir = os.getenv("FONTDIR") or "./fonts",

@ -22,6 +22,16 @@ function getGlyph(face, charcode, bgcolor, fgcolor)
return glyph[1]
end
local rendered_glyph = face.ftface:renderGlyph(charcode, bgcolor, fgcolor)
if face.ftface:checkGlyph(charcode) == 0 then
for index, font in pairs(Font.fallbacks) do
DEBUG("fallback to font", font)
local fb_face = Font:getFace(font, face.size)
if fb_face.ftface:checkGlyph(charcode) ~= 0 then
rendered_glyph = fb_face.ftface:renderGlyph(charcode, bgcolor, fgcolor)
break
end
end
end
if not rendered_glyph then
DEBUG("error rendering glyph (charcode=", charcode, ") for face", face)
return

Loading…
Cancel
Save