Chapter 2. How to Use these Fonts

The fonts supplied in this package are PCL soft fonts. They are so named to differentiate from hardware fonts. Soft fonts reside in the RAM area instead of the ROM in a printer. Although they can be used as if a built-in hardware font, they can not survive a power outage. Therefore, we recommend that your application sends the font at the beginning of every print job to avoid situations that the fonts are lost because someone just pressed the power button. Some high-end printers store soft fonts in their hard drive and automatically load the fonts at the startup. In this case, the soft fonts can be treated as if part of the printer.

For applications to use a soft font, the font must be sent to the printer first. This process is called downloading. The font only needs to be sent once, and will reside in the printer for all the time until a power recycle happens. When your application needs to print the barcode, it sends a special command to switch from the default font to the barcode font. This is called selecting font. After the font is selected, you send the full barcode string (which includes start character, data, checksum and stop character) to printer. At last, you send a PCL command to tell printer to switch back to the default font.

A PCL command always begins with the ESC character (referred as <esc> throughout of this manual). The ASCII value for this character is 27. It is followed by one or two characters (called commands). A PCL command may contain parameters, and termination characters. If you are not familiar with PCL commands, you may want to obtain the [PCL Technical Reference Manual], part number 5021-0377 from HP.

2.1. PCL Font Types

There are several kinds of PCL fonts. Among them the most widely used ones are the bitmapped format and the scalable true type format. The former type usually has a file extension SFP, which stands for Soft Font Portrait. It is so named because there is another type called SFL (Soft Font Landscape) due to the fact that early HP Laerjet printers were unable to rotate font characters. The SFP and SFL formats are identical, except the orientation parameter. A bitmapped font, like a bitmap image, consists of an array of pixel values, instead of drawing commands. As a result, bitmapped fonts only produce fixed size characters which can not be scaled. For example, a font designed to print barcodes at 0.5" height won't produce barcodes at 1.0". You need to ask the font designer to create another font to produce a different size barcode.

Scalable True Type font (SFT), on the contrary, is just like a true type font on Windows or Mac systems. They contains drawing commands instead. As such they can be scaled to any size. You only need one font in the printer to produce barcodes of multiple sizes.

The fonts included in this package are PCL scalable fonts.

2.2. Font Selection

The font selection process is simple for a bitmapped font, since the size is fixed. It is not the case for scalable font. Selecting font by its font ID does not work very well for scalable font. Instead, we recommend to use a combination of symbol set, point size and typeface family value to select the font.

For example, the following statements select scalable font MRV Code39XSA 16 points:

