Understanding HPGL


Data Exchange by Ralph Grabowski

Hewlett-Packard has found itself in the fortunate position of having creating two de facto standards for output devices: HPGL (short for Hewlett-Packard Graphics Language) and PCL, short for Printer Control Language. Although HPGL was intended for HP's line of pen plotters, variants have found their way into inkjet and laser printers. PCL, on the other hand, is strictly used by HP for its raster devices and is very slowly loosing favor to PostScript and Windows-based direct-GDI.

A Brief History of HPGL

HPGL is a command set embedded in the ROM of pen plotters to help reduce the work required by applications programmers to create plotted output. HPGL uses two-letter mnemonics as instructions for drawing lines, circles, text, and simple symbols. HPGL has evolved over the years as HP added features to its line of pen, electrostatic, inkjet, and laser plotters and printers.

However, there is one primary drawback to HPGL: it is bulkier than other plotting languages, which means it takes longer to transmit an HPGL plot file than, say, a Houston Instruments' DM/PL (short for digital microprocessor plotting language) plot file. To overcome the limitation, Hewlett-Packard in 1988 introduced HPGL/2, which featured "polyline encoding," a form of data compression that reduces the plot file size and, hence, transmission time by two-thirds.

With HPGL being the de facto plotting standard, competitors inevitably include HPGL or some similarly-named dialect in their plotter products. In addition, HPGL has become a form of CAD drawing translation of last resort, since all CAD packages produce HPGL files and several read the format.

Coordinate Systems

One irritant to HPGL is that there are two different coordinate systems in use. Small-format plotters, including A- and B-size plotters, locate the origin at the lower-left corner; large-format plotters, including D- and E-size plotters, located the origin at the center of the media.


TIP: HPGL uses the plu (short for plotter units) as its form of measurement. There are 40 plu per millimeter and 1,016 plu in one inch.

All plotting languages have two forms of limits: (1) hard limits; and (2) soft limits. The hard limits are the limits beyond which the plotter cannot plot due to physical constraints. The soft limits are usually imposed by the application software generating the plot file. Any part of the drawing extending beyond the limits (hard or soft) is clipped (is not be plotted). HPGL names the plot extents as P1 (the lower-left corner) and P2, the upper-right corner.

Reading An HPGL Plot File

A typical HPGL plot file consists mostly of ASCII characters with some control codes thrown in. You can read the file with any text editor. Since the plot files tend to be written as one long line (no CR or LF), it is helpful to have a text editor with no limitation on line length.

To produce a sample HPGL file, configure a CAD package to plot to file using an HPGL driver (possibly called "HP Plotter" or given a specific model number, such as HP7220 or HP7586). Create a very simple drawing (a couple of lines), then plot the drawing to disk. When you load a plot file into the text editor, it looks something like this:

Plot initialization data:
[Esc].(;.I81;;17:[Esc].N;19:IN;SC;PU;PU;SP1;LT;VS36;

Plot data:
PA12345,4567;PD;PA-2345;6789; ...et cetera

Plot termination data:
PU;PA0,0;SP;EC;PG1;EC1;OE;

Decoding the HPGL Code

HPGL consists of two kinds of instructions:

The most typical HPGL instruction is:

PA1234,5678;
The PA instruction moves the pen to absolute position (1234,5678) in plu coordinates. The instruction has four parts to its syntax: PA is an HPGL command (in this case, to move the pen).

  • 1234 and 5678 are parameters (in this case, absolute coordinates).
  • , a separator (the comma) between two or more parameters.
  • ; and a terminator (the semi-colon).

    PA All HPGL instructions start with a two-letter mnemonic. For example, PA is the abbreviation for Pen Absolute, a pen positioning command. Other common command mnemonics include:

    1234 and 5678 Most HPGL instructions include one or more parameters to modify their meaning. Here, 1234 and 5678 are the absolute pen coordinates in plu. Parameters of other instructions are the pen number and plotter speed.


    TIP: To use the default parameter of an instruction, simply leave out the parameter value.

    , (separator) When an instruction uses more than one parameter, HPGL wants them separated with:


    TIP: HP recommends use of the comma as the separator; only use the negative sign with negative values.

    ; (terminator) To indicate the end of the instruction, you have the option of using a semi-colon ( ; ) or nothing at all.


    TIP: Use the semi-colon when you want to make the plot file legible to humans; use no terminator to significantly reduce transmission time and file size.

    Device-Control Instructions

    HPGL uses device-control instructions to set up the plotter's hardware. These instructions set up communications between the CAD software and the plotter, return plotter status data, reset the plotter, et cetera.

    Device-control instructions (DCI, for short) begin with the escape character (ASCII 27, or 1B in hex) shown as [Esc] in this tutorial. Text editors often show Escape as a left arrow ( <- ) or as Ctrl-Bracket ( ^[ ). A typical HP device-control instruction looks like this:
    [Esc].N0;19:

    The purpose of this DCI is to specify the Xoff (short for transmission off) trigger character, which tells the plotter which ASCII character the CAD software expects to receive as the Xoff character, as follows:

    Initializing the HPGL Plot File

    A typical HPGL plot file consists mostly of ASCII characters with some control codes thrown in. The plot initialization data (in this case, generated by AutoCAD R11) looks something like this:
    [Esc].(;[Esc].I81;;17:[Esc].N;19:IN;SC;PU;SP1;LT;VS36;

    To make it easier to read, letūs reformat the data with one instruction per line:
    [Esc].(;
    [Esc].I81;;17:
    [Esc].N;19:
    IN;
    SC;
    PU;
    SP1;
    LT;
    VS36;

    [Esc].(; instructs the plotter to interpret data as HPGL and DCI instructions, rather than plotting the data stream as literal text characters. This DCI has no parameters; [Esc].Y is an alternative provided by HPGL.

    [Esc].I81;;17: sets the parameters for Xon-Xoff handshake mode, with the following parameters:

    [Esc].N;19: was described earlier.

    IN; (INitialize) Resets most of the plotter's functions to default settings, some of which follow:


    TIP: Settings made on the plotter's front panel are not reset.
    TIP: Recall that the semi-colon ( ; ) terminator is optional.

    SC; (SCale) Scale the coordinate system to the plot's extents, P1 and P2; the default is no scale (the CAD software handles the scaling).

    PU; (Pen Up) Lifts the pen; optionally moves the pen to a new location.

    SP1; (Select Pen) Selects a pen, #1 in this case.


    TIP: HPGL automatically returns the current pen to its holder at the end of a plot.

    LT; (Line Type) Selects the linetype and pattern length; the default is continuous lines (the CAD software handles the linetype generation).

    VS36; (Velocity Select) Selects the pen speed in cm/sec; optionally selects the pen by number.


    TIP: The pen speed is sometimes overruled by the setting of the pen carousel. HP suggests using a slower speed to create a slightly thicker line (but at the expense of longer plot time).



    © Copyright 1994-1995 Automata, Inc.
    Last modified: February 19, 1996