From f4f7ef0d705ba3eb4f1711cc5b556ae3ed7df748 Mon Sep 17 00:00:00 2001 From: Radek Dutkiewicz Date: Mon, 11 Jun 2018 13:00:21 +0100 Subject: [PATCH] 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 --- src/SFML/Graphics/Font.cpp | 1 + src/SFML/Graphics/Text.cpp | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index b6f5c604c..cafba5ba7 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -727,6 +727,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) // Make the texture 2 times bigger Texture newTexture; newTexture.create(textureWidth * 2, textureHeight * 2); + newTexture.setSmooth(true); newTexture.update(page.texture); page.texture.swap(newTexture); } diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index fae7d9ac0..66875513c 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -50,15 +50,17 @@ namespace // 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) { - float left = glyph.bounds.left; - float top = glyph.bounds.top; - float right = glyph.bounds.left + glyph.bounds.width; - float bottom = glyph.bounds.top + glyph.bounds.height; + float padding = 1.0; - float u1 = static_cast(glyph.textureRect.left); - float v1 = static_cast(glyph.textureRect.top); - float u2 = static_cast(glyph.textureRect.left + glyph.textureRect.width); - float v2 = static_cast(glyph.textureRect.top + glyph.textureRect.height); + float left = glyph.bounds.left - padding; + float top = glyph.bounds.top - padding; + float right = glyph.bounds.left + glyph.bounds.width + padding; + float bottom = glyph.bounds.top + glyph.bounds.height + padding; + + float u1 = static_cast(glyph.textureRect.left) - padding; + float v1 = static_cast(glyph.textureRect.top) - padding; + float u2 = static_cast(glyph.textureRect.left + glyph.textureRect.width) + padding; + float v2 = static_cast(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 + right - italicShear * top - outlineThickness, position.y + top - outlineThickness), color, sf::Vector2f(u2, v1)));