Difference between revisions of "LOADFONT"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 10: Line 10:
{{PageDescription}}
{{PageDescription}}
* ''font_handle'' is the handle you want to use to represent the font.
* ''font_handle'' is the handle you want to use to represent the font.
* ''TTF_filename$'' is the filename of the '''truetype''' only font. Can include the path to the font file.
* ''TTF_filename$'' is the filename of the '''truetype''' only font. Can include the path to the font file. Windows users should find TTF fonts in the C:\WINDOWS\FONTS folder.
* ''Height'' is the height of the font.
* ''Height'' is the height of the font. Font heights can be found using [[_FONTHEIGHT]].
* ''Style'' parameter(s), if any are literal(inside of quotes) or variable text parameters.
* ''Style'' parameter(s), if any are literal(inside of quotes) or variable text parameters. Monospace has limited font selections.
* You can pass different styles with different [[STRING]] variables.
* You can pass different styles with different [[STRING]] variables.


Line 19: Line 19:
{{PageExamples}}
{{PageExamples}}


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


{{CodeStart}}
{{CodeStart}}


font$ = "C:\WINDOWS\Fonts\cour.ttf"  
font$ = "C:\WINDOWS\Fonts\cour.ttf"         'TTF file in Windows
style$ = "monospace, italic, bold"
style$ = "monospace, italic, bold"         'font style
f& ={{Cl|_LOADFONT}}(font$, 30, style$)
f& ={{Cl|_LOADFONT}}(font$, 30, style$)
{{Cl|_FONT}} f&
{{Cl|_FONT}} f&
Line 35: Line 35:


{{OutputEnd}}
{{OutputEnd}}
''Note:'' 30 means each row of text (including vertical spacing) will be exactly 30 pixels high. This may make the program screen larger.


* In a 32-bit graphics mode you can alpha blend onto the background:
''Note:'' 30 means each row of text (including vertical spacing) will be exactly 30 pixels high. This may make some program screens larger.
 
''Example 2:'' In a 32-bit graphics mode you can alpha blend onto the background:


{{CodeStart}}
{{CodeStart}}
Line 44: Line 45:
{{Cl|SCREEN (statement)|SCREEN}} i&
{{Cl|SCREEN (statement)|SCREEN}} i&
{{Cl|COLOR}} &HC0FFFF00,&H200000FF
{{Cl|COLOR}} &HC0FFFF00,&H200000FF
f& ={{Cl|_LOADFONT}}("x:\times.ttf",25)
f& ={{Cl|_LOADFONT}}("C:\Windows\Fonts\times.ttf", 25) 'normal style
{{Cl|PRINT}} "Hello!"
{{Cl|PRINT}} "Hello!"



Revision as of 08:31, 7 July 2010

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


Syntax

handle& = _LOADFONT (ttf_filename$, height[, "BOLD|, ITALIC|, UNDERLINE|, DONTBLEND|, MONOSPACE"])



Description

  • font_handle is the handle you want to use to represent the font.
  • TTF_filename$ is the filename of the truetype only font. Can include the path to the font file. Windows users should find TTF fonts in the C:\WINDOWS\FONTS folder.
  • Height is the height of the font. Font heights can be found using _FONTHEIGHT.
  • Style parameter(s), if any are literal(inside of quotes) or variable text parameters. Monospace has limited font selections.
  • You can pass different styles with different STRING variables.


Examples

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

font$ = "C:\WINDOWS\Fonts\cour.ttf" 'TTF file in Windows style$ = "monospace, italic, bold" 'font style f& =_LOADFONT(font$, 30, style$) _FONT f& PRINT "Hello!"

Hello!

Note: 30 means each row of text (including vertical spacing) will be exactly 30 pixels high. This may make some program screens larger.

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

i& =_NEWIMAGE(800,600,32) SCREEN i& COLOR &HC0FFFF00,&H200000FF f& =_LOADFONT("C:\Windows\Fonts\times.ttf", 25) 'normal style PRINT "Hello!"

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.


QB64 Font SUBs and Functions:

SUB _FREEFONT font_handle
SUB _FONT font_handle[,image_handle]
FUNC _FONT (function) font_handle = _FONT[(image_handle)]
SUB _PRINTSTRING (x,y), text_to_print$[,image_handle]
FUNC _PRINTWIDTH width_in_pixels = _PRINTWIDTH(text_to_print$[,image_handle])
SUB _PRINTMODE _FILLBACKGROUND/_KEEPBACKGROUND/_ONLYBACKGROUND[,image_handle]
FUNC _PRINTMODE (function) 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)]




Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page