add glyph fallbacks

if glyph is not found in specified fontface, fallback fonts are checked
on by one until a glyph is found.
This commit is contained in:
chrox
2013-06-16 15:33:50 +08:00
parent 4c32e95358
commit bbfa6428aa
2 changed files with 15 additions and 0 deletions

View File

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