Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mistake in the 'Text and fonts' tutorial  (Read 5257 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Mistake in the 'Text and fonts' tutorial
« on: November 19, 2013, 02:36:03 pm »
I just ran into a small mistake in the 'Text and fonts' tutorial, which seems to be indicating that the font class has afunction called getLineHeight.

Quote from: Text and fonts - Tutorial
Finally, you can get some other metrics of the font, such as the line height or the kerning (always for a certain character size):

int lineHeight = font.getLineHeight(characterSize);

int kerning = font.getKerning(character1, character2, characterSize);

Looking at the documentation and the header file, I can't seem to find such a function. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Mistake in the 'Text and fonts' tutorial
« Reply #1 on: November 19, 2013, 02:46:30 pm »
Yep, it's getLineSpacing. I'll correct it ASAP, thanks.
Laurent Gomila - SFML developer

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Mistake in the 'Text and fonts' tutorial
« Reply #2 on: November 19, 2013, 04:28:54 pm »
I read this recently, too, and I think it would be nice if you could add one or two sentences to describe what kerning is (because its a foreign concept for most people as they dont create font files themself).
And please clarify from which points inside the characters it is measured and if the numbers is the distance between the characters or if its how much the real position of the second character differs from the "normal" position (of a square box character) without it.

Maybe you could hint of the possibility to squeeze the textlength into a given space you have available using shape scale function (from just reading about sf::Text I thought its not possible and still did not try, as I have it working some other way).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Mistake in the 'Text and fonts' tutorial
« Reply #3 on: November 19, 2013, 04:37:53 pm »
You don't have to know what kerning is to draw text with SFML. If you need to use it, it means that you're writing your own text layout algorithm with sf::Font directly, which is advanced stuff, and thus I assume that you know (or can search on your own) what those technical properties mean and how to interpret them.

Explaining this very specific stuff in the tutorial would just confuse people who don't care. And since it's not specific to SFML, you can find good sources of information elsewhere. Other possible sources of information are the sf::Text source code and the FreeType documentation (they have a very good page about font metrics).
Laurent Gomila - SFML developer

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Mistake in the 'Text and fonts' tutorial
« Reply #4 on: November 19, 2013, 04:44:45 pm »
Yes, luckily I did know, but 5 more words about the second point would be nice at least, as its a number sfml gives and every other number in the library is clearly documented.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Mistake in the 'Text and fonts' tutorial
« Reply #5 on: November 19, 2013, 04:54:30 pm »
Which number are you referring to?
Laurent Gomila - SFML developer

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Mistake in the 'Text and fonts' tutorial
« Reply #6 on: November 20, 2013, 01:34:46 am »
End of the tutorial http://sfml-dev.org/tutorials/2.1/graphics-text.php:
Quote
The sf::Glyph structure contains three members:

- textureRect is the texture coordinates of the glyph within the texture
- bounds is the bounding rectangle of the glyph, which helps to position it relatively to the base line of the text
- advance is the horizontal offset to apply to get the start position of the next glyph in the text

Above it absolutely clear on first read, like everything in the tutorial/docs, except one thing:
Quote
Finally, you can get some other metrics of the font, such as the line spacing or the kerning (always for a certain character size):
Below you see 2 function calls, but no hint of the use. It may as well not be there, but it would be nicer to improve it a bit:
I saw in the class list its 2 things measured in points, but not in tutorial?
I know kerning is a reduction in the spacing depending on two neighboring letters to make it look uniformly on differently sized/shaped letters, but normal people dont and would be happy about telling just that little bit (and its weird the tutorial got no info when the method list got some). Still I can only guess how the number of SFML applies. So is it a positive number you need to subtract or already a negative number you can directly add? The words in () let me guess its after adding the advance from above even though it probably just tells about needing to put the correct height as a parameter, but on a tutorial you shouldnt need to guess and even in the method list its ambiguous.
Btw., is line spacing the difference between the upper border of two lines of text or the difference between the lower border of one line and upper border of next line?

 

anything