oh my god... how to calculate text length?

BlitzMax Forums/BlitzMax Beginners Area/oh my god... how to calculate text length?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

How can i calculate text length in __pixel__? I use Arial-font. I can't see how to do this??? Each char have different image width...

(copy arial.ttf to your prog directory)



Graphics 640,480,0

Local font:TImageFont=LoadImageFont("Arial.ttf",13)
If Not font End

SetImageFont font
SetBlend ALPHABLEND

SetClsColor 255,255,255
Cls

SetColor 0,0,0
DrawText "1234567890",10,10

gettextwidth("123",font)

Flip
WaitKey

Function gettextwidth(text$,font:TImageFont)
For i=0 To text.length-1
Local c=text[i]
Local glyph:TImageGlyph=font._glyphs[c]
Local image:TImage=glyph._image

Print glyph._x+","+glyph._y+","+glyph._w+","+glyph._h+","+glyph._advance '??????? or what
Next
EndFunction