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

Author Topic: Kerning, Convert 'char' to 'sf::Uint32' etc.  (Read 1942 times)

0 Members and 1 Guest are viewing this topic.

Haikarainen

  • Guest
Kerning, Convert 'char' to 'sf::Uint32' etc.
« on: September 02, 2011, 08:38:13 pm »
Hello fellas! I'm trying to figure out how long a std::string is going to be in pixels with a specific font beforehand. Currently i have this:
Code: [Select]

int kerning = 0;
std::string s;
for(int i = 0; i < s.length();i++){
if(i > 0){
kerning+= Fonthere->GetKerning(sf::Uint32(s.at(i)), sf::Uint32(s.at(i-1)), TextHere.GetCharacterSize());
}
}


But kerning is still just 0. Am i doing the types around string and sf::Uint32 wrong?

edit; Code-example extremly shortened. s is initialized and has a long value. fonthere and texthere is used to draw stuff and works properly. etc.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Kerning, Convert 'char' to 'sf::Uint32' etc.
« Reply #1 on: September 02, 2011, 09:41:13 pm »
You should read the definition of kerning first ;)

The calculation of text bounding rect is not straight-forward, why not simply use sf::Text(s).GetRect()?
Laurent Gomila - SFML developer

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Kerning, Convert 'char' to 'sf::Uint32' etc.
« Reply #2 on: September 03, 2011, 07:15:09 am »
Quote
Am i doing the types around string and sf::Uint32 wrong?


Depends on how your string is encoded.

It looks like all you're doing is promoting it, which will work for ASCII but will fail for pretty much anything else.

Haikarainen

  • Guest
Kerning, Convert 'char' to 'sf::Uint32' etc.
« Reply #3 on: September 03, 2011, 07:45:49 am »
This thread can be closed :p was too tired to think last night and had coded for several hours straight. What i really wanted to achieve was string being linebreaked after a certain ammount of pixelspace, and I've achieved this now.

If someone have an awesome solution to this please reply, since mine isn't currently very optimal.

 

anything