From bbfa6428aa4a9d0f68576f43350bcbc6ac16fccd Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 16 Jun 2013 15:33:50 +0800 Subject: [PATCH] add glyph fallbacks if glyph is not found in specified fontface, fallback fonts are checked on by one until a glyph is found. --- frontend/ui/font.lua | 5 +++++ frontend/ui/rendertext.lua | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/frontend/ui/font.lua b/frontend/ui/font.lua index 836508e2a..42d57a734 100644 --- a/frontend/ui/font.lua +++ b/frontend/ui/font.lua @@ -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", diff --git a/frontend/ui/rendertext.lua b/frontend/ui/rendertext.lua index 8f9ff9e4c..bc49dd254 100644 --- a/frontend/ui/rendertext.lua +++ b/frontend/ui/rendertext.lua @@ -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