Difference between revisions of "LOADFONT"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
(Created page with 'The '''_LOADFONT''' function returns a font handle for a TrueType font (.TTF). * You need to know that if you are in a text mode (such as SCREEN 0, the default). * SCREEN 0 wil…')
 
imported>Clippy
Line 20: Line 20:
:SCREEN i&
:SCREEN i&
:COLOR &HC0FFFF00,&H200000FF
:COLOR &HC0FFFF00,&H200000FF
:f&=_LOADFONT("x:\times.ttf",25)
:f& =_LOADFONT("x:\times.ttf",25)
:PRINT "Hello!"
:PRINT "Hello!"


Line 30: Line 30:


:FUNC _LOADFONT    new_font_handle = _LOADFONT(ttf_filename$,height[,"BOLD,ITALIC,UNDERLINE,DONTBLEND,MONOSPACE"])
:FUNC _LOADFONT    new_font_handle = _LOADFONT(ttf_filename$,height[,"BOLD,ITALIC,UNDERLINE,DONTBLEND,MONOSPACE"])
:SUB  _FREEFONT   _FREEFONT font_handle
:SUB  [[_FREEFONT]] _FREEFONT font_handle
:SUB  _FONT       _FONT font_handle[,image_handle]
:SUB  [[_FONT]] _FONT font_handle[,image_handle]
:FUNC _FONT        font_handle=_FONT[(image_handle)]
:FUNC _FONT        font_handle =_FONT[(image_handle)]
:SUB  _PRINTSTRING _PRINTSTRING(x,y),text_to_print$[,image_handle]
:SUB  [[_PRINTSTRING]] _PRINTSTRING(x,y),text_to_print$[,image_handle]
:FUNC _PRINTWIDTH width_in_pixels=_PRINTWIDTH(text_to_print$[,image_handle])
:FUNC [[_PRINTWIDTH]] width_in_pixels = _PRINTWIDTH(text_to_print$[,image_handle])
:SUB  _PRINTMODE   _PRINTMODE _FILLBACKGROUND/_KEEPBACKGROUND/_ONLYBACKGROUND [,image_handle]
:SUB  [[_PRINTMODE]] _PRINTMODE _FILLBACKGROUND/_KEEPBACKGROUND/_ONLYBACKGROUND [,image_handle]
:FUNC _PRINTMODE   1 keepbackground/2 onlybackground/3 fillbackground =_PRINTMODE[(image_handle)]
:FUNC [[_PRINTMODE]] 1 keepbackground/2 onlybackground/3 fillbackground =_PRINTMODE[(image_handle)]
:FUNC _FONTHEIGHT character_height_in_pixels=_FONTHEIGHT[(font_handle)]
:FUNC [[_FONTHEIGHT]] character_height_in_pixels = _FONTHEIGHT[(font_handle)]
:FUNC _FONTWIDTH   character_width_in_pixels=_FONTWIDTH[(font_handle)]
:FUNC [[_FONTWIDTH]] character_width_in_pixels = _FONTWIDTH[(font_handle)]

Revision as of 20:29, 4 September 2009

The _LOADFONT function returns a font handle for a TrueType font (.TTF).


  • You need to know that if you are in a text mode (such as SCREEN 0, the default).
  • SCREEN 0 will only be able to use mono-spaced (fixed width) fonts.

Example:

f& =_LOADFONT("x:\cour.ttf",30,"monospace,italic,bold,underline")
_FONT f&
PRINT "Hello!"

Note: 30 means each row of text (including vertical spacing) will be exactly 30 pixels high

  • In a 32-bit graphics mode you can alpha blend onto the background:

Example:

i& =_NEWIMAGE(800,600,32)
SCREEN i&
COLOR &HC0FFFF00,&H200000FF
f& =_LOADFONT("x:\times.ttf",25)
PRINT "Hello!"
  • You can load a fixed width font file without using the "monospace" option and it will be treated as variable width. This can be useful because LOCATE treats the horizontal position as an offset in pixels for variable width fonts.


Using Fonts:

FUNC _LOADFONT new_font_handle = _LOADFONT(ttf_filename$,height[,"BOLD,ITALIC,UNDERLINE,DONTBLEND,MONOSPACE"])
SUB _FREEFONT _FREEFONT font_handle
SUB _FONT _FONT font_handle[,image_handle]
FUNC _FONT font_handle =_FONT[(image_handle)]
SUB _PRINTSTRING _PRINTSTRING(x,y),text_to_print$[,image_handle]
FUNC _PRINTWIDTH width_in_pixels = _PRINTWIDTH(text_to_print$[,image_handle])
SUB _PRINTMODE _PRINTMODE _FILLBACKGROUND/_KEEPBACKGROUND/_ONLYBACKGROUND [,image_handle]
FUNC _PRINTMODE 1 keepbackground/2 onlybackground/3 fillbackground =_PRINTMODE[(image_handle)]
FUNC _FONTHEIGHT character_height_in_pixels = _FONTHEIGHT[(font_handle)]
FUNC _FONTWIDTH character_width_in_pixels = _FONTWIDTH[(font_handle)]