Previous section To contents Next section

12.4 Image.Font

CLASS
Image.Font

DESCRIPTION

NOTE
Short technical documentation on a font file: This object adds the text-drawing and -creation capabilities of the Image module.

For simple usage, see write and load.

other methods: baseline, height, set_xspacing_scale, set_yspacing_scale, text_extents

struct file_head
{
unsigned INT32 cookie;   - 0x464f4e54
unsigned INT32 version;  - 1
unsigned INT32 chars;    - number of chars
unsigned INT32 height;   - height of font
unsigned INT32 baseline; - font baseline
unsigned INT32 o[1];     - position of char_head's
} *fh;
struct char_head
{
unsigned INT32 width;    - width of this character
unsigned INT32 spacing;  - spacing to next character
unsigned char data[1];   - pixmap data (1byte/pixel)
} *ch;

version 2:

On-disk syntax (everything in N.B.O), int is 4 bytes, a byte is 8 bits:

pos 0 int cookie = 'FONT'; or 0x464f4e54 4 int version = 2; 1 was the old version without the last four chars 8 int numchars; Always 256 in this version of the dump program 12 int height; in (whole) pixels 16 int baseline; in (whole) pixels 20 char direction; 1==right to left, 0 is left to right 21 char format; Font format 22 char colortablep; Colortable format 23 char kerningtablep; Kerning table format

24 int offsets[numchars]; pointers into the data, realative to &cookie. [colortable] [kerningtable]

At each offset:

0 int width; in pixels 4 int spacing; in 1/1000:th of a pixels 8 char data[]; Enough data to plot width * font->height pixels Please note that if width is 0, there is no data.

Font formats: id type 0 Raw 8bit data 1 RLE encoded data, char length, char data, 70% more compact than raw data 2 ZLib compressed data 60% more compact than RLE

Colortable types: 0 No colortable (the data is an alpha channel) 1 24bit RGB with alpha (index->color, 256*4 bytes, rgba) 2 8bit Greyscale with alpha (index->color, 256*2 bytes)

Kerningtable types: 0 No kerning table 1 numchars*numchars entries, each a signed char with the kerning value 2 numchar entries, each with a list of kerning pairs, like this: int len len * (short char, short value) **!

SEE ALSO
Image and Image.Image

METHOD
Image.Font.baseline

SYNTAX
int baseline()

RETURNS
font baseline (pixels from top)

SEE ALSO
height and text_extents

METHOD
Image.Font.create

SYNTAX
void create(string filename)

DESCRIPTION
Loads a font file to this font object. Similar to load().

METHOD
Image.Font.height,
Image.Font.text_extents

SYNTAX
int height()
array(int) text_extents(string text, ...)

DESCRIPTION
Calculate extents of a text-image, that would be created by calling write with the same arguments.

ARGUMENTS
argument(s)description
string text, ...
One or more lines of text.

RETURNS
an array of width and height

SEE ALSO
write, height and baseline

METHOD
Image.Font.load

SYNTAX
object|int load(string filename)

DESCRIPTION
Loads a font file to this font object.

ARGUMENTS
argument(s)description
string filename
Font file

RETURNS
zero upon failure, font object upon success

SEE ALSO
write

METHOD
Image.Font.set_xspacing_scale,
Image.Font.set_yspacing_scale

SYNTAX
void set_xspacing_scale(float scale)
void set_yspacing_scale(float scale)

DESCRIPTION
Set spacing scale to write characters closer or more far away. This does not change scale of character, only the space between them.

ARGUMENTS
argument(s)description
float scale
what scale to use

METHOD
Image.Font.write

SYNTAX
object write(string text, ...)

DESCRIPTION
Writes some text; thus creating an image object that can be used as mask or as a complete picture.

ARGUMENTS
argument(s)description
string text, ...
One or more lines of text.

RETURNS
an Image.Image object

SEE ALSO
text_extents, load, Image.Image->paste_mask and Image.Image->paste_alpha_color

Previous section To contents Next section