An Introduction to HP-GL/2 Graphics

The PCL 5 printer provides the ability to print vector graphics using the HP-GL/2 graphics language. HP-GL/2 graphics may be created within application software or imported from existing applications. For various types of images (many technical drawings and business graphics, for  example), it is advantageous to use vector graphics instead of raster graphics. The advantages of using vector graphics include faster I/O transfer of large images and smaller disk storage requirements.

Note As a guideline, use raster graphics for small, complex images or those images that cannot be accomplished with HP-GL/2 (such as scanned photographs). Use HP-GL/2 for images that would involve a large amount of I/O data transfer if printed using raster graphics, or for drawings that are already in HP-GL/2 format. If the image is easier to describe using vectors instead of raster lines, the image will usually print faster using HP-GL/2.

Printing with HP-GL/2 requires leaving the PCL printer language mode and entering the HP-GL/2 mode. Switching between modes involves only a few commands and software applications may easily switch between the two modes as needed --without affecting performance.

LEARNING HP-GL/2

The best way to learn to use HP-GL/2 commands is to first read through this chapter and Chapter 16 for a general overview of the language and its relationship to the PCL printer language. Then, flip through the other HP-GL/2 chapters until you see an example that interests you or fits your

objective. Read through the examples and try printing them using your choice of programming languages. If you need a little help in converting the generic commands shown in the examples to a programming language, see the Using HP-GL/2 with Programming Languages discussion later in this chapter.

As you see commands that you are unfamiliar with, find the page number of the command description in the index and read about the command. After trying some examples and seeing how the commands interact, you should be well on your way to learning the HP-GL/2 language. Think of an application that you would like to program and then look for an example that uses some of the elements you desire. In your search to create your drawing, you will be steadily learning to print using the HP-GL/2 language.In the process of giving you an overview of HP-GL/2, this chapter describes the interaction between the PCL printer language and the HP-GL/2 modes and introduces the following topics:

HP-GL/2 Commands and Syntax

Using HP-GL/2 with Programming Languages

Defining the Image Area and Scaling Factor

The HP-GL/2 Coordinate System

HP-GL/2 and PCL Orientation Interactions

The Vector Graphic Limits

Units of Measure

Pen Position and Location

Automatic Image Enlargement/Reduction

Absolute and Relative Pen Movement

Chapter 16 covers more of the HP-GL/2 fundamentals and the remaining chapters (17 - 21) discuss the HP-GL/2 commands and their syntax.

HP-GL/2 Commands and Syntax

There are two classes of commands used to print vector graphics: PCL printer language commands and HP-GL/2 commands. As their name implies, the PCL printer language commands are used when in the PCL printer language mode. They define the area on the page where the HP-GL/2 graphics will be printed and provide a means to enter the HP-GL/2 mode. The HP-GL/2 commands are used within HP-GL/2 mode, define the image that will be printed, and allow you to return to the PCL printer language mode. The HP-GL/2 language has its own syntax and each command is listed in this section of the manual.

To make it easier to learn and use the vector graphics commands, they have been grouped into functional categories. The categories are designated as shown  in Tables 15-1 to 15-5:

HP-GL/2 Commands by Group

Table 14-1

CONFIGURATION GROUP

DF  Default Values
IN  Initialize
IP Input P1 and P1
IR Input Relative P1 and P2
IW  Input Window
PG  Advance Page
RO  Rotate Coordinate System
RP  Replot
SC Scale

Table 15-2.

VECTOR GROUP

AA  Arc Absolute
AR Arc Relative
AT Absolute Arc (Three Point)
CI  Circle
PA  Plot Absolute
PD Pen Down
PE Polyline Encoded
PR Plot Relative
PU Pen Up
RT Relative Arc (Three Point)

Table 15-3

POLYGON GROUP

EA Edge Rectangle Absolute
EP Edge Polygon
ER Edge Rectangle Relative
EW Edge Wedge
FP Fill Polygon
PM Polygon Mode
RA Fill Rectangle Absolute
RR Fill Rectangle Relative
WG Fill Wedge

 

Table 15-4.

CHARACTER GROUP

AD Alternate Font Definition
CF Character Fill Mode
CP Character Plot
DI Absolute Direction
DR Relative Direction
DT Define Label Terminator
DV Define Variable Text Path
ES Extra Space
FI* Select Primary Font
FN* Select Secondary Font
LB Label
LO Label Origin
SA Select Alternate Font
SB* Scalable or Bitmap Font
SD Standard Font Definition
SI Absolute Character Size
SL Character Slant
SR Relative Character Size
SS Select Standard Font
TD Transparent Data

*Indicates these commands are part of the Dual Context Extensions to the HP-GL/2 language

Table 15-5

LINE AND FILL ATRIBUTES GROUP

AC Anchor Corner
FT Fill Type
LA Line Attributes
LT Line Type
PW Pen Width
RF Raster Fill Definition
SM Symbol Mode
SP Select Pen
SV* Screened Vectors
TR* Transparency Mode
UL User Defined Line Type
WU Pen Width Unit Selection

