[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PostScript font installation: my evolving tools...

Over the Christmas break, I've written two Perl modules, GlyphEncoding.pm
and FontMetrics.pm that provide support for generating font metrics for
use in TeX. Some might claim that in doing so, I've been yet another
person to re-invent this particular wheel, but on the other hand, I'm
not able to take over the maintenance of fontinst, in part because I
don't really understand its internals, but also because I use TeX for
typesetting, not for programming, and want to keep it that way.

I've endeavoured to write something that's both sensible and extensible,
but my aim initially has been to create something that meets my own
needs, so currently virtual font support is fairly primitive (all we
have right now is the ability to combine the glyphs from several fonts,
but no glyph faking yet -- I think I might well turn out to be ideologically
opposed to glyph faking in a virtual font anyway; it seems to me like
it is better to do that sort of thing in TeX instead -- then again, I've
been thinking lately that if you're using PostScript fonts, maybe you
shouldn't care at all for the T1 encoding; if you do want to use the T1
encoding, glyph fakery becomes important).

On the other hand, some of the improvements in my code are the ability
to cope with decimals in AFM files, and some pretty comprehensive code
for generating LIGTABLE entries.

Right now, code to use my modules looks like this:
    use GlyphEncoding;
    use FontMetrics;
    $ly1 = GlyphEncoding->newFromFile("texnansi.enc");
    $tir = FontMetrics->newFromAfmFile("tir.afm")->setEncodingTo($ly1);

In the above code, $ly1 is a GlyphEncoding object and $tir is a FontMetrics
object. As an aside, if we rand this code, we'd get the following (mostly
harmless) output on STDERR:
    Missing glyph 'cwm' for TeXnANSIEncoding[10]
    Missing glyph 'ff' for TeXnANSIEncoding[11]
    Missing glyph 'ffi' for TeXnANSIEncoding[14]
    Missing glyph 'ffl' for TeXnANSIEncoding[15]
    Missing glyph 'dotlessj' for TeXnANSIEncoding[17]
    Missing glyph 'nbspace' for TeXnANSIEncoding[160]
    Missing glyph 'sfthyphen' for TeXnANSIEncoding[173]
    I had to round some heights by 15.0000000 units.
    I had to round some depths by 16.0000000 units.

For the moment my code doesn't support reading metric information from
anything other than an AFM file. I could write something that would read
PL files, but I know I wouldn't be happy unless my PL file parser could
understand TeX LIGTABLES completely (including reading SKIP entries,
since my code will actually write SKIP entries if necessary), and that
seems like a hellish job. Since there are AFM files for Computer Modern,
this shouldn't be too much of a concern anyway.

However, there are various `little things' that I'd like to get right,
and haven't been able to figure out by myself. One is what the best way
to calculate the font dimensions SPACE, STRETCH, SHRINK, and EXTRASPACE,
since it seems to me that different utilities work out these parameters
using different formulas, and none of them seemed to correspond to the
values suggested in my copy of _Elements of Typographic Style_. Currently
I do something like:

    if ($metrics->hasGlyph('space')) {
	$spacewidth = $metrics->width('space');
    } elsif ($metrics->hasGlyph('m')) {	# Use value from char
	$spacewidth = $metrics->width('m') / 4;
    } else {				#    ^--- should this be 3?
        ... panic ...

... to figure out the value for SPACE and set STRETCH and SHRINK to
$spacewidth * 3/5 and $spacewidth * 5/21 respectively, which from looking
at the output (and not the code) of fontinst, seems to be the values
fontinst uses. For comparison I've listed below the values used by
other tools:

  fontinst	$spacewidth * 3/5 	$spacewidth * 5/21	(??)
  CMR10/MF	$spacewidth * 1/2 	$spacewidth * 1/3
  afm2tfm	$designunits * 1/5	$designunits * 1/10
  Y&Y's TFMs	$designunits * 4/25	$designunits * 11/100	(??)
or, seen as values (assuming $designunits = 1000):

  fontinst	200			79
  CMR10/MF	166.667			111.111
  afm2tfm	200			100
  Y&Y's TFMs	160			110

Also, I was working on something that added the necessary left and right
sidebearings to letters make a set of letters suitable for math (OML),
but looking at zrmhax.mtx in the fontinst distribution didn't prove very
useful. It just hardcodes a bunch of values, like this:


... which didn't seem a very satisfactory solution -- ideally I'd like to
have an algorithm to do this.

If people are interested, I could put my preliminary code up on my web
site so you can play with them... (be warned that you'd need a very
recent Perl version before you can run my code).

Opinions and advice welcome,


P.S. With where my tools are at now, I can use them for most tasks.
I've built a set of virtual fonts for use with Kepler, for example,
that provide the expert ligatures and oldstyle digits, and used them