Jim Buzbee's Hershey Font Page

This is an implementation of the Hershey Font set for Java. The HersheyFont class has methods for loading a specifed Hershey font across the net so that there is no dependency on installed fonts. You can set character string rotation, horizontal alignment, vertical alignment, character width, character height, font line width, italics, and degree of italic slant.

Here's a pre-alpha font editor for Hershey Fonts

Release : 1.4, Dated Aug 13, 2000, Copyright (c) Jim Buzbee.

Here are some examples of drawing with the HersheyFont class :

If you had a Java enabled browser, you would see my demo now !

The Gothic fonts are a bit slow ( at least on my machine ). The others render fairly quickly.

The effort was pretty much a totally new implementation of hershey font rendering, but I started with various pieces of code written in FORTRAN and C. The original authors were listed as : Alan Richardson, Pete Holzmann, and James Hurt.

If you want to use the class, I have everything you need wrapped up in a gzip'ed tar file .
Note that I retain the copyright for my code and classes, but you may feel free to use it for any purpose. See the file test.java for an example of how to use the routines.

Here is a quick look at the class :

Two constructors :

HersheyFont( String fontFileName ) 
Where the file name of the font is passed in.  Not usable in an applet.

HersheyFont( URL base, String fontName ) 
Normal use : HersheyFont font = new HersheyFont( getCodeBase(), "romand.jhf");

And the public methods :

public void drawString( String text, int x, int y, Graphics g ) 
Draws the specified string at the specified location, using the current
font attributes. 

public void setRotation( double theta )
Sets the rotation angle attribute for the font.

public void setWidth( float width ) 
Sets the font width.  "Normal" is 1.0, negative numbers flip the characters.

public void setHeight( float height )
Sets the font height.  "Normal" is 1.0, negative numbers flip the characters.

public void setLineWidth( int width )
Sets the line width for drawing the fonts.  The value is in pixels and has a
default value of 1.  This should be used sparingly, as it degrades performance.
Large values also don't look so great, as many of the vectors in the 
characters are short.

public void setItalics( boolean flag ) 
Sets the italic flag of the font.  Purists might argue that my 
implementation is just a "slant" of the characters and not a true
italic font, but it's something..

public void setItalicsSlant( float slant ) 
Sets the slant factor when using italics.  A "normal" italic font would have
a value of around 0.75, anything over 2 gets very hard to read.  Negative
values cause the font to slant backwards.

public void setVerticalAlignment( int alignment ) 
Sets the vertical alignment for the font. Legal values are :

HersheyFont.VERTICAL_TOP      ( align at the character top )
HersheyFont.VERTICAL_HALF     ( align at the character half point )
HersheyFont.VERTICAL_CAP      ( align at the character cap )
HersheyFont.VERTICAL_BOTTOM   ( align at the character bottom, default )
HersheyFont.VERTICAL_NORMAL   ( default ( Bottom )  )

public void setHorizontalAlignment( int alignment )
Sets the horizontal alignment for the font. Legal values are :

HersheyFont.HORIZONTAL_CENTER   ( Center justification )
HersheyFont.HORIZONTAL_LEFT     ( Left Justification, normal )
HersheyFont.HORIZONTAL_RIGHT    ( Right justification )
HersheyFont.HORIZONTAL_NORMAL   ( Normal ( Left ) justification, default )

public String getName( )
Gets the name of the font

Version 1.4 has a work-around for a J++ bug (Thanks to Paul Emory Sullivan )

Version 1.2-13, unreleased

New for version 1.1 of the HersheyFont class : A couple of minor bug fixes, a new method for getting the name of a font and quite a few new fonts that I found scattered about. Some of the fonts look very similar to others, but by viewing their source it appears that they have been "tweeked" along the way so I left them all in. I tried to keep their names close to what they were, but I added a ".jhf" (Java Hershey Font) extension to all of them for consistancy. There may still be other Hershey fonts lurking around out there. If you spot one, let me know !

Here's a sample of the characters in the fonts at half size. All of the fonts are included in the above file.

Any Questions comments or problems, Drop me a line

I've got some other Java pages

Jim Buzbee jbuzbee@nyx.net