* Indicates these commands are part of the Palette Extensions to the HP-GL/2 language.

Each of the above command categories is discussed in its own chapter, beginning with Chapter 17, The Configuration Group.

As shown in the tables above, each HP-GL/2 command is a two-letter mnemonic code designed to remind you of its function. For example, IN is the INitialize command, SP is the Select Pen command, and CI is the CIrcle command. Parameters are used with certain HP-GL/2 commands to tell the printer to complete the command in a particular way. A typical HP-

GL/2 command appears as follows:

    FT1

The mnemonic (FT, for Fill Type) tells the printer a fill type will be specified; the "1" parameter specifies a solid black fill.

UNDERSTANDING HP-GL/2 SYNTAX

HP-GL/2 commands have four components: a mnemonic, parameter(s), separator(s), and a terminator. Refer to the following illustration of a typical HP-GL/2 command and the description of its components.

Mnemonic Separator

\ / Terminator

PA30, 30; /

Parameters

Mnemonic -- The two-letter mnemonic is designed to remind you of the command’s function. The mnemonic can be uppercase or lowercase.

Parameter (s) --Some commands have no parameters; for those commands having them, parameters can be either required or optional (as indicated in the description of that command);

Separator (s) -- When you use parameters, you must separate them with a comma or space, or in the case of a numeric parameter, with a + or - sign. (Commas are recommended because some computers eliminate spaces, especially when sending variables.)

Terminator -- All commands require a terminator. HP-GL/2 commands are terminated by a semicolon or the first letter of the next mnemonic. The last command prior to exiting HP-GL/2 mode must be terminated with a semicolon. The following illustration shows the flexibility of the syntax. Each variation of the two-command sequence is permissible; however, the first method is recommended for your programming. The recommended method uses the first letter of the next mnemonic to terminate commands, uses no space between the mnemonic and its parameters, and separates parameters with a comma. (For clarity, examples in this HP-GL/2 section of the semicolons as terminators as shown in the middle example below.)

PDPU1O,20

/

Recommended

PD; PU1O, 20;

PD PU 10 20;

NOTATIONS USED TO EXPRESS SYNTAX

The next section explains how the syntax of individual commands is presented.

to The following describes the notations used in the syntax section of each command description:

Mnemonic

For readability, the mnemonic is shown in uppercase and separated from the parameters and/or terminator.

parameters

Parameters are shown in italic.

[ ]

Parameters in square brackets are optional.

[paraml,param2 ... [,paraml,param2]]

These optional parameters must be paired.

params ... params

These parameters may be given the number of times specified in the command description.

text ... text

This parameter indicates that you can type in a range of ASCII characters, such as in the Label (LB) command.

(...)

Indicates you can use a range of the previous parameter; however, all X coordinates

must have a corresponding Y coordinate.

;

Command terminator. A semicolon is optional and is shown in parentheses in most

command syntax. The Polyline Encoded (PE) command is an exception, and must

be terminated by a semicolon. Also, the last HP-GL/2 command before leaving

HP-GL/2 mode must always be followed by a semicolon.

,

A comma is always shown as the separator between parameters. A space, +, or - is  also valid (although not preferred). (A + or - is only a valid separator for numeric parameters.)

__________________________________________________

Note

Remember that while X,Y coordinates are shown in parentheses in text [for example (3,4) or (0,0)], the parentheses are not part of the syntax. Do not enter these parentheses in your commands.

_______________________________________________________________________________________

Omitting Optional Parameters

Some commands have optional parameters that take on default values if they are omitted. When you omit a parameter, you must omit all subsequent parameters in the same command (the Define Label Terminator (DT) command is an exception).

For example, the Line Type (LT) command has three optional parameters: type, pattern length, and mode. The following command shows all three being used (type = 6, pattern length = 25, mode = 1).

    LT6,25, 1

If you omit the second parameter you must also omit the third parameter, as shown below. The printer uses the most recently specified pattern length and mode. If you have not specified a length or mode since sending a Default Values (DF) or Initialize (IN) command, the printer uses the parameter’s defaults.

    LT6

For example, do not send the following command (the printer would interpret 1 as the second parameter).

LT6, 1

Parameter Formats

You must give parameters in the format (type of units) required by each HP-GL/2 command. The required format is stated in the parameter table of each command’s description, and is described as follows.

1. Integer -- An integer from -1,073,741,824 (-2^30) to 1,073,741,823 (2^30 - 1). The printer automatically rounds fractional parameters to the nearest integer. Using a number outside the specified range causes an error.

2. Clamped Integer -- An integer from -32,768 (-2^15) to 32,767 (2^15 -1). The printer automatically rounds fractional parameters to the nearest integer. Sending a number outside this range does not cause an error, but the number is 93clamped94 to the limits of the range. For example, when parsing a clamped integer, the printer treats all numbers between 32,767 and 67,108,863 as 32,767.

