PreviousNext
Help > Software > The <graphics.h> Library for C.impl > Fonts
Fonts

C.impl supports drawing characters from different fonts. Font are defined as a sequence of individual bitmaps for each character, and characters with variable width within the same font are supported.

A font structure is defined as:

typedef struct font_t {

  font_header_t header;

  unsigned char definitions[];

};

A separate header structure holds the general parameters of the font:

typedef struct font_header_t {

  unsigned short start;          // code of the first character in the font

  unsigned short characters;    // number of character definitions in the font

  unsigned char width;           // font width

// This parameter specifies the number of columns in the characters.

// In fonts where the field (.width) is 0, every character definition starts

// with a byte that defines how many columns are present in this character.

// The actual number of bytes to follow depend on the height of the font as

// well: for fonts with height 8 lines or less, every byte represents one

// column, for fonts with height 16 lines or less, every column takes two

// bytes, and so on.

// In fonts with fixed width where (.width) is greater than 0, the leading

// width-specifying byte in every definition is missing since the width is

// already know for all characters

  unsigned char height;   // character definition height in pixels

// This parameter also inherently defines the number of bytes needed for one

// column of a character

  unsigned char blankL;   // blank columns to add on the left side of every char

  unsigned char blankR;   // blank columns to add on the right side of every char

  unsigned char blankT;   // blank rows to add on the top side of every character

  unsigned char blankB;   // blank rows to add on the bottom side of every char

  char *name;                 // optional font name as ASCIIZ string

};

 

Font definition examples:

1.  The definition of character ‘A’ in a font with fixed width 5 (the “width” field in the font header has value 5 and that defines that all characters in the font will be within 5 columns) and height 7 rows:

This sequence of bytes looks like this:

0x7C, 0x12, 0x11, 0x12, 0x7C

 

 

7C

12

11

12

7C

0

 

 

#

 

 

1

 

#

 

#

 

2

#

 

 

 

#

3

#

 

 

 

#

4

#

#

#

#

#

5

#

 

 

 

#

6

#

 

 

 

#

7

not used

 

 

In addition to the definition, in the font header there are fixed definitions for certain number of blank pixels to be added to all sides of every character in the font.

2.  Definition of character ‘W’ in a font with variable width (the “width” field in the font header has value 0) and height 14 rows.

 

Since the width is variable, every character in the font has its own width, and that is specified in one additional byte at the beginning of every character definition.

 

The character in this particular example has 12 columns, and every column is described by two bytes. Since by definition the font has maximum height of 14 pixels, the last two bits in the second byte will remain unused and they are not displayed on the screen.

 

The definition will look like this:

12, 0x01,0x00, 0xFE,0x01, 0x00,0x07, 0x00,0x20, 0x20,0x18, 0xE0,0x07, 0x20,0x1e, 0x00,0x20, 0x00,0x18, 0xFE,0x07, 0x01,0x00

 

 

01

FE

00

00

00

20

E0

20

00

00

FE

01

0

#

 

 

 

 

 

 

 

 

 

 

#

1

 

#

 

 

 

 

 

 

 

 

#

 

2

 

#

 

 

 

 

 

 

 

 

#

 

3

 

#

 

 

 

 

 

 

 

 

#

 

4

 

#

 

 

 

 

 

 

 

 

#

 

5

 

#

 

 

 

#

#

#

 

 

#

 

6

 

#

 

 

 

 

#

 

 

 

#

 

7

 

#

 

 

 

 

#

 

 

 

#

 

 

 

00

01

07

1E

20

18

07

1E

20

18

07

00

8

 

#

#

 

 

 

#

 

 

 

#

 

9

 

 

#

#

 

 

#

#

 

 

#

 

10

 

 

#

#

 

 

#

#

 

 

#

 

11

 

 

 

#

 

#

 

#

 

#

 

 

12

 

 

 

#

 

#

 

#

 

#

 

 

13

 

 

 

 

#

 

 

 

#

 

 

 

14

not used in this font

15

 

All character definitions start immediately after the font header, and follow up in sequential order, so in the example above, after the character ‘W’ will follow character 'X', then character ‘Y’, and so on.

C.impl includes a standard system font with fixed size in a 5x8 pattern drawn in a 6x11 area. The font is based on the full 255 characters CP437 map with the only change introduced in code 158 to include the euro sign character.