LoadFont ( fontname$[,height][,bold][,italic][,underline] )

Parameters

fontname$ - name of the typeface to load, for example "Arial"

height (optional) - character height in pixels; 12 (default)

bold (optional) - True for the bold weight; 0 (default)

italic (optional) - True for the italic style; 0 (default)

underline (optional) - True for underlined text; 0 (default)

Description

Loads a font and returns a handle to it.

The name is a Windows typeface name, the same one you would pick in a word processor - "Arial", "Courier New", "Verdana". Windows matches as closely as it can, so a name it does not recognise gets you a substitute rather than a failure. Make it a font you can rely on being installed, or ship the file and install it yourself, if the exact look matters.

The height is in pixels, not points, and it describes the character cell - the space a line of text occupies - so the letters themselves come out slightly smaller than the number you ask for. Windows may not have that exact size available and will pick the nearest; call FontHeight after SetFont to find out what you actually got, and lay your text out from that rather than from the number you requested.

Loading a font does not start using it. Pass the handle to SetFont to make it the current font, after which Text, Print and Write use it. A game typically loads two or three fonts at startup - a big one for the title, a small one for the HUD - and switches between them with SetFont.

Each combination of style flags is a separate font handle, so bold and regular Arial means two LoadFont calls. Free them with FreeFont when you are done.

See also: SetFont, FreeFont, FontHeight, FontWidth, StringWidth, Text.

Example

; LoadFont Example
; ----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; LoadFont(fontname$,height,bold,italic,underlined) returns a font handle
title_plain=LoadFont("Arial",48)
title_bold=LoadFont("Arial",48,True)
title_italic=LoadFont("Arial",48,False,True)
title_under=LoadFont("Arial",48,False,False,True)

; A small font for the info overlay
info_font=LoadFont("Arial",14)

title_font=title_plain
desc$="LoadFont(Arial,48) - plain"

While Not KeyDown(1)

    ; Keys 1-4 pick which loaded font draws the title
    If KeyHit(2) Then
        title_font=title_plain
        desc$="LoadFont(Arial,48) - plain"
    End If
    If KeyHit(3) Then
        title_font=title_bold
        desc$="LoadFont(Arial,48,True) - bold"
    End If
    If KeyHit(4) Then
        title_font=title_italic
        desc$="LoadFont(Arial,48,False,True) - italic"
    End If
    If KeyHit(5) Then
        title_font=title_under
        desc$="LoadFont(Arial,48,False,False,True) - underlined"
    End If

    Cls

    ; Draw the title screen with the chosen font, pulsing gently
    pulse=155+Sin(MilliSecs()/4.0)*100
    SetFont title_font
    Color pulse,pulse,255
    Text 320,180,"STAR PATROL",True,True
    Color 255,255,255
    Text 320,250,"press start",True,True

    SetFont info_font
    Color 255,255,255
    Text 0,0,"1-4: choose font style   Esc: exit"
    Text 0,20,desc$

    Flip

Wend

; Release the font handles when we are done with them
FreeFont title_plain
FreeFont title_bold
FreeFont title_italic
FreeFont title_under
FreeFont info_font

End

Index