[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Guide to Printers and Printing


Printer Code Page Translation Tables

Translation of code points in the print file to code points for the printer is a two-stage process (translation of code points for Oriental languages is handled differently). The first stage translates code points from the print file to code points in an intermediate code page. The intermediate code page consists of 16-bit integer code points for all supported characters. The first 256 code points in the intermediate code page are identical to IBM Code Page 850, except that code points 0 through 31 (decimal) are ASCII control characters instead of printable characters. The intermediate code page is defined in the /usr/lib/lpd/pio/etc/codepage.txt file.

Stage-1 Translation

The example C language code shown below generates a stage-1 translation table to translate code points from a hypothetical Code Page 123 to the intermediate code page.

#include <piostruct.h>
#include <fcntl.h>
/*** Table to Translate Code Points for Input Code Page ***/
/*** "123" to Code Points for the Intermediate Code Page    ***/
short table[256] = {
/* 00 (000) */ CP, CP, CP, CP,
.
.
.
/* FC (252) */ CP, SC, 126, CP };
/*** Write the Table to a File (Error Processing Not Shown) ***/
main ( ) {
int fildes;
int fmt_type = 1;
fildes = open("/usr/lib/lpd/pio/transl/123", O_CREAT | O_WRONLY,\
0664);
write(fildes, "PIOSTAGE1XLATE00", 16);
write(fildes, &fmt_type, sizeof(fmt_type));
write(fildes, table, sizeof(table));
return(0);
}

The CP at code point 252 means that the code point should be copied with no change. The SC at code point 253 means the character is not defined in the intermediate code page and so a substitute character should be printed instead. The 126 at code point 254 means that code point 254 should be translated to code point 126.

The -X flag in the qprt command specifies the print file's code page name. When this value is 123, the formatter reads the table from the /usr/lib/lpd/pio/trans1/123 file and uses it for stage-1 translation.

Stage-2 Translation

In the second stage of code point translation, one or more stage-2 translation tables convert code points from the intermediate code page to those appropriate for the printer. The t0 - t9 attributes in the database colon file specify the full path names of stage-2 translation tables. Each of the t0 - t9 attributes can specify multiple stage-2 translation tables by separating the names with commas. The print formatter reads in the stage-2 translation tables and chains them into a ring. Beginning with the table for the current printer code page, the formatter processes each character in the input print file. The first determination is whether the character is defined in that printer code page. In other words, the code point value is not larger than the number of code points in the table, and the value is not SC.

If the character is in the code page, the translated code point is sent to the printer. The formatter selects the printer code page by sending the appropriate printer command string. By convention, the printer command string's 2-character attribute name is at index 0 in the Command Names array. If the character is not in the code page, the formatter repeats the process for the next stage-2 translation table in the ring. If the formatter cannot find a translation table in the ring that can print the character, it prints a substitute character (underscore) instead.

The following example C language code generates a stage-2 translation table named XYZ.999, which translates code points from the intermediate code page to code points for the printer's code page. The c1 attribute is assumed to contain the printer command string that will cause the printer to select code page XYZ.999.

#include <piostruct.h>
#include <fcntl.h>
/*** Table to Translate Code Points for the Intermediate ***/
/*** Code Page to Code Points for a Printer Code Page ***/
struct transtab table[] = {
/* 00 (000) */ {CP}, {CP}, {CP}, {CP},
.
.
.
/* FC (252) */ {63}, {CP}, {94,1}, {SC} };

/*** Command Names for the Translate Table ***/
char cmdnames[][2] = {
{'c', '1'},              /* index 0 - select the code page */
{'e', 'b'} };            /* index 1 - next byte is graphic */

/*** Write the Table To a File (Error Processing Not Shown) ***/
main() {
int fildes;
int num_commands = sizeof(cmdnames) / 2;
fildes = open("/usr/lib/lpd/pio/trans2/XYZ.999", O_CREAT |
O_WRONLY,\ 0664);
write(fildes, "PIOSTAGE2XLATE00", 16);
write(fildes, &num_commands, sizeof(num_commands));
write(fildes, cmdnames, sizeof(cmdnames));
write(fildes, table, sizeof(table));
return(0);
}

The {63} at code point 252 means that code point 252 should be translated to code point 63 before being sent to the printer. The {CP} at code point 253 means that code point 253 should be sent to the printer with no translation. The {94,1} at code point 254 means that code point 254 should be translated to code point 94 before it is sent to the printer. The ,1 in {94,1} indicates that the printer command string whose 2-character attribute name is at index 1 in the Command Names array should be sent to the printer before sending the code point. The SC at code point 255 indicates that the character at code point 255 in the intermediate code page cannot be printed by the printer code page described by this stage-2 translation table.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]