Bounding Boxes

A bounding box is shown below.
                |<--- width --->|
                      = w
              - ----------------- -
              ^ |   |           | ^
              | |   |           | |
       ascent | |   |           | |
              | |   |           | | height = h
              | |   |           | |
baseline ---> - |---O-----------| |             point "O" = Origin
              | |   |           | |
 descent = yd | |   |           | |
              v |   |           | v
              - ----------------- -

|<--| xd

The values are in pixels of the bitmap. In the fixed pitch fonts that HBF deals with, these parameters will be the same for each character of the font.

The HBF_BITMAP_BOUNDING_BOX bounds the bitmap of a glyph; thus its width and height are equal to the width and height of the bitmap.

FONTBOUNDINGBOX is a BDF 2.1 property, defining an area within which all glyphs of the font are usually displayed (even if the font is of variable width). In HBF, the FONTBOUNDINGBOX allows for the specification of inter-glyph and inter-line spacing. In many cases, where such control over spacing is not required, the sizes of HBF_BITMAP_BOUNDING_BOX and FONTBOUNDINGBOX are the same. In all cases, the bitmap bounding box must fit within the font bounding box.

In an application, a line of text may contain glyphs from more than one font. The glyphs must be aligned along the horizontal "baseline" of the line of text. The baseline contains the "origins" of the glyph bounding boxes. The origin of a bounding box may not be at the lower left corner of the bounding box because some letters in a Latin font, like 'g', 'j', 'Q', etc., have "descenders" extending below the baseline. The xd and yd values of a bounding box specify the offset of the lower left corner of the bounding box from the origin.

In such cases, the yd value of both bounding boxes may be non-zero due to the need to align neatly with a Latin font along a line of text. E.g., use

          FONTBOUNDINGBOX 24 24 0 -4
instead of
          FONTBOUNDINGBOX 24 24 0 0
to align with a Latin font with "FONTBOUNDINGBOX 12 24 0 -4" which contains letters with descent "-4", such as 'g', 'j', 'Q', etc.

The following shows an example of unequal bitmap and font bounding boxes. Suppose the HBF file contains the lines

          FONTBOUNDINGBOX 16 18 0 -2
and (indicating a 16x15 bitmap)
          HBF_BITMAP_BOUNDING_BOX 16 15 0 -1
In the following diagram, the boundary of the font bounding box is dashed, while the boundary of the bitmap bounding box is dotted:
                |<--- width --->|
                      = 16
                -----------------      -
a blank row-->  |               |      ^
a blank row-->  |               |      |
                |...............| -    |
                |///////////////| ^    |
                |///////////////| |    |
                |// 16x15  /////| |    |
                |// bitmap /////| |15  |18 = FONTBOUNDINGBOX height.
                |///////////////| |    |
                |///////////////| |    |
baseline ---->  O---------------- |    |   point "O" = Origin (0,0)
                |///////////////| v    |
              -1|...............| -    |   -1 = yd of HBF_BITMAP_BOUNDING_BOX.
a blank row-->  |               |      v
              -2-----------------      -   -2 = yd of FONTBOUNDINGBOX.
Note that the origins of the two bounding boxes are identified.

The following are some more examples to illustrate the relationships between FONTBOUNDINGBOX and HBF_BITMAP_BOUNDING_BOX.

Suppose we have five HBF files: HBF1, HBF2, HBF3, HBF4, HBF5.

16x16 bitmap HBFs

HBF1: (HBF_BITMAP_BOUNDING_BOX and FONTBOUNDINGBOX are the same.)
HBF_BITMAP_BOUNDING_BOX 16 16 0 -2
FONTBOUNDINGBOX         16 16 0 -2
HBF2: (to allow for inter-line spacing of 2 pixels with the glyph bitmap aligned at the bottom of the FONTBOUNDINGBOX)
HBF_BITMAP_BOUNDING_BOX 16 16 0 -2
FONTBOUNDINGBOX         16 18 0 -2

16x15 bitmap HBFs

HBF3: (to be aligned at the top of HBF1 glyph bitmap when shown with HBF1)
HBF_BITMAP_BOUNDING_BOX 16 15 0 -1
FONTBOUNDINGBOX         16 16 0 -2
HBF4: (to be aligned at the bottom of HBF1 glyph bitmap when shown with HBF1)
HBF_BITMAP_BOUNDING_BOX 16 15 0 -2
FONTBOUNDINGBOX         16 16 0 -2
HBF5: (to be aligned at the top of HBF2 glyph bitmap when shown with HBF2 and using the same FONTBOUNDINGBOX as HBF2)
HBF_BITMAP_BOUNDING_BOX 16 15 0 -1
FONTBOUNDINGBOX         16 18 0 -2

Part of Hanzi Bitmap Font (HBF) File Format version 1.1.