Glyph Bitmap Distribution Format
Template:Short description The Glyph Bitmap Distribution Format (BDF) by Adobe is a file format for storing bitmap fonts. The content takes the form of a text file intended to be human- and computer-readable. BDF is typically used in Unix X Window environments. It has largely been replaced by the PCF font format which is somewhat more efficient, and by scalable fonts such as OpenType and TrueType fonts.
Overview
In 1988, the X Consortium adopted BDF 2.1 as a standard for X Window screen fonts,[1] but X Window has largely moved to other font standards such as PCF, Opentype, and Truetype.
Version 2.2 added support for non-Western writing. For example, glyphs in a BDF 2.2 font definition can specify rendering from top-to-bottom rather than simply left-to-right.
A BDF font file contains three sections:
- a global section that applies to all glyphs in a font;
- a section with a separate entry for each glyph; and
- the <syntaxhighlight lang="text" class="" style="" inline="1">ENDFONT</syntaxhighlight> statement.
Example
This is an example font containing one glyph, for ASCII capital "A". This glyph is taken from the GNU Unifont.
Template:Col-2Template:SxhlTemplate:Col-end
STARTFONT 2.1 FONT -gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1 SIZE 16 75 75 FONTBOUNDINGBOX 16 16 0 -2 STARTPROPERTIES 2 FONT_ASCENT 14 FONT_DESCENT 2 ENDPROPERTIES CHARS 1 STARTCHAR U+0041 ENCODING 65 SWIDTH 500 0 DWIDTH 8 0 BBX 8 16 0 -2 BITMAP 00 00 00 00 18 24 24 42 42 7E 42 42 42 42 00 00 ENDCHAR ENDFONT |
In the above example, the global declarations begin with the <syntaxhighlight lang="text" class="" style="" inline="1">STARTFONT</syntaxhighlight> line and end with the <syntaxhighlight lang="text" class="" style="" inline="1">CHARS</syntaxhighlight> line.
<syntaxhighlight lang="text" class="" style="" inline="1">STARTFONT 2.1</syntaxhighlight> defines the version of this BDF file as version 2.1.
<syntaxhighlight lang="text" class="" style="" inline="1">FONT -gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1</syntaxhighlight> defines the font family and face names as an X logical font description.
<syntaxhighlight lang="text" class="" style="" inline="1">SIZE 16 75 75</syntaxhighlight> defines this to be a 16 point font, with an X-axis resolution of 75 dots per inch (dpi) and a Y-axis resolution of 75 dpi. This is the norm under X Window.
<syntaxhighlight lang="text" class="" style="" inline="1">FONTBOUNDINGBOX 16 16 0 -2</syntaxhighlight> defines a bounding box for the font of 16 pixels wide by 16 pixels high, with the lower left-hand corner starting at Template:Math and Template:Math. Note that although the bounding box is defined to be a 16 by 16 cell, this can be overridden for individual glyphs. The "A" glyph, for example, is only 8 pixels wide.
<syntaxhighlight lang="text" class="" style="" inline="1">STARTPROPERTIES 2</syntaxhighlight> declares that two special properties will follow. <syntaxhighlight lang="text" class="" style="" inline="1">STARTPROPERTIES</syntaxhighlight> is optional in the BDF specification. X Window allows the properties <syntaxhighlight lang="text" class="" style="" inline="1">FONT_ASCENT</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">FONT_DESCENT</syntaxhighlight> to show the height above and below the baseline, respectively, for all glyphs. <syntaxhighlight lang="text" class="" style="" inline="1">FONT_ASCENT 14</syntaxhighlight> declares that 14 of the 16 pixels in height are above the baseline. <syntaxhighlight lang="text" class="" style="" inline="1">FONT_DESCENT 2</syntaxhighlight> declares that 2 of the 16 pixels in height are below the baseline. <syntaxhighlight lang="text" class="" style="" inline="1">ENDPROPERTIES</syntaxhighlight> appears at the end of the <syntaxhighlight lang="text" class="" style="" inline="1">STARTPROPERTIES</syntaxhighlight> section.
<syntaxhighlight lang="text" class="" style="" inline="1">CHARS 1</syntaxhighlight> declares that one character will follow. Although Adobe now refers to this file format as the Glyph BDF, they have retained the keyword <syntaxhighlight lang="text" class="" style="" inline="1">CHARS</syntaxhighlight> in the final version of the specification.
Lines beginning with the word <syntaxhighlight lang="text" class="" style="" inline="1">COMMENT</syntaxhighlight> can be inserted within a BDF file. Anything following the <syntaxhighlight lang="text" class="" style="" inline="1">COMMENT</syntaxhighlight> keyword on a line is ignored.
Following the above global declarations, the following entries may repeat for each glyph.
<syntaxhighlight lang="text" class="" style="" inline="1">STARTCHAR U+0041</syntaxhighlight> specifies the start of a character in version 2.1 and earlier, or of a glyph in version 2.2. The string name of this particular character is <syntaxhighlight lang="text" class="" style="" inline="1">U+0041</syntaxhighlight>, expressing in the Unicode convention the code point hexadecimal 41 (decimal 65, the ASCII character “A”). In version 2.1 and earlier, the character name string was limited to 14 characters. In version 2.2, the glyph name string can contain up to 65,535 characters.
<syntaxhighlight lang="text" class="" style="" inline="1">ENCODING 65</syntaxhighlight> declares the decimal code point for this glyph in the font.
<syntaxhighlight lang="text" class="" style="" inline="1">SWIDTH 500 0</syntaxhighlight> declares the scalable width of 500 on the X-axis and 0 (by default) on the Y-axis. This will result in an X-axis offset to the next glyph, but no Y-axis offset to the next glyph (i.e., the glyphs appear straight across in a line). The scalable width is 1000 times the actual point size of the character—the same unit used in an Adobe Font Metric (AFM) file. The number of pixels calculated as Template:Math, where Template:Math is 500 in this example, and resolution is 75 dpi for this font. Because 75 is approximately equal to 72, the number of pixels is the full width of a glyph (defined globally as 16 pixels) times Template:Math, or in other words the width of this glyph is 8 pixels.
<syntaxhighlight lang="text" class="" style="" inline="1">DWIDTH 8 0</syntaxhighlight> declares the device width of a glyph. In this case, after the glyph is rendered, the start of the next glyph is offset 8 pixels on the X-axis and 0 pixels on the Y-axis from the current glyph origin. Note that the device width is not necessarily equal to the width of the glyph. It is simply the offset on the X-axis to move the current point to the start of the next glyph.
The scalable width is used to calculate the width of a high-resolution glyph on a printer, whereas the device width is used to calculate the width of a glyph on a display device. Thus the scalable width is specified to greater precision than the device width.
<syntaxhighlight lang="text" class="" style="" inline="1">BBX 8 16 0 -2</syntaxhighlight> declares a bounding box that is 8 pixels wide and 16 pixels tall. The lower left-hand corner of the character is offset by 0 pixels on the X-axis and -2 pixels on the Y-axis.
<syntaxhighlight lang="text" class="" style="" inline="1">BITMAP</syntaxhighlight> begins the bitmap for the current glyph. This line must be followed by one line per pixel on the Y-axis. In this example the glyph is 16 pixels tall, so 16 lines follow. Each line contains the hexadecimal representation of pixels in a row. A “1” bit indicates a rendered pixel. Each line is rounded to an 8 bit (one byte) boundary, padded with zeroes on the right. In this example, the glyph is exactly 8 pixels wide, and so occupies exactly 8 bits (one byte) per line so that there is no padding. The most significant bit of a line of raster data represents the leftmost pixel.
<syntaxhighlight lang="text" class="" style="" inline="1">ENDCHAR</syntaxhighlight> ends the current glyph.
The declarations <syntaxhighlight lang="text" class="" style="" inline="1">STARTCHAR</syntaxhighlight> through <syntaxhighlight lang="text" class="" style="" inline="1">ENDCHAR</syntaxhighlight> are repeated for each glyph in a font.
<syntaxhighlight lang="text" class="" style="" inline="1">ENDFONT</syntaxhighlight> appears as the last line in the file, after all glyphs in the font have been enumerated.
Version 2.2 extensions
Version 2.2 of the BDF specification adds support for non-Western fonts. These additions allow moving the origin by a positive or negative movement on the X and Y axes. This not only accommodates right-to-left writing direction, but even top-to-bottom (for example, for Chinese). The following values provide multinational-font support:
<syntaxhighlight lang="text" class="" style="" inline="1">METRICSET</syntaxhighlight> is set to 0 for writing direction 0, 1 for writing direction 1, or 2 (in the initial global area) for both writing directions within the same font. Traditional Western left-to-right scripts use <syntaxhighlight lang="text" class="" style="" inline="1">METRICSET 0</syntaxhighlight>.
<syntaxhighlight lang="text" class="" style="" inline="1">SWIDTH1</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">DWIDTH1</syntaxhighlight> have the same parameters as <syntaxhighlight lang="text" class="" style="" inline="1">SWIDTH</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">DWIDTH</syntaxhighlight>, respectively. <syntaxhighlight lang="text" class="" style="" inline="1">DWIDTH1</syntaxhighlight> must be present for a <syntaxhighlight lang="text" class="" style="" inline="1">METRICSET 1</syntaxhighlight> glyph. Its offsets can be positive or negative.
<syntaxhighlight lang="text" class="" style="" inline="1">VVECTOR</syntaxhighlight> defines an X-axis offset and a Y-axis offset to transition from a mode 0 glyph to a mode 1 glyph. An opposite offset is applied during a mode 1 to mode 0 glyph transition.
This scheme easily accommodates two writing directions. Historically, fonts had 128 or 256 code points. Today, Unicode allows for over one million code points. Fonts can conceivably contain thousands of glyphs, some of which should be written left-to-right, some right-to-left, and some top-to-bottom. Such multi-directional writing requires creative use of <syntaxhighlight lang="text" class="" style="" inline="1">DWIDTH1</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">SWIDTH1</syntaxhighlight> for each glyph.
In addition to keywords added for international support, version 2.2 adds the <syntaxhighlight lang="text" class="" style="" inline="1">CONTENTVERSION</syntaxhighlight> declaration. This keyword is followed by an integer to indicate the version number of the font.
For more detailed information, consult the version 2.2 specification.
X Window properties
X Window font utilities support several properties that can be specified in the <syntaxhighlight lang="text" class="" style="" inline="1">STARTPROPERTIES</syntaxhighlight> section of a BDF file.[2] A generic BDF file is in ASCII encoding. X Window properties are specified using ISO 8859-1 encoding, which is an extension of ASCII. These properties include:
- <syntaxhighlight lang="text" class="" style="" inline="1">CAP_HEIGHT</syntaxhighlight> (integer) The height above the baseline of a capital letter (See Cap height).
- <syntaxhighlight lang="text" class="" style="" inline="1">COPYRIGHT</syntaxhighlight> (string)[3] A copyright statement.
- <syntaxhighlight lang="text" class="" style="" inline="1">DEFAULT_CHAR</syntaxhighlight> (unsigned integer) The default character (glyph) to display for an undefined glyph.
- <syntaxhighlight lang="text" class="" style="" inline="1">FACE_NAME</syntaxhighlight> (string[3]) The name of the face for this font.
- <syntaxhighlight lang="text" class="" style="" inline="1">FONT</syntaxhighlight> (string)[3] The X Window name of the font.
- <syntaxhighlight lang="text" class="" style="" inline="1">FONT_ASCENT</syntaxhighlight> (integer) The height above the baseline, for line spacing calculation.
- <syntaxhighlight lang="text" class="" style="" inline="1">FONT_DESCENT</syntaxhighlight> (integer) The descender below the baseline, for line spacing calculation.
- <syntaxhighlight lang="text" class="" style="" inline="1">FONT_VERSION</syntaxhighlight> (string)[3] The version of the font.
- <syntaxhighlight lang="text" class="" style="" inline="1">FOUNDRY</syntaxhighlight> (string)[3] The name of the foundry.
- <syntaxhighlight lang="text" class="" style="" inline="1">FAMILY_NAME</syntaxhighlight> (string)[3] The font family name.
- <syntaxhighlight lang="text" class="" style="" inline="1">NOTICE</syntaxhighlight> (string)[3] A general comment.
- <syntaxhighlight lang="text" class="" style="" inline="1">POINT_SIZE</syntaxhighlight> (integer) See Point (typography). If it is not separately specified, EMspace = round(POINT_SIZE/10), ENspace = round(POINT_SIZE/20), and THINspace = round(POINT_SIZE/30).
- <syntaxhighlight lang="text" class="" style="" inline="1">RESOLUTION_X</syntaxhighlight> (unsigned integer)
- <syntaxhighlight lang="text" class="" style="" inline="1">RESOLUTION_Y</syntaxhighlight> (unsigned integer)
- <syntaxhighlight lang="text" class="" style="" inline="1">SLANT</syntaxhighlight> (string)[3] “R” is roman, “I” is italic, “O” is oblique, “RI” is reverse italic, “RO” is reverse oblique, “OT” is other, and a number indicates polymorphic slant capability.
- <syntaxhighlight lang="text" class="" style="" inline="1">WEIGHT_NAME</syntaxhighlight> (string)[3] The weight of this font (“Bold” and “Normal” are typical, though there is no set enumeration).
- <syntaxhighlight lang="text" class="" style="" inline="1">X_HEIGHT</syntaxhighlight> (integer) The height above the baseline of a lower-case “x” (See x-height).