Ttf load

From Bennu Wiki
Jump to: navigation, search


Syntax

INT ttf_load ( <STRING filename> , <INT height> )

Description

Loads a TTF file as a font into memory.

Also called load_ttf().

Parameters

STRING filename - The filename of the TTF file that you wish to load (including extension and possible path).
INT height - The height in pixels of the to be created font, a size indication.

Returns

INT : FontID

-1 - Error: file does not exist; insufficient memory; failed to init freetype.dll; error while loading file; error creating new font.
0 - Invalid filename.
>0 - The FontID.

Errors

Insufficient memory - There is insufficient memory available. This error doesn't occur often.
Failed to init freetype.dll - There was an error initializing freetype.dll
Error loading file - There occurred an error while trying to load the file.
Error creating new font - There occurred an error while trying to create a new font.

Notes

This function gets a TrueType font and creates a new font with generated glyphs based on the recovered font in the standard characters set (ISO-8859-1). These glyphs are generated with two colours, being colour 0 (transparent) and the color last set by set_text_color(). The first one is the background colour and the last one is the colour of the characters self.

It's possible to save the loaded font as FNT with save_fnt(). This way the font can be reused on platforms not having mod_ttf. Note that a FNT file only has information about the font for one size, while a TTF file has information for any size.

The specified size is only an indication; some characters may be a little higher in fact.

Example

import "mod_key"
import "mod_proc"
import "mod_map"
import "mod_video"
import "mod_ttf"
import "mod_text"
global
  int id_ttfs[2];
Begin
    set_mode(320,240,16);
    id_ttfs[0] = load_ttf("resources/presdntn.ttf",48); 
    id_ttfs[1] = load_ttfaa("resources/presdntn.ttf",48,16,RGB(255,0,0),RGB(0,255,0)); 
    write(id_ttfs[0],20,10,0,"Hello");
    set_text_color(RGB(255,0,255));
    write(id_ttfs[0],150,10,0,"World");
    write(id_ttfs[1],20,100,0,"Bye");
    Repeat
        frame;
    Until(key(_ESC))

    unload_fnt(id_ttfs[0]);
    unload_fnt(id_ttfs[1]);

    exit();
End

Used in example: set_mode(),set_text_color(), rgb(), load_ttf(),load_ttfaa(), write(), key(), unload_fnt()


Mod_ttf
Globals None
Imported:
M7
Functions Ttfload()Ttfloadaa()Ttfloadx()