Jim Buzbee's Hershey Font Page
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.
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