Implement FreeTypeFont::hasCodePoint()

This commit is contained in:
David Capello 2017-03-07 13:01:42 -03:00
parent 7cd92041b3
commit 556dcceaff
3 changed files with 17 additions and 2 deletions

View File

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

View File

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

View File

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