Skip to content

Commit

Permalink
Merge pull request #576 from binary1248/text_fix
Browse files Browse the repository at this point in the history
Fix text being rendered with a vertical offset when the font's ascent doesn't match it's size.
  • Loading branch information
LaurentGomila committed Apr 22, 2014
2 parents 7f0f89b + 6469f35 commit ee336a3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SFML/Graphics/Font.cpp
Expand Up @@ -473,6 +473,11 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c

int width = bitmap.width;
int height = bitmap.rows;
int ascender = face->size->metrics.ascender >> 6;

// Offset to make up for empty space between ascender and virtual top of the typeface
int offset = characterSize - ascender;

if ((width > 0) && (height > 0))
{
// Leave a small padding around characters, so that filtering doesn't
Expand All @@ -487,7 +492,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c

// Compute the glyph's bounding box
glyph.bounds.left = bitmapGlyph->left - padding;
glyph.bounds.top = -bitmapGlyph->top - padding;
glyph.bounds.top = -bitmapGlyph->top - padding - offset;
glyph.bounds.width = width + 2 * padding;
glyph.bounds.height = height + 2 * padding;

Expand Down

0 comments on commit ee336a3

Please sign in to comment.