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

Author Topic: Getting height of space under base in font  (Read 2710 times)

0 Members and 2 Guests are viewing this topic.

Beta_Ravener

  • Jr. Member
  • **
  • Posts: 51
    • ICQ Messenger - 271426715
    • View Profile
Getting height of space under base in font
« on: September 19, 2011, 12:17:21 am »
I'm building my own render procedure for text rendering. I'm still using sf::Text, sf::Font etc., what I do is creating tags on various position that specify for example color, font or character size. While rendering I cut the string on rows and rows on uniform blocks - characters that have position inside uniform block share the same set of tags so I can set those to sf::Text and render them easily, then move my render position and repeat. However I encountered a little problem. I work with sf::Font::GetLineSpacing for determining row height and as there can be various sizes inside one row, I get maximum height and set that as main one and when rendering smaller than this one, I decrement the value so it sits on the same line. However this isn't really true because when I enlarge character size I get height steps. This is because I don't really set characters like "aAbB" on same line but those like ",,||". It can be understood after realizing what sf::Font::GetLineSpacing returns. My problem is now determining that piece of space is under the "alphabetical row" - the line on which characters lie. I tried this by retrieving Glyph and working whit Bound, but those value seems to be different from what i expected, because they don't grow with character size as fast as I'd expect and those steps can be still seen. Thanks for help

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting height of space under base in font
« Reply #1 on: September 19, 2011, 08:07:02 am »
Sorry, I've read your message several times but I don't understand what you want :?

Maybe a picture of the problem would help.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Getting height of space under base in font
« Reply #2 on: September 19, 2011, 02:06:10 pm »
What I'm getting out of your text is that you want to create some kind of rich-text drawer? My guess would be to create your own class for this, as I doubt sf::Text would cut it. Maybe you could still use sf::Font, sf::Glyph etc.

Good luck anyhow!

Beta_Ravener

  • Jr. Member
  • **
  • Posts: 51
    • ICQ Messenger - 271426715
    • View Profile
Getting height of space under base in font
« Reply #3 on: September 19, 2011, 03:18:38 pm »
Haikarainen got it right. In fact I'm building UI specialy for SFML where no conversions are needed, it works with native SFML classes and is also class oriented. This post is related to my rich edit, and I was already thinking about rebuilding whole rendering procedure but first I'd like to ask here so I don't have to rebuild quite a lot of code. For Laurent I'm including image of what happens when I introduce character size tag to my string.



That cursor there just didn't get updated that's why it's so small, but you can see there what I mean by word "step". The character size of 70 have that under base height almost as big as is the character size of 20 full height. I'd like the bottoms of those "aaaaaa" on the one same line, but I fail to find that information about under base (base is that line on which "a" sits) height anywhere. It can be possible that sfml don't even track that info because it's quite useless other than my case, but there must be way to retrieve it from font.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting height of space under base in font
« Reply #4 on: September 19, 2011, 03:47:13 pm »
Ok I see, you want to align your characters on the same base line, regardless their size.

It's easy: subtract the character size (text.GetCharacterSize()) from the Y position of your text and they should all be aligned perfectly ;)
Laurent Gomila - SFML developer

Beta_Ravener

  • Jr. Member
  • **
  • Posts: 51
    • ICQ Messenger - 271426715
    • View Profile
Getting height of space under base in font
« Reply #5 on: September 19, 2011, 03:59:18 pm »
I was searching in source for sfml and I tracked using character size to point where it is passed for requesting font page. Well I don't know much about fonts and size pages, but will your solution work for different fonts also? for example if the last "a" would be Verdana(and not the Arial), would I get it aligned or not? I find it little strange that aligning would depend solely on character size because then all the fonts would be guaranteed to have bottom of for example "a" at the very same pixel. If I'm wrong please correct me.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting height of space under base in font
« Reply #6 on: September 19, 2011, 04:05:50 pm »
It should work with different fonts, yes.

It's not strange, it just means that fonts and SFML are correctly implemented ;)
Laurent Gomila - SFML developer

Beta_Ravener

  • Jr. Member
  • **
  • Posts: 51
    • ICQ Messenger - 271426715
    • View Profile
Getting height of space under base in font
« Reply #7 on: September 19, 2011, 04:18:50 pm »
Well man you're magician. Works like charm even with those strange handwritten fonts :D Things and people like this makes the life so easy  :wink:

 

anything