freetypy.Glyph.get_cbox

Glyph.get_cbox()

Get the glyph’s ‘control box’.

The control box encloses all the outline’s points, including Bézier control points. Though it coincides with the exact bounding box for most glyphs, it can be slightly larger in some situations (like when rotating an outline which contains Bézier outside arcs).

Computing the control box is very fast, while getting the bounding box can take much more time as it needs to walk over all segments and arcs in the outline.

Parameters:mode (int, optional) – The mode which indicates how to interpret the returned bounding box values. For the available options, see GLYPH_BBOX.
Returns:bbox – The glyph coordinate bounding box.
Return type:BBox

Notes

Coordinates are relative to the glyph origin, using the y upwards convention.

If the glyph has been loaded with LOAD.NO_SCALE, mode must be set to GLYPH_BBOX.UNSCALED to get unscaled font units in 26.6 fixed-point pixel format.

If the font is tricky and the glyph has been loaded with LOAD.NO_SCALE, the resulting BBox is meaningless. To get reasonable values for the BBox it is necessary to load the glyph at a large ppem value (so that the hinting instructions can properly shift and scale the subglyphs), then extracting the BBox which can be eventually converted back to font units.

Note that the maximum coordinates are exclusive, which means that one can compute the width and height of the glyph image as:

width  = bbox.xMax - bbox.xMin
height = bbox.yMax - bbox.yMin

Note also that for 26.6 coordinates, if mode is set to GLYPH_BBOX.GRIDFIT, the coordinates will also be grid-fitted, which corresponds to:

bbox.xMin = floor(bbox.xMin)
bbox.yMin = floor(bbox.yMin)
bbox.xMax = ceil(bbox.xMax)
bbox.yMax = ceil(bbox.yMax)

To get the bbox in pixel coordinates, set mode to GLYPH_BBOX.TRUNCATE.

To get the bbox in grid-fitted pixel coordinates, set mode to GLYPH_BBOX.PIXELS.