next up previous contents index
Next: Font Subsetting Up: Missing or Invalid AFM Previous: Generation of AFM Information   Contents   Index


Writing AFM Files

In order to reduce the situations where AFM data has to be generated on the fly, t1lib provides the following function:

 int T1_WriteAFMFallbackFile( int FontID)

to 0pt It writes an AFM file for the font identified by FontID. This is done executing the following steps:
  1. The AFM filename is constructed by taking the fontfilename, cutting off the extension and appending .afm.
  2. A pointer array of size , where , is allocated and set to NULL. The leading 256 entries are reserved to point to encoded characters' metrics. The remaining entries are intended to point to metrics of unencoded characters. We see that this is a worst case speculation: The pointer array is large enough for the extremely unusual case that no characters are encoded.
  3. Next the function steps through all character names and gets their encoding index . If , the character is encoded and the th pointer element in the array is set to point to the metrics of this character. If , the character is not encoded and the lowest unused pointer in the second area is set to point to the metrics of this character.
  4. Next the AFM file is opened and the header information as well as a comment by t1lib are written. There are 5 entries that are not trivially to extract from the font file: Ascender, Descender, XHeight, CapHeight and EncodingScheme. Their discussion is deferred to later in this section.
  5. After the header, the metrics information is written in the format required for AFM files. This is done by stepping through the pointer array until the first NULL pointer in the unencoded characters' area is reached.
The result is a list of char-dimensions entries which is leaded by the encoded characters in ascending order of their encoding index, followed by a list of unencoded characters in alphabetical order.

As seen above, the current encoding takes influence on the order the characters appear in the AFM file. One should thus not produce AFM files from reencoded fonts, although this is possible. This yields non-standard AFM files and gives no performance gain, even not when used with t1lib.

The entry EncodingScheme is not always contained in the fontfile itself. It is generated by comparison between encodings. t1lib has only one builtin encoding, AdobeStandardEncoding, which is recognized. Every further encoding, defined by the font itself or applied by a user, is always marked as FontSpecific.

The entries CapHeight, XHeight Ascender and Descender are not fully determined by a Type 1 font file although they are existent with high probability. As rough definitions can be considered:

It is obvious that these definitions make only sense in certain font definitions. For example, a musical notation font might not necessarily define an ascender since no capital letters are provided.

In the Type 1 notion these dimensions are referred to as top alignment and bottom alignment values respectively. The corresponding alignment ``zone'', i.e., an interval, is defined by the alignment height and a corresponding overshoot position. The alignment zones are specified in the BlueValues array for top alignment zones and the OtherBlues array for bottom alignment zones. A Type 1 font may define up to 7 top alignment zones and 5 bottom alignment zones. It is unfortunately not defined which of these alignment zones refer to CapHeight, XHeight, Ascender and Descender.

t1lib tries to get out of this dilemma by making a best guess:

  1. For each of the characters `H', `x' and `d' it fetches the largest y-value and compares the result with each alignment zone in the BlueValues array. The alignment zone closest to the observed character dimension is assumed a candidate for the respective quantity.
  2. It checks whether the difference between the alignment zone just selected and the character dimension is within a certain tolerance area. This tolerance width is charspace units. If the result is positive, the quantity in question is assigned the numerical value of the standard height (not the overshoot) of this alignment zone. Since we are currently considering top alignment zone, this will always be the lower value.
  3. If the value is out of tolerance or the font even does not define the character, the corresponding entry in the AFM file is left out.
  4. A comparable procedure is then done for Descender, this time examining the OtherBlues array.
Note that if the values do not seem to be correct, the corresponding lines can be removed from the AFM file without doing any harm. These entries are optional only.

T1_WriteAFMFallBackFile() can indicate a number of error conditions by returning appropriate values. These are:


next up previous contents index
Next: Font Subsetting Up: Missing or Invalid AFM Previous: Generation of AFM Information   Contents   Index
2005-01-12