Certain commands have parameters which are restricted to a smaller range. These ranges are listed in the parameter tables for each command. Sending a number outside the reduced parameter range may produce unexpected results.

3. Real -- A number where the integer portion is from -1,073,741,824 (-2^30) to 1,073,741,823 (2^30 - 1). You are  assured of at least 6 significant digits (including integer and fractional portion). You may omit the decimal point when no decimal fraction is specified. If you don’t specify a sign, the parameter is assumed to be positive. Using a number outside this range causes the command to be ignored

4. Clamped Real -- number where the integer portion is from -32,768 to 32,767; you are assured of at least 6 significant digits (including integer and fractional portion). You may omit the decimal point when no decimal fraction is specified. If you don’t specify a sign, the parameter is assumed to be positive. Sending a number outside this range does not cause an error, but the number is "clamped" to the limits of the range. For example, the printer treats all numbers between 32,767 and 67,108,863 as 32,767.

Certain commands have parameters which are restricted to a smaller range. These ranges are listed in the parameter tables for each command. Sending a number outside the reduced parameter range causes the command to be ignored.

5. Label —Any sequence of characters. In the HP-GL/2 language, text is described using the term "label". Refer to the Label (LB) command in Chapter 21 for a complete description.

Note Numbers within the above-mentioned ranges do not ~ cause errors; however,

the range may exceed the printer’s physical printing area. Numbers that move the pen position outside the effective window result in image clipping. This topic is discussed in more detail later in this chapter in the Vector Graphics Limits discussion.

When you see the term current units in a parameter table, the unit system of that parameter depends on whether scaling is on or off. When scaling is on, the units are user units; when scaling is off, the units are plotter units.

Note The printer cannot use exponential format numbers (for ~ example, 6.03E8). If you are using a computer or language that uses the exponential format, you must use integer variables or a formatting technique to output fixed-point real numbers. 

Note Parameter values less than the range maximum are passed by the parser; these values may subsequently be unscaled into resolution units (e.g. 7200 units per inch) that exceed the device dependent internally representable number range. If this occurs the device enters a LOST mode where all relative drawing commands are ignored until a command is received which specifies an absolute move to a point within the internally representable number range.

When LOST mode is entered, the pen is raised and the following commands are ignored: AA, AR, AT, CL, CP, EA, ER, EW, LB, PE, PM, PR, RA, RR, RT, and WG.

The commands allowed in LOST mode are: AC, AD, CF, GO, DF, DI, DR, DT, DV, ES, FT, IN, IP, IR, 1W, LA, LO, LT, PA, PD, PG, PU, PW, RF, RO, RP, SA, SB, SC, SD, SI, SL, SM, SP, SR, SS, TD, UL, WU, and the PM1/PM2 forms of PM.

The commands IN, PG, RP, and PA, with in-range parameters, clear LOST mode, PD and PU in absolute plotting mode, with in-range parameters, also clear LOST mode. When PD clears LOST mode, a line is drawn from the last valid current position to the first point in the PD parameter sequence. If PA clears LOST mode, the pen will not go down until a PD command is received.

Using HP-GL With Programming Languages

The HP-GL/2 examples included in this manual are given in a "generic" format; that is, the examples show the commands required to perform a specific function but usually do not use a specific programming language. In most cases, the commands are accompanied by a brief description of the command being used.

To see how HP-GL/2 commands are used in BASIC and the C programming language, see the following examples.

Example: BASIC

This example uses BASIC to implement the generic Drawing Lines.

10 LPRINT CHR$(27);"E"; : REM Reset the printer

20 LPRINT CHR$(27);"%B";: REM Enter the HP-GL/2 Mode

30 LPRINT "IN"; : REM Initialize HP-GL/2 Mode

40 LPRINT "SP1PA10,10";: REM Select Pen & Move to 10,10

50 LPRINT "PD2500,10,10,1500,10,10";: REM Pen Down and Draw

60 LPRINT CHR$(27);"%0A";: REM Enter PCL Mode

70 LPRINT CHR$(27);"E": REM Reset to end job/eject page

 

Example: C Programming Language

This example uses the C programming language to implement the same example (the Drawing ines example on page 18-3).

 

#include <stdio.h>

 

main()

 

{

FILE *prn; /* initialization section */

prn = fopen("PRN","wb");

fprintf(prn,"\33E"); /* send an esc F to reset printer */

fprintf(prn,"\33%0B"); /* Esc%lB to Enter HP-GL/2 */

fprintf(prn,"IN"); /* Initialize HP-GL/2 Mode */

fprintf(prn,"SP1PA10,10"); /* Select pen & move to 10,10

fprintf(prn,"PD2500,10,10,1500,10,l0;"); /* Pen down & draw */

fprintf(prn,"\33%0A"); /* enter PCL at previous CAP */

fprintf(prn,"\33E"); /* Reset to end job/eject page */

}