float textWidth = 0;
Ogre::Font* f = dynamic_cast<Ogre::Font*>(Ogre::FontManager::getSingletonPtr()->getByName(fontName).get());
f->setTrueTypeSize(fontSize);
f->setTrueTypeResolution(72);
for(unsigned int i=0; i < text.length();i++) {
textWidth += (f->getGlyphAspectRatio(text[i]) * fontSize);
}
Which produces a semi-correct figure, shown in this image:
The white bar over each GUI element indicates the figure given off by the textWidth using the caption of each button as the text. If the code was correct, then the white bar would end exactly at the end of the text. But as you can see with shorter text the difference isn't noticeable but with that really long one it's really off.
So the question is; Is my code wrong or is this a bug in Eihort?
Many thanks in advance.
Last edited by betajaen on Mon Apr 23, 2007 10:39 am, edited 1 time in total.
By looking at the API ref from Dagon, it seems that the size of the font isn't the screen size, but the point size of the font used to generate the texture.
Instead, it looks to me that you should use the charHeight ( from TextAreaOverlayElement ) instead of the fontSize to calculate the text width.