New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Letter spacing bugfix #1366
Letter spacing bugfix #1366
Conversation
Ties letter spacing factors to the font size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should be updated as well. We don't need to give too much technical detail, but users should at least know what kind of result to expect.
src/SFML/Graphics/Text.cpp
Outdated
@@ -317,7 +317,9 @@ Vector2f Text::findCharacterPos(std::size_t index) const | |||
|
|||
// Precompute the variables needed by the algorithm | |||
bool isBold = m_style & Bold; | |||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance * m_letterSpacingFactor; | |||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance; | |||
float letterSpacing = ( whitespaceWidth / 3.0 ) * ( m_letterSpacingFactor - 1.0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment: use floats, not doubles (3.f, 1.f, etc.).
src/SFML/Graphics/Text.cpp
Outdated
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance * m_letterSpacingFactor; | ||
float whitespaceWidth = m_font->getGlyph(L' ', m_characterSize, isBold).advance; | ||
float letterSpacing = ( whitespaceWidth / 3.0 ) * ( m_letterSpacingFactor - 1.0 ); | ||
whitespaceWidth += letterSpacing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor code style: the = should be aligned with the ones surrounding it
Great! Besides the documentation that Laurent mentioned I think the commit message should be changed to something more meaningful. Maybe: Fix letter spacing factors (now tied to the font size). Or something like that. |
I’m at the hospital until evening UK time. Sorry for lagging. |
No worries! Take your time. Health comes first :) |
Fixed letter spacing factors (now tied to the font size)
I'm a Github noob, as you have probably noticed. Is it acceptable now? |
@LaurentGomila I'm not sure what documentation are you referring to. if it's the comment block in the Text.hpp it's descriptive enough I think. |
I'd replace this /// This method enables you to set a factor to the spacing
/// between letters. (which is really really bad, but so as many other comments in SFML 😁 ) With something like this /// This factor doesn't directly apply to the existing
/// spacing between each character, it rather adds a fixed
/// space between them which is calculated from the font
/// metrics and the character size.
/// Note that factors below 1 (including negative numbers) bring
/// characters closer to each other
/// |
I didn't mean to replace the whole comment, only the part that I posted above. Please keep the indication of default value, and we can also keep the first sentence. And it's just an example that I wrote quickly, feel free to adapt/correct/complete it instead of just copy-pasting it 😃 |
Thank you for being patient. It's my first pull request done in git. I used the website to publish my code before. |
And besides, I'm not a native English speaker, so I chose the safest way :) |
I know this has the potential to blow up the discussion, but reading over this again, wouldn't it be a better design to set the start of the additional factor at 0 intead of 1. So it would be a factor in percent or negative percent instead of somewhat randomly starting for 1 as no additional offset. |
/// spacing between each character, it rather adds a fixed | ||
/// space between them which is calculated from the font | ||
/// metrics and the character size. | ||
/// Note that factors below 1 (including negative numbers) bring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this is not entirely correct I would say. My proposal:
/// This factor doesn't directly apply to the existing
/// spacing between each character. It rather uses a fixed
/// space which is calculated from the fonts whitespace
/// and the character size. This spacing is scaled by the
/// `spacingFactor` and added to the default spacing between
/// two characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not entirely correct
Which part is incorrect?
My proposal
Well, no need to describe all implementation details. Users don't need to know that.
include/SFML/Graphics/Text.hpp
Outdated
/// metrics and the character size. | ||
/// Note that factors below 1 (including negative numbers) bring | ||
/// characters closer to each other. | ||
/// By default the letter spacing factor is 1. | ||
/// | ||
/// \param spacing New letter spacing factor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter name is: spacingFactor
Since it's a factor, it makes sense to start at 1. And it remains consistent with the line spacing factor. And if one day we find a better algorithm that use actual factors, then I don't want to have to change the behaviour from the user point of view. If we go too far in the direction of "this is an offset, not a factor" we'll have to revert all that stuff to use actual offsets in public interface ;) |
Starting at 1.0 makes sense as going below 0.0 results in letters overlaping each other. We don’t need factoring in (-n,n) range but rather (0,n) |
You know that is the secret plan all along 😉 The point I wanted to add was that the factor affects that fixed spacing and not the "default" spacing. But yeah I guess it doesn't matter to much. |
Soooo, could we finally close that chapter please? I’m having an impression that we are overthinking it a little bit. |
If @LaurentGomila is fine with it, it's ok from my side. |
I think it is important, that's why I say it in my version of the comment. My point was: users need to know how it behaves, not how it is precisely calculated.
Proper documentation is not "overthinking". It's probably the most important thing, now that the technical issues have been sorted out. As long as the PR is not blocked in endless arguments, there's no hurry, let's not be afraid to discuss even the most minor details 😉
If the current code has been tested and still works as expected, I'm totally fine with it. |
Squashed and merged in deeb3a9 |
Ties letter spacing factors to the font size.