HP-GL is the language of Hewlett-Packard’s pen plotters; HP-GL/2 is its successor for plotters and printers, and is also built into PCL 5. HP-GL/2 is defined in HP’s The HP-GL/2 and HP RTL Reference Guide, which this page follows; HP-GL was described in each plotter’s programming manual. A plot file is the stream of instructions a program sends to the plotter.
Instructions
An instruction is a two-letter mnemonic, optional parameters, and a terminator:
PA 1000,2000; PD3000,2000,3000,4000; LBHello<ETX>
(<ETX> stands for the single byte 0x03.)
- Mnemonic: two letters, written in upper case.
- Separators between parameters: a comma (recommended), a space,
or, for numbers, a
+or-sign starting the next one.DT,LB,PEandSMtake no separators. - Terminator: HP recommends none: the next mnemonic ends the
instruction (
PDPU10,20). A semicolon, or any non-numeric character, also ends one.PEandPGand the output instructions must end with a semicolon,LBends with the label terminator, theCOtext is in double quotes, and a semicolon is required after the last instruction before leaving HP-GL/2. - An optional parameter can only be left out together with all the parameters
after it (
DTis the exception).
Parameter types
| Type | Range in HP-GL/2 | Notes |
|---|---|---|
| Integer | −8,388,608 to 8,388,607 (±223) | A fraction is rounded to the nearest integer; values outside may give unexpected results. |
| Clamped integer | −32,768 to 32,767 | Values outside are clamped to the limits; some parameters allow less. |
| Real | −8,388,608.0000 to 8,388,607.9999 | At least six significant digits; the decimal point may be left out; no exponent form. |
| Clamped real | −32,768.0000 to 32,767.9999 | As above, clamped. |
| Label text | any characters | Up to the label terminator: ETX (0x03) by default, changed with DT. |
| Quoted string | text in " | Used by CO and BP; "" is a quotation mark inside it. |
These ranges are minimums; a device may accept more. Coordinates are in current units: user units when scaling is on, plotter units when it is off.
Units and coordinates
- The plotter unit is 0.025 mm: 40 to the millimetre, 1,016 to the inch. Unscaled coordinates are in plotter units.
- The origin is a corner of the plot area that depends on the device; in PCL 5 printers it is a corner of the PCL picture frame.
- P1 and P2 are two scaling points. On printers they default to
the lower-left and upper-right corners of the hard-clip limits (the physical
boundary of printing); on plotters the defaults depend on the device.
IPandIRmove them. - User units:
SCmaps P1 and P2 to user coordinates, so drawing commands can use any units; withSCoff, plotter units apply. ROrotates the coordinate system by 90° steps;IWclips to a window.- Pen widths and some sizes are in millimetres or as a percentage of the P1–P2
diagonal, as set by
WU.
PE: polyline encoded
HP-GL/2’s PE instruction packs a run of coordinates into printable
characters, about half the size of plain numbers. After PE come flags
and numbers, up to ;:
| Flag | Meaning |
|---|---|
: | Select pen: the next number is a pen number. |
< | Pen up: move to the next pair with the pen raised (in rectangle mode, also return to line mode). |
> | Fractional data: the next number gives how many binary fraction bits the coordinates have (default 0). |
= | The next point is absolute; others are relative to the previous point. |
7 | Seven-bit mode: numbers use base 32 rather than base 64 for the rest of the instruction, and eighth bits are ignored. |
9 | Rectangle mode: each following quadruplet is a pen-up move and then a relative rectangle filled with the current fill type. |
Each number is encoded as follows. A signed value v is first made
unsigned: 2v if positive, 2|v| + 1 if negative (the sign goes in
the lowest bit). It is then written in base 64 (or 32), least significant digit
first. In base 64, every digit but the last is the byte 63 + d (63–126) and
the last is 191 + d (191–254). In base 32 every digit but the last is
63 + d (63–94) and the last 95 + d (95–126). For fractional
data the value is first multiplied by 2n and rounded, where
n is the number of fraction bits given by >. Flags are
plain characters (their eighth bit is ignored); numbers after : and
> are encoded like coordinates. Coordinates come in x, y pairs, with
the pen down unless < precedes the pair.
What a file looks like
- A plot normally starts by setting known conditions with
IN(all defaults) orDF(most defaults), then selects a pen withSP. - On devices with the Technical Graphics extension, a plot starts with
BP, which also performsIN;MT,PSandQLmust come in this picture header, before any drawing. A picture ends atPG,RPor the nextBP. - In a PCL 5 job,
Esc%0BorEsc%1Benters HP-GL/2 andEsc%0AorEsc%1Areturns (see the PCL page). Devices with HP RTL use the same commands to switch between vector and raster data.
Sources
- HP, The HP-GL/2 and HP RTL Reference Guide (third edition, 1997) – HP-GL/2 syntax, parameter formats, units of measure, the PE instruction and its encoding, the picture header
- HP, PCL 5 Printer Language Technical Reference Manual, part II (bpl13211) – HP-GL/2 inside PCL 5