<esc>(0Y<esc>(s16v33221T

or

<esc>(0Y<esc>(s16v<esc>(s33221T

There are three parts in this statement. The first part, <esc>(0Y selects code 3 of 9 symbol set. The middle part <esc>(s16v sets font size to 16 points. Finally, the last part <esc>(s33221T select the font with typeface family value 33221 (which corresponds to MRV Code39XSA. Typeface family value is the weakest requirement, however, if multiple code 39 fonts are installed in the printer, it is the only criteria to select the right font.

For a list of typeface family values of code 39 fonts, refer to Appendix A, Supplemental Information.

If MRV Code39XSA is not present in the printer, another code 39 font will be selected. If no code39 fonts are present, the default font is used. Therefore font selection can be used to verify if the font has been properly downloaded to the printer.

2.3. Downloading Font To Your printer

You can download the fonts to printer by writing some code. On the other hand, in many occasions you might want to do it under command prompt or in a shell environment. The downloading operation involves three steps:

  1. Designate a Font ID to the soft font. The Font ID should be unique among all soft fonts.

    The PCL command to use is <esc>*c#D, while # is the decimal value of the Font ID.

  2. Send the actual soft font.

  3. Make the font permanent by sending PCL command <esc>*c5F.

Step 1 and 2 must be carried out in one connection. If for some reason they can not be sent together in one command line, you need to merge data into one file and send this file instead. We'll explain how to achieve this soon.

There are several methods to send the data above to the printer, depending on the platform and connection choice. For example, if the printer is directly connected to a computer via a parallel port, or the printer is shared among a Windows network, you can use copy to send data to the printer. If it is a network printer connected to a TCP/IP network, you will need to use lpr command.

In preparation of downloading the soft font to your printer, consider the number that you will assign as the font ID. Each soft font must have an unique number associated. Any font with the same ID overwrites the previous one.

In the example we provided, we put the font ID command in file C80D.txt. Another file c5F.txt contains the command for step 3.

2.3.1. Windows

On Windows you can use copy/b command to send data to printer.

c:\> copy /b C80D.txt +mrvcode39xsa.sft +c5F.txt LPT1:

If your operating system is DOS which only supports 8.3 file format, you need to shorten the file name before running the command.

If the destination printer is on the network, use the printer's network name in the place of LPT1. For example, the following command sends the font to a network printer which is shared as HPLaserJon computer Chicago:

c:\> copy/b C80D.txt +mrvcode39xsa.sft +c5F.txt  \\Chicago\HPLaserJ

2.3.2. UNIX/LINUX

On UNIX and LINUX platforms, you can use cat command to copy file to a raw device.

For example, the following command sends the font file to printer:

#cat C80D.txt +mrvcode39xsa.sft +c5F.txt  /dev/lpt1r

Here, /dev/lpt1r refers to the printer connected to the LPT1 port. The r means raw device.

2.3.3. LPR

When the printer is connected to a TCP/IP network directly, the best method is to send commands through lpr command. A TCP/IP device may be identified with a full qualified DNS name, or an IP address. In our test lab, we assigned our network printer a fixed IP address 192.168.1.22, and we use this address in the examples below. In lpr manual page, it is also referred as Printer Name.

Another name you will need is Queue Name. The queue names are names assigned to the processors in the print server. Most print servers and network printers have hard-coded queue names. Some allow you to define your own queue. On HP JetDirect printer servers, the raw PCL queues are named as raw, raw1, raw2 and raw3. In test files we use raw as the queue name.

Note that lpr command only accepts 1 file at a time. However, the step1 and step2 commands must be sent in one stream, otherwise the printer will discard them altogether. As a result, you will need to merge these three files into one first. On Windows, you can use copy command:

copy /b C80D.txt +mrvcode39xsa.sft +c5F.txt total.bin

On Linux/Unix platforms, use cat command:

cat c80D.txt mrvcode39xsa.sft c5F.txt > total.bin

Now we can send these files (Windows):

lpr -S 192.168.1.22 -P raw -ol total.bin  
lpr -S 192.168.1.22 -P raw -ol data.txt

You need to replace the ip address, the queue name and the file name with the appropriate ones in your environment.

On Linux/UNIX platforms, things are more complicated. The configuration varies from platform to platform. Generally you need to set up the printer first. On RedHat Linux, this can be done using printtool. You assign a printer name (queue name) in the configuration, and you use this name in lpr command. Assume that the name is HPPrinter, the lpr command on RH Linux becomes:

lpr -P HPPrinter -o raw total.bin     
lpr -P HPPrinter -o raw data.txt

2.3.4. Checking Font Existence

Normally if the printer has sufficient memory, the download will be successful. You usually won't need to worry about the memory issue. To verify that the font is residing in the printer, you can write some code which selects the font and prints a couple of lines of text. High end printer models usually have a LCD control panel that provides a way to print the PCL font list. If a LCD panel is on the printer, you can do the following to print a PCL font list, and check the font name against the list:

  • Press the ENTER/MENU key on the control panel.

  • Use the > or < key to select Reports and press ENTER/MENU.

  • Use the > or < key to select PCL Font List and press ENTER/MENU. The printer exits the Menu settings and prints the list.

Although soft fonts can survive many PCL commands, they are residing in the RAM area, not the ROM. Therefore they are not able to survive a power loss. Thus, it is a good idea to download the font at each printing job. Our font size is very small (5K ~ 20K) and downloading only takes approximately 1 second. Each time the font downloaded will automatically overwrite the one downloaded earlier if the two fonts share the same Font ID.

The image below is taken from the actual print out on a HP Laerjet 2300 model [1].



[1] Note that some tall(M and above) fonts printers characters much taller than the regular line height. As a result, the font names are not very clearly displayed in the print out. The best way to verify the font existence is to select one and print some characters out.