C Language Development Kit/Application development/Fonts and displaying text

From OptiWiki

Jump to: navigation, search

Fonts on terminals with a display

The terminals with display have build-in standard character fonts with different sizes. Depending on the terminal, the following fonts are available: huge, large, medium, small and tiny.

Huge font Large font Medium font Small font Tiny font
OPH1004 & H13 & PX30 X X X X X
OPH1003 X X X X
PHL2700 X X X X
PHL1300 & PHL1700 X X
OPL97xx & DCL153x & PX25 X X X X

You can find out the exact size of a character (measured in pixels) by using the function getfontsize(). See the setfont() function for details of built-in standard fonts. These will fulfill requirements of many users. Also see the setecho() function that controls echoing typed characters on the display.

The [[C Language Development Kit/Character maps and key codes/Character maps|character map] is shown here.

User defined fonts can also be used by the handheld terminal. The user font can be loaded into the handheld terminal at run time in a file or it can be linked to the executable during design time. In both cases the user font is specified in the form of a table with the following elements:

    unsigned char height;         // height of a character measured in pixels
    unsigned char width;          // width of a character measured in pixels
    unsigned char byte_1;         // first eight pixels
    unsigned char byte_2;         // second eight pixels ...
    // (and so on)

See the description of the setfont() function for full details on how to design your own font. By calling setfont() the user specifies if the handheld terminal must use the standard large or small font, a user font in a file, or a user font in a table. The file or table is specified by name, so it is possible to load more than one user font into the handheld terminal and to switch between fonts at run time. The maximum character bitmap size is limited to 16*16 bits.

There are some practical limitations on how many characters can be defined in a font table. The standard C functions that process text to be printed on the screen assume that the text to be printed is specified byte for byte. The string supplied to the function is processed byte for byte. The value of a byte in the string serves as an index into the font table. This would mean that 256 characters can be defined in the font table and be printed with these functions. The font is a so-called one-byte font. The printsymbol() function prints one character on the screen and has an integer as argument, hence it can address 65536 characters in the table. For each character to be printed a call must be made to printsymbol(). A special character was introduced to be able to print two-byte fonts. When functions as printf(), putc() encounter the character 0xFF in the text, the next two bytes will be combined into one integer and used as an index in the font table. For example the call printf("\xFF%c%c",0xA6,0xD2); will print the character whose hexadecimal index value is A6D2. Examples of two byte fonts are Kanji (Japan), Jian Ti (simplified Chinese) and Fan Ti (traditional Chinese). Another way to print two-byte fonts with the 0xFF character is illustrated below. In this example a literal string of Chinese characters is printed on the screen. It is assumed that Chinese characters on the PC are represented as two-byte codes in the source code of the program.

Example:

#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
 
void main( void )
{
    char str[100];
 
    for(;;)
    {
        ConvertString(str,"Chinese characters literal text");
        printf("%s", str);
 
        while( getchar() == EOF )
            idle();
    }
}
 
void ConvertString(char *out, char *in)
{
    int x;
    unsigned int hi_byte, low_byte, c;
 
    for(x=0;;x+=2)
    {
        if (in[x]=='\0')
            break;
 
        hi_byte = in[x]&0xFF;
        lo_byte = in[x+1]&0xFF;
        c=someformula(hi_byte,lo_byte);
        *(out++)='\xFF';
        *(out++)=(c>>8)&0xFF;
        *(out++)=c&0xFF;
    }
 
    *out='\0';
}

In this example we assume that when the compiler scans the source file it will replace each Chinese character by two bytes in the const section of the executable. At run-time, when the literal text is converted for screen printing by ConvertString() the handheld terminal will scan the text byte for byte. In the example the function someformula() returns the integer index in the font table for the Chinese character. This integer is placed in the string str as two bytes preceded by the 0xFF character. str is passed to printf() to be printed on the screen.

Refer to Special characters for a list of escape sequences that can be used in functions like printf() or putc() to denote special characters. Examples are '\n' for carriage return and '\xFF' to combine two bytes into one integer index in a font file.

The font of the DWT7133

The DWT7133 has only one built-in font. User fonts cannot be defined for the DWT. However, the user is able define the first 8 characters in the font with the function definecharacter().

The [character map] of the DWT7133 is shown [here].

The DWT7133 display can show 2 lines of 16 characters. Each character is a bitmap of 5 bits wide and 8 bits high.

The setecho() function can be used to control echoing typed characters on the display.

Refer to Special characters for a list of escape sequences that can be used in functions like printf() or putc() to denote special characters. Examples are '\n' for carriage return and '\xFF' to combine two bytes into one integer index in a font file.

Views
Personal tools