diff --git a/src/ft/face.h b/src/ft/face.h index cd4c9b0f6..631ca12c8 100644 --- a/src/ft/face.h +++ b/src/ft/face.h @@ -83,6 +83,15 @@ namespace ft { return int(m_face->descender * y_scale); } + bool hasCodePoint(int codepoint) const { + if (m_face) { + codepoint = FT_Get_Char_Index(m_face, codepoint); + return (codepoint != 0); + } + else + return false; + } + Cache& cache() { return m_cache; } protected: diff --git a/src/she/common/freetype_font.cpp b/src/she/common/freetype_font.cpp index f464987fd..574b9a5c5 100644 --- a/src/she/common/freetype_font.cpp +++ b/src/she/common/freetype_font.cpp @@ -20,7 +20,6 @@ namespace she { FreeTypeFont::FreeTypeFont(const char* filename, int height) : m_face(m_ft.open(filename)) { - ASSERT(m_face.isValid()); if (m_face.isValid()) m_face.setSize(height); } @@ -71,7 +70,7 @@ void FreeTypeFont::setAntialias(bool antialias) bool FreeTypeFont::hasCodePoint(int codepoint) const { - return true; // TODO + return m_face.hasCodePoint(codepoint); } FreeTypeFont* loadFreeTypeFont(const char* filename, int height) diff --git a/src/she/draw_text.cpp b/src/she/draw_text.cpp index d8bb1d8f9..eb10943cc 100644 --- a/src/she/draw_text.cpp +++ b/src/she/draw_text.cpp @@ -39,6 +39,13 @@ retry:; uint32_t code = *it; if (code && !font->hasCodePoint(code)) { Font* newFont = font->fallback(); + + // Search a valid fallback + while (newFont && !newFont->hasCodePoint(code)) + newFont = newFont->fallback(); + if (!newFont) + break; + y += font->height()/2 - newFont->height()/2; font = newFont;