Skip to content
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

Closed
wants to merge 5 commits into from
Closed

Letter spacing bugfix #1366

wants to merge 5 commits into from

Conversation

oomek
Copy link
Contributor

@oomek oomek commented Feb 6, 2018

Ties letter spacing factors to the font size.

Ties letter spacing factors to the font size.
@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.5.0 via automation Feb 6, 2018
@eXpl0it3r eXpl0it3r added this to the 2.5 milestone Feb 6, 2018
@eXpl0it3r eXpl0it3r moved this from Discussion to Review & Testing in SFML 2.5.0 Feb 6, 2018
Copy link
Member

@LaurentGomila LaurentGomila left a 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.

@@ -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 );
Copy link
Member

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.).

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;
Copy link
Contributor

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

@Foaly
Copy link
Contributor

Foaly commented Feb 6, 2018

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.

@oomek
Copy link
Contributor Author

oomek commented Feb 6, 2018

I’m at the hospital until evening UK time. Sorry for lagging.

@Foaly
Copy link
Contributor

Foaly commented Feb 6, 2018

No worries! Take your time. Health comes first :)

Fixed letter spacing factors (now tied to the font size)
@oomek
Copy link
Contributor Author

oomek commented Feb 6, 2018

I'm a Github noob, as you have probably noticed. Is it acceptable now?

@oomek
Copy link
Contributor Author

oomek commented Feb 6, 2018

@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.

@LaurentGomila
Copy link
Member

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
/// 

@LaurentGomila
Copy link
Member

LaurentGomila commented Feb 7, 2018

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 😃

@oomek
Copy link
Contributor Author

oomek commented Feb 7, 2018

Thank you for being patient. It's my first pull request done in git. I used the website to publish my code before.

@oomek
Copy link
Contributor Author

oomek commented Feb 7, 2018

And besides, I'm not a native English speaker, so I chose the safest way :)

@Foaly
Copy link
Contributor

Foaly commented Feb 7, 2018

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
Copy link
Contributor

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.

Copy link
Member

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.

/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter name is: spacingFactor

@LaurentGomila
Copy link
Member

LaurentGomila commented Feb 7, 2018

wouldn't it be a better design to set the start of the additional factor at 0 intead of 1

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 ;)

@oomek
Copy link
Contributor Author

oomek commented Feb 7, 2018

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)

@Foaly
Copy link
Contributor

Foaly commented Feb 8, 2018

... use actual offset ...

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.

@oomek
Copy link
Contributor Author

oomek commented Feb 8, 2018

Soooo, could we finally close that chapter please? I’m having an impression that we are overthinking it a little bit.

@Foaly
Copy link
Contributor

Foaly commented Feb 8, 2018

If @LaurentGomila is fine with it, it's ok from my side.

@LaurentGomila
Copy link
Member

The point I wanted to add was that the factor affects that fixed spacing and not the "default" spacing.

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.

Soooo, could we finally close that chapter please? I’m having an impression that we are overthinking it a little bit.

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 @LaurentGomila is fine with it, it's ok from my side.

If the current code has been tested and still works as expected, I'm totally fine with it.

@eXpl0it3r eXpl0it3r changed the title Modification of Foaly's Commit Letter spacing bugfix Feb 10, 2018
@eXpl0it3r eXpl0it3r moved this from Review & Testing to Ready in SFML 2.5.0 Feb 11, 2018
@eXpl0it3r
Copy link
Member

Squashed and merged in deeb3a9

@eXpl0it3r eXpl0it3r closed this Feb 15, 2018
SFML 2.5.0 automation moved this from Ready to Merged / Superseded Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

4 participants