Freetype: use actual metrics instead of bitmap data. also skip empty glyphs (whitespace chars/missing glyphs etc).
This commit is contained in:
parent
07417491cb
commit
151baaa8ff
1 changed files with 15 additions and 10 deletions
|
|
@ -105,19 +105,24 @@ Font::Glyph FreeTypeDriver::loadGlyph(unsigned int codepoint, Image& img)
|
|||
|
||||
FT_Error error = FT_Load_Char(m_face, codepoint, flags);
|
||||
if (!error) {
|
||||
|
||||
FT_GlyphSlot slot = m_face->glyph;
|
||||
FT_Glyph_Metrics& metrics = m_face->glyph->metrics;
|
||||
|
||||
if (slot->bitmap.buffer) {
|
||||
img.create(PixelFormat::PF_Alpha,
|
||||
slot->bitmap.width,
|
||||
slot->bitmap.rows,
|
||||
slot->bitmap.buffer);
|
||||
if (metrics.width > 0 && metrics.height > 0) {
|
||||
|
||||
FT_Bitmap& bmp = m_face->glyph->bitmap;
|
||||
|
||||
img.create(PixelFormat::PF_Alpha,
|
||||
bmp.width,
|
||||
bmp.rows,
|
||||
bmp.buffer);
|
||||
|
||||
glyph.offset.x = metrics.horiBearingX / (1 << 6);
|
||||
glyph.offset.y = metrics.horiBearingY / (1 << 6);
|
||||
glyph.size.x = metrics.width / (1 << 6);
|
||||
glyph.size.y = metrics.height / (1 << 6);
|
||||
}
|
||||
|
||||
glyph.offset = vec2b(slot->bitmap_left, slot->bitmap_top);
|
||||
glyph.size = vec2b(slot->bitmap.width, slot->bitmap.rows);
|
||||
glyph.advance = static_cast<unsigned char>(slot->advance.x >> 6);
|
||||
glyph.advance = static_cast<unsigned char>(metrics.horiAdvance >> 6);
|
||||
} else {
|
||||
log("FreeType: failed to load glyph for character code '%c'\n", codepoint);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue