Skip to content

Text: Add ability to round lineSpacing and letterSpacing to the closest integer #3595

@Lorenzooone

Description

@Lorenzooone

Prerequisite Checklist

Describe your feature request here

Right now, if you use sf::Text::setLineSpacing(float) and sf::Text::setLetterSpacing(float),
you risk getting blurry images.

As an example: above text with setLetterSpacing(1.1), below text with setLetterSpacing(1.0).
Image

Image

I propose two functions, setLineSpacingRounding(bool) and setLetterSpacingRounding(bool) (the getters as well, if needed...?) to ensure that the lineSpacing and letterSpacing variables resulting from using the values set by "setLineSpacing and setLetterSpacing" are integers, to prevent the blur you can see here.

Link to the relevant code:

const float letterSpacing = (whitespaceWidth / 3.0f) * (m_letterSpacingFactor - 1.0f);

Use Cases

Preventing blurry text.

API Example

text_line->setLetterSpacing(1.1);
// Prevent horizontal blurring
text_line->setLetterSpacingRounding(true);


text_paragraph->setLetterSpacing(1.1);
text_paragraph->setLineSpacing(1.1);
// Prevent horizontal blurring
text_paragraph->setLetterSpacingRounding(true);
// Prevent vertical blurring
text_paragraph->setLineSpacingRounding(true);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions