Lightsaber Computing

Java 2D PostScript Text

Synopsis - what this project is about.
PSGraphics2D - Graphics2D subclass for PostScript.
Comparison - this project vs. Java 2D printing.
Source code hosted at
SourceForge Logo


Java 2D PostScript Text builds on the Java 2D Graphics2D class to generate PostScript code for text-intensive, global printing applications. This includes support of CID fonts for multi-lingual printing.

It is part of a larger Lightsaber Computing multi-lingual computing initiative known as Project 3PO.

The project summary page for the source code can be found on Source Forge.


2000 Aug 6 - Initial tarball java2d-pstext-0.1.tar.gz has been released on Source Forge.

2000 Aug 4 - Project has been registered on Source Forge. No code has been copied to the site yet. Project info is being written.

The PSGraphics2D class

At present, effort is focusing on PSGraphics2D, an extension/subclass of the Graphics2D class, found in the Java 1.2 Standard Edition JDK/JRE. The parent class includes font and image manipulation, in addition to rendering of text; in these areas, PSGraphics2D doesn't come anywhere near its parent. This is an issue which will have to be addressed as the class implementation matures.

The current implementation of PSGraphics2D takes advantage of an earlier effort by Lightsaber Computing, aimed at solving a set of technical problems posed by clients of the company, particularly in dealing with multi-lingual printing.

Graphics2D is a general purpose 2D rendering API intended for display or printing. The API is sufficiently rich that it covers most of the capabilities that the Lightsaber Computing rendering library was aimed at. The API is being widely accepted; it there made sense to take the rendering library and match it to the API.

However, Graphics2D goes far beyond simply rendering text. The involved technologies are sufficiently diverse and complex that Lightsaber Computing has chosen to manage the effort as an open source project.

Comparison to Java 2D Printing

Although Java 2D is able to generate PostScript code, each glyph in a line of text seems to be rendered by PostScript graphics operators. In essence, the resulting PostScript file has no text in it.

PSGraphics2D assumes that the output will be sent to a PostScript rendering engine, such as a laser printer or software package such as PostScript.

To compare the text rendering capabilities of the two, one can look at the PostScript output which was generated by each for rendering the string "Hello, World!":

The PostScript generated by PSGraphics2D is clearly smaller. However, the issues are not so simple.

The advantages of the native Java 2D solution are that:

  • there are no unresolved questions about how the glyphs will look. Everything has been predetermined by the graphics operators.
  • it doesn't depend on fonts loaded in the target printer.

The disadvantages are that the resulting file:

  • is EXTREMELY large, and may overflow some print spoolers.
  • is not searchable. The text which was rendered will not show up in the file.
  • uses unhinted glyphs. At lower resolutions, e.g., on desktop displays, characters of increasing complexity are harder to read.

By contrast, the PSgraphics2D class takes the traditional PostScript printing approach, assuming that the fonts are loaded into the printer. The potential problems which plague this, and every PostScript generator are:

  • the true metrics of fonts in the printer may not match the font metrics available to the software.
  • the fonts may not exist in the printer at all.

The advantages are that the resulting output:

  • uses the actual text, and is therefore searchable.
  • lets the rendering engine handling hinting.
  • can be compact in size.