HPGL Import

Author: Ulf Dittmer

Date:3/4/2006

Description: This plugin imports HPGL (Hewlett Packard Graphics Language) files, which were used mostly for driving pen plotters before the advent of laser printers and PostScript, but still aren't uncommon in scientific and engineering applications today.

Installation: You can download the source file HPGL_Reader.java and compile it using the "Compile and Run" command, or download the class file HPGL_Reader.class and put it into the plugins folder. After restarting ImageJ, it should show up in the plugins menu.

Supported commands: The plugin supports the following HPGL commands. If you find some features that are not available or seem buggy, send me the file in question and the expected image, and I'll see what I can do.

  • IN - initialization
  • PA - plot absolute
  • PR - plot relative
  • PU - pen up
  • PD - pen down
  • CI - draw circle
  • LB - draw text
  • BL - buffer label
  • PB - print buffered label
  • SI - set text size
  • SR - set text size relative
  • DT - set text termination character
  • SP - select pen (i.e., color)
  • PW - set pen width
  • SC - set scale
  • IP - set reference points for scaling
  • DI - set text rotation
  • LT - select line type (dotted, dashed etc.)

Notes and Limitations: ImageJ's Undo and Record functionalities are supported.

In keeping with HPGL, an output format of A4 landscape is assumed. By setting "isA4" to false in the source code, A3 can be chosen. In macro mode, this can also be done by setting a parameter: "a4=false".
If no image is open, a new one will be created; otherwise the contents will be overlayed on top of whatever the image contains. This has the benefit that several files can be imported successively, and that externally generated HPGL (e.g. from gnuplot or a GUI drawing application) can be added to an existing image.

The Java2D features are rather slow, due to a lot of image copying back and forth between ImageJ and Java2D images. But they're only used if absolutely necessary, e.g. if text really is at a non-zero angle, or lines really aren't supposed to be solid. In macro mode those features can be turned off by using "usejava2d=false" as parameter.

The results of using the plugin aren't pixel-by-pixel copies of what a real plotter would generate. In writing it I perused several HPGL-reading source codes and descriptions found on the Internet, but the closest I found to a reference was this page.

I don't know if there are standard sequences of colors and line dash patterns which are selected by the SP and LT commands, so I came up with my own. They can be changed easily by adapting the cmap and dashvalues arrays in the source code. Dash patterns in particular are explained in the docs of the Dotted Line plugin (which also served as inspiration for the Java2D features).

Changes: January 2004
  • Initial version
  • Version 2: added support for scaling (IP and SC commands)
March 2006 - version 3
  • The parameters of the PW command no longer have to be integers - they're rounded if necessary (thanks to Sue Smith for bringing this to my attention).
  • More accurately modeled line type patterns
  • Implemented BL and PB commands


Back To ImageJ Plugin Page | Back To Home Page