C Language Development Kit/Functions/SetFont

From OptiWiki

Jump to: navigation, search
Description This function is used to select a character font. setfont() uses a pointer to a user defined font table, the name of a font file, or selects one of the two built-in fonts. The maximum character bitmap size is limited to 16*16 bits. The number of characters is not limited, however the functions that display a character, for example putc(), use an integer to specify the character, so practically the number of characters is limited to 65535. By default the LARGE font is selected,

except for the OPH100x which uses the MEDIUM font by default.

Syntax
int setfont(unsigned int type, char * name);
Arguments
unsigned int type
Specifies whether a user font or a built-in font is used. The following constants are defined for this function:
USER_FONT Selects a user font in a table, name points to the table.
FILE_FONT Selects a font file, name is the name of the font file.
EXTRA_LARGE_FONT Selects the extra large system font (only supported on OPH 1000).
LARGE_FONT Selects the large system font.
MEDIUM_FONT Selects the medium system font (not supported on PHL 1300 and PHL 1700).
SMALL_FONT Selects the small system font.
TINY_FONT Selects the tiny system font (not supported on PHL 1300 and PHL 1700).

The following table shows the size of the various fonts, plus the amount of characters and lines that fit on the screen of the terminal.

EXTRA LARGE LARGE MEDIUM SMALL TINY
OPH100x 16 * 14 pixels
8 chars * 8 lines
16 * 8 pixels
14 chars * 8 lines
12 * 6 pixels
18 chars * 10 lines
8 * 8 pixels
14 chars * 16 lines
6 * 6 pixels
18 chars * 21 lines
PHL1300 12 * 6 pixels
16 chars * 4 lines or
16 chars * 5 when
cursor() with NOICON
6 * 6 pixels
16 chars * 8 lines or
16 chars * 10 when
cursor() with NOICON
PHL1700 12 * 6 pixels
16 chars * 4 lines
6 * 6 pixels
16 chars * 8 lines
PHL2700 16 * 8 pixels
16 chars * 4 lines
12 * 6 pixels
21 chars * 5 lines
8 * 8 pixels
16 chars * 8 lines
6 * 6 pixels
21 chars * 10 lines
OPL97xx 16 * 8 pixels
14 chars * 4 lines
12 * 6 pixels
18 chars * 5 lines
8 * 8 pixels
14 chars * 8 lines
6 * 6 pixels
18 chars * 10 lines
DCL153x 16 * 8 pixels
14 chars * 4 lines
12 * 6 pixels
18 chars * 5 lines
8 * 8 pixels
14 chars * 8 lines
6 * 6 pixels
18 chars * 10 lines

The character map for the different terminals is shown here.

char * name

A pointer to a user defined font table or the name of a font file. When a built-in font is selected, name is ignored (use NULL).

The contents of the user defined font table or font file must have the following format:

    unsigned char height;
    unsigned char width;
 
    unsigned char byte_1;
    unsigned char byte_2;
    unsigned char byte_3;
    ...........
    unsigned char byte_n;

The first two bytes defines the height and width of a character, the rest of the table defines the bitmaps of the characters. The definition of these data bytes depends on the character height. When the character height is 8 pixels or less the data is defined as follows:

Suppose we want to define a 6*6 character. The bitmap of this character is shown in the next picture: File:Small char.jpg The data for this character will be: 0x78, 0x24, 0x24,0x24,0x78,0x00. These 6 bytes define the first character (character 0) the next 6 bytes define character 2 etc. Functions like putchar() can be used to show a user defined bitmap on the display.

When the character height is more then 8 pixels, the bitmaps are split in two halves. First the upper half of the character is defined, next the lower half. Suppose we want to define a 12*6 character. The bitmap of this character is shown below: File:Large char.jpg As described before, the upper half is defined first, so the data for this character becomes: 0x00, 0xC0, 0x20, 0x20, 0xC0, 0x00, 0x00, 0x3F, 0x02, 0x02, 0x3F, 0x00.

Returns
OK No errors encountered.
ERROR Specified font file does not exist.
Remarks With the standard C functions only characters up to 255 can be printed. With the printsymbol()

function characters up to 65535 can be printed. The printf() and putchar() functions can however print characters up to 65535 by using a special mechanism. The 0xFF character is interpreted by printf() and by putchar() as an instruction to take the next two bytes and

to combine them into an integer index in the font file / table. For example,
printf("\xFF%c%c",0xA6,0xD2);

prints character A6D2 on the screen.

Since the horizontal and vertical size of a character depend on the font type, the same character coordinates (as set by gotoxy()) may refer to different physical positions for different fonts.

Therefore after calling setfont() the cursor may have to be set to the desired location.

Tip LARGE_FONT and SMALL_FONT have the same number of characters per line, and the same number of lines on both the PHL1700 and the PHL2700. Therefore, a PHL1700 application recompiled for the PHL2700 will have the same appearance on the LCD screen. It is not necessary to change the font, because of the screen size.

Tip You can scroll LARGE_FONT characters by half a line height, by changing to SMALL_FONT, going to the bottom of the display and then printing a newline. Similarly for MEDIUM_FONT and TINY_FONT.

Example
// The following example shows a word on the screen in a user defined font.
// The 'const' keyword in the definition of the character map causes the data to
// be placed in Flash-ROM. When this is omitted, the data is placed in RAM.
// This can be an advantage when a very large font table is required,
// since the RAM size is larger then the Flash-ROM size.
 
#include "lib.h"
#include <stdio.h>
 
const char charmap[2+7*6] = { // 7 char's * 6 bytes plus 2 header bytes
    0x06, 0x06,
    0x00, 0x38, 0x44, 0x44, 0x38, 0x00, //0
    0x00, 0x7C, 0x14, 0x14, 0x08, 0x00, //1
    0x04, 0x04, 0x7C, 0x04, 0x04, 0x00, //2
    0x00, 0x44, 0x7C, 0x44, 0x00, 0x00, //3
    0x00, 0x38, 0x44, 0x44, 0x44, 0x00, //4
    0x00, 0x38, 0x44, 0x44, 0x38, 0x00, //5
    0x00, 0x7C, 0x08, 0x10, 0x7C, 0x00  //6
};
 
void main( void )
{
    int x;
 
    setfont( USER_FONT, (unsigned char*) charmap);
 
    for( x=0; x < 7; x++)
    {
        gotoxy( 2+x, 3);
        printsymbol( x);
    }
 
    while( 1 )
        idle();
}


Views
Personal tools