The TApxCharSetMapping Class

HierarchyPropertiesMethods

Unit:

AxTerm

Description:

The TApxCharSetMapping class provides a method to emulate the different character sets used by terminals by using glyphs from different fonts.

One of the problems of emulating a terminal is that terminals, especially the older ones, use specialized glyphs that are not available in the normal fonts. The character set mapping class attempts to work around this problem by enabling the emulator to obtain the glyphs for different character sets from different fonts.

Before proceeding with the character set mapping class, a few terms should be defined. A character is a binary value, usually byte-sized. The way a character is usually thought of is both as its binary value and as its visual form. Hence, when character 'a' is thought of, for example, it is thought of in terms of its value ($61) and of its visual form (a drawing of a lowercase letter 'a', like the one you just read just now). However, the link between the character 'a' and the visual form of the character is not fixed. Different fonts may display the character 'a' in different ways and some visual representations (what are known as glyphs) may look nothing like a lowercase 'a'. An example is the symbol font where the character 'a' is drawn as a Greek lowercase . With terminals, there may be several character sets that are available at once, and these character sets function in the same way as fonts. On the VT100, for example, there are two main character sets, standard and special graphics, which display the line draw characters. In the first, the character 'a' is drawn as a lowercase 'a'. In the second, it is drawn as a checkerboard glyph.

The character set mapping class is designed for use by a terminal emulator. When the terminal display needs to be painted, the emulator will use a character set mapping class to identify which glyphs need to be painted on the terminal window. For this it will pass a string of characters to the mapping class, together with the character set to be used. The TApxCharSetMapping object will return a "script" to the emulator. This script will consist of a series of text drawing commands all of the form "using font X, draw string Y." Usually the script will consist of just one command, since the characters will generally all come from the standard ASCII set and hence can be drawn using just one font.

The TApxCharSetMapping class gets its mapping data from one of two sources: a specially formatted text file or a resource linked into the application. Thus, it is possible to have a default mapping linked to the application, but also to be able to provide a way of altering the mappings at run time (maybe to suit the fonts on the user's machine).

To help create the resource the character set mapping class has a method to write its current mapping set to a binary file, which can then be compiled into a resource file. The following code example shows this process:

var
CharSetMap : TApxCharSetMapping;
begin
CharSetMap := TApxCharSetMapping.Create;
try
CharSetMap.LoadFromFile('AXCHSVT1.TXT');
CharSetMap.StoreToBinFile('VT100.BIN');
finally
CharSetMap.Free;
end;
end;

The code creates a TApxCharSetMapping instance called CharSetMap. A set of mappings is then read from a file called AXCHSVT1.TXT (this file is a default set of character set mappings for a VT100 emulator that is provided with Async Professional CLX). The mappings are then written out to a file called VT100.BIN.

This latter file can be compiled into a resource using a standard Windows resource compiler (such as BRCC.EXE or BRCC32.EXE supplied with Delphi and C++Builder). At the time of this writing, a Windows resource compiler is not supplied with Kylix.

The resource script (RC file) required for this is as follows:

MyVT100CharSetMap RCDATA VT100.BIN

If you name the resource file VT100.RC, the resource compiler will create a file called VT100.RES. Adding the resource to your application at that point is merely a case of adding the following line to your project file and recompiling:

{$R VT100.RES}

Now you can call the LoadFromRes method of your TApxCharSetMapping instance to load this set of character set mappings.