FontHeight ( )
Parameters
| None. |
Description
|
Returns the height in pixels of the current font. This is the line height - the vertical space one row of text occupies - so it is the number to step by when you print a list. Drawing your lines at y, y+FontHeight(), y+FontHeight()*2 and so on keeps them evenly spaced whatever font is selected, which is much better than guessing a number that breaks the moment you change size. Use it for scrolling message logs, dialogue boxes, menus, and for working out how many lines fit in a panel: GraphicsHeight()/FontHeight() gives you a screenful. It reports the font actually loaded, which may not be exactly the height you asked LoadFont for - Windows picks the nearest available size. Measure rather than assume. It refers to whichever font SetFont selected last, so call it after switching, not before. StringHeight returns the same value for any string. See also: FontWidth, StringHeight, StringWidth, SetFont, LoadFont. |
Example
; FontHeight Example ; ------------------ Graphics 640,480,0,2 SetBuffer BackBuffer() ; A small font for the info overlay info_font=LoadFont("Arial",14) size=24 font=LoadFont("Arial",size) While Not KeyDown(1) ; [ / ] shrink or grow the font (reloaded at the new size) If KeyHit(27) And size<48 Then FreeFont font size=size+6 font=LoadFont("Arial",size) End If If KeyHit(26) And size>12 Then FreeFont font size=size-6 font=LoadFont("Arial",size) End If Cls SetFont font ; FontHeight returns the pixel height of the current font - the ; classic use is spacing lines of text so they can never overlap h=FontHeight() Color 255,255,255 For i=0 To 3 Text 80,140+i*h,"Line "+(i+1) Next ; Tick marks one FontHeight apart, right beside the lines Color 80,200,255 For i=0 To 4 Line 50,140+i*h,72,140+i*h Next SetFont info_font Color 255,255,255 Text 0,0,"[ / ] change font size Esc: exit" Text 0,20,"Arial "+size+"pt: FontHeight() = "+h+" pixels between lines" Flip Wend End
Index