Font Classes

Robert Miner thought of this one. It's pretty slick.
  1. If you have a local installation of IDVI, then your browser should never need to download the IDVI classes over the network. This is because the browser will load classes which are in its CLASSPATH in preference to the version on a remote machine. Unfortunately, there is currently no way to make files other than classes available in the CLASSPATH. This precludes using local fonts, and means that you must always download font files over the web.

  2. The trick is to write a class which stores fonts as static final data. In order to load only those fonts which are needed, we need a separate class for each font file. Encode the pk font file into a static final String, since this is the only form of static final data which does not incur overhead in the class file format. It is safe to use all 65536 possible character values, since Strings are stored with a separate length. Of course the string constant looks very large in the source file when encoded this way, since almost every character will be a \uHHHH hex escape. But it will compile to a file only marginally larger than the original pk font file.

  3. Write a tool to convert binary data files into java source files with static final Strings. Go ahead and make it an 80 column text file, since the compiler will silently convert "..." + "..." + "..." spread over many lines into a single string constant in the class file.

  4. Define a package idvi.font.cache. Write a tool which will automatically generate a class named after a font, which encodes the corresponding pk font file. Modify idvi.font.DVIFont to first look for a font class file (using Class.getClassByName( )), and create an InputStream from the final String data in the font class file if it exists.

  5. Make a separate release consisting of 4 Megabytes of the "usual" fonts, with a makefile which will install the font classes into an existing IDVI installation. Note that IDVI only uses fonts rendered to a single screen resolution (usually 300dpi), so that there is no need for 600 or 144 or 360 or 1440pt fonts. (The Geometry Center manages to have 50 Megabytes of fonts, somehow!)