Fixed glyph cropping on sub-pixel positioning of text

Added 1 pixel padding for glyph uv's  and increased glyph quads boundaries by 1 pixel so the glyphs aren't cropped when text is being scrolled with sub-pixel increments
This commit is contained in:
Radek Dutkiewicz 2018-06-11 13:00:21 +01:00 committed by Lukas Dürrenberger
parent dc0dfd601a
commit f4f7ef0d70
2 changed files with 11 additions and 8 deletions

View File

@ -727,6 +727,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height)
// Make the texture 2 times bigger // Make the texture 2 times bigger
Texture newTexture; Texture newTexture;
newTexture.create(textureWidth * 2, textureHeight * 2); newTexture.create(textureWidth * 2, textureHeight * 2);
newTexture.setSmooth(true);
newTexture.update(page.texture); newTexture.update(page.texture);
page.texture.swap(newTexture); page.texture.swap(newTexture);
} }

View File

@ -50,15 +50,17 @@ namespace
// Add a glyph quad to the vertex array // Add a glyph quad to the vertex array
void addGlyphQuad(sf::VertexArray& vertices, sf::Vector2f position, const sf::Color& color, const sf::Glyph& glyph, float italicShear, float outlineThickness = 0) void addGlyphQuad(sf::VertexArray& vertices, sf::Vector2f position, const sf::Color& color, const sf::Glyph& glyph, float italicShear, float outlineThickness = 0)
{ {
float left = glyph.bounds.left; float padding = 1.0;
float top = glyph.bounds.top;
float right = glyph.bounds.left + glyph.bounds.width;
float bottom = glyph.bounds.top + glyph.bounds.height;
float u1 = static_cast<float>(glyph.textureRect.left); float left = glyph.bounds.left - padding;
float v1 = static_cast<float>(glyph.textureRect.top); float top = glyph.bounds.top - padding;
float u2 = static_cast<float>(glyph.textureRect.left + glyph.textureRect.width); float right = glyph.bounds.left + glyph.bounds.width + padding;
float v2 = static_cast<float>(glyph.textureRect.top + glyph.textureRect.height); float bottom = glyph.bounds.top + glyph.bounds.height + padding;
float u1 = static_cast<float>(glyph.textureRect.left) - padding;
float v1 = static_cast<float>(glyph.textureRect.top) - padding;
float u2 = static_cast<float>(glyph.textureRect.left + glyph.textureRect.width) + padding;
float v2 = static_cast<float>(glyph.textureRect.top + glyph.textureRect.height) + padding;
vertices.append(sf::Vertex(sf::Vector2f(position.x + left - italicShear * top - outlineThickness, position.y + top - outlineThickness), color, sf::Vector2f(u1, v1))); vertices.append(sf::Vertex(sf::Vector2f(position.x + left - italicShear * top - outlineThickness, position.y + top - outlineThickness), color, sf::Vector2f(u1, v1)));
vertices.append(sf::Vertex(sf::Vector2f(position.x + right - italicShear * top - outlineThickness, position.y + top - outlineThickness), color, sf::Vector2f(u2, v1))); vertices.append(sf::Vertex(sf::Vector2f(position.x + right - italicShear * top - outlineThickness, position.y + top - outlineThickness), color, sf::Vector2f(u2, v1)));