TextHeight() problem!

BlitzMax Forums/BlitzMax Beginners Area/TextHeight() problem!

LuckyBargee(Posted 2011) [#1]
Hi All,

I'm trying to draw a text in the middle of recrectangles. For this task, I computed the width and height of the text and then drew a recrectangle like DrawRect(10,10,width,heigh) and put DrawText(word,10,10) on it.

I've faced a problem when I tried TextHeight() and used consola.ttf. The height had been computed wrongly! On the other hand, TextHeight() computed the text correctly for arial.ttf! But I need to use the consola.ttf.
What is wrong in my code, how to solve this problem? Help, pls!


SuperStrict

Const word:String="IT IS A TEXT..."

Global Font1:TImageFont=LoadImageFont("consola.ttf",70,SMOOTHFONT)	
If Font1 = Null Then Print("* ERROR: File consola.ttf not loaded!"); End

Global Font2:TImageFont=LoadImageFont("arial.ttf",70,SMOOTHFONT)	
If Font2 = Null Then Print("* ERROR: File arial.ttf not loaded!"); End

Global h:Short=0			' height of the font
Global w:Short=0			' width of the font

' --- CODE ---
 Graphics(800,600,16,60,GRAPHICS_BACKBUFFER)
 
 Repeat
 	Cls
'consola.ttf				
	SetImageFont(Font1)
 	h=TextHeight(word)
 	w=TextWidth(word)
	SetColor 0,0,255	
 	DrawRect(10,100,w,h)
	SetColor 255,255,255				
	DrawText(word,10,100) 

'arial.ttf
	SetImageFont(Font2)
 	h=TextHeight(word)
 	w=TextWidth(word)
	SetColor 0,0,255	
 	DrawRect(10,200,w,h)
	SetColor 255,255,255				
	DrawText(word,10,200) 

	Flip(1)

 Until KeyHit(KEY_ESCAPE) Or AppTerminate()




JazzieB(Posted 2011) [#2]
There's actually nothing wrong with your code or the FontHeight function. It's to do with the font itself. Seems like Consola has additional space beneath the text (can't remember the technical term for this). I think you will therefore need to make manual adjustment to the position of the text to make it central.