mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user