Pre-announce: GraphicFont

	A common complaint I have heard from Java developers is
that the number of fonts available to them is pitiful. I've made
a hack to help alleviate this problem and am letting the developer
community know before I polish things up.
	Here is the story:

        A few months ago, a number of designers, developers, and
typographers got together to discuss how to solve the font problem
on the Web. This group is trying to figure out how we can make quality,
platform-independent fonts available for designers, developers, and
artists on the Internet that use the Web as a communications medium.
(see http://fonts.verso.com/).
	One idea that stuck in my mind was Paul Haeberli's font
bitmap scheme, where the font would be encoded in an image, and you
could just split it up and use it as any other bitmap font.
	I started learning Java last month, and let me tell you, to me
it's just like being on the Web all over again! Once upon a time I was
going to learn X/Motif, or tcl/tk, or C++ on the Mac, or something with
a godawful learning curve. But already I've made quite a few nifty
Java hacks, and never having programmed any real GUI code before,
my eyes are opened.
	One of the first Java barriers I came up against was the fact
the developers only have a choice of three or four internal fonts:
Times, Helvetica, and a system (monospaced, I think) font. Frankly, they
suck, and doing Java things with those fonts is not inspiring at all,
and any applet you see out there just looks like bad HTML extensions,
since everything uses the same fonts. Also, if you specify certain fonts
in Java, they end up looking slightly *different* on different platforms.
This is no good.
	Well, I've hacked a solution, and I've got working code!
	Basically, I've made a near drop-in Java Font/FontMetrics class
replacement, a little class that anyone can incorporate into their Java
app/applet. I call the class "GraphicFont".
	Here's how it works:

	1. A bitmap font at a certain size is encoded into the
	   GraphicFont format. Basically, this means going into
	   a program like Photoshop and typing out all the letters in
	   the font in a strip. You could include international characters,
	   etc. but for now I'm only using standard U.S. keyboard chars.

	   The letters are separated by vertical lines, and leading,
           descent, ascent, etc. information is encoded as RGB values in
	   the upper left corner of the image. It doesn't know anything
	   about kerning, since I don't know how to implement it.

	   The image is saved as a GIF, so it ends up being pretty small.
	   For instance, a 48-point font is about 9k, and 12-point fonts
	   are usually around 1k.

	2. In a Java program, the font image is completely loaded first.
	   It may be grabbed over the net, cached locally, or what have you.

	   A GraphicFont object is created and initialized with an
	   Image object as a parameter.

	3. Now you can do all sorts of things - there is a function in
	   which you can specify a string, and it returns a transparent image
	   of the string rendered in the particular font.

	   You can also set the font drawing color, background color,
	   get and set various font metrics (it provides the functionality
	   of Java's FontMetrics, basically), and so on.

	   Programmers can cache these rendered images for better performance,
	   or do anything you normally can do to a bitmap: rotation, scaling,
	   and so on. I have made some preliminary image transformation
	   code (such as scaling with smoothing using bilinear mapping and
	   other techniques), but I'd ultimately like to see something like
	   netpbm for Java developers...

	Here is the neat thing: You can finally make antialiased fonts!
*No more jaggies!* Although non-antialiased fonts will work just fine,
you can make the characters antialiased in the image and maintain
transparency against arbitrarily complex backgrounds although the quality
is rough.
	But you can specify a certain foreground and background color for
the font, and all the antialiased colors will be remapped correctly, making
it all look great.
	I am using GraphicFont in some of my applets, and strings are
rendered fairly quickly. There are a few factors affecting speed
(string width, font size, etc.) but I expect that via better bit manipulation
techniques I can make it faster.
	From the quick demo I've put together, everything looks beautiful.
I am tempted to never go back to HTML again.
	So this is a heads-up as to where I am regarding fonts. My best
hope is that this will change the look of things for the better and
make Java more widely regarded.

	Here are some issues I'm working on:

	1) So far I've made fonts of Gill Sans and Gill Sans Bold in
	   various sizes and am planning to make many more. What is the
	   legality of using Adobe bitmaps for this project? What about
	   using fonts like Arial, Espy Sans/Serif, Garamond?

	   I am planning, BTW, to make this code and technology
	   freely available for any use.

	2) I think this would be a good vehicle for getting free, nicely
	   rendered bitmap fonts onto the net. Does anyone have some
	   quality fonts they'd like to donate?

	3) How can I support things like kerning? Is it worth going
	   that extra mile? What about internationalization?

	4) I'd like to do things like use GraphicFont with the JDK 1.0
	   HTML parser and write functions that render blocks of text.
	   Do you see where I'm heading? How fast would it work in HotJava?

	5) I want to use the GIF comment area for copyright/author/
	   distribution information. This can make it very easy for
	   developers and users to find out where a font came from,
	   who to contact, etc. but I need Java code that will
	   extract a GIF comment.

	6) If I could get GIF-writing Java code, I could make a convertor
	   to make the font-encoding process a lot easier, and almost
	   entirely automatic.

	7) Of course, this is all a temporary hack until real scalable fonts
	   are done. But anything is better than what's out there now.
	   And this works, now.

	Needless to say, after having dealt with the same half-dozen fonts
on the Web for over three years now, I am excited!
	Everything is in a rough state but time willing I will have
everything up online and downloadable with a small font library and
a polished demo or two within one to two weeks.
	Stay tuned,

	-- Kevin

--
Kevin Hughes * kevinh@eit.com
Enterprise Integration Technologies Webmaster (http://www.eit.com/)
Hypermedia Industrial Designer * Duty now for the future!

Received on Monday, 19 February 1996 03:39:34 UTC