mcfonts.glyphs
¶
Various glyph formats that can be present in a font.
Each vary in their storage formats and methods of manipulating contained data.
Module Contents¶
Classes¶
A bitmap glyph. |
|
The base Glyph class. Should never be called or instantiated. |
|
A space glyph. |
|
A unihex glyph. |
Attributes¶
-
mcfonts.glyphs.BITMAP_EXPORT_PIXEL_THRESHOLD =
180
¶
- class mcfonts.glyphs.BitmapGlyph¶
Bases:
Glyph
A bitmap glyph.
Must contain an image and ascent. Height, ascent, and bearings are optional. Bearings and width are lazily-loaded.
- ascent : int¶
Required ascent.
- bearings : tuple[int, int] | None¶
Optional padding from the edges of the canvas.
- height : int | None¶
Optional height. Lazy default is 8 if None.
- image : PIL.Image.Image¶
Required image.
- program : list[str | int] | None¶
Optional Type 2 charstring program of the glyph.
- width : int | None¶
Optional width. Lazy default is self.image.width.
- construct_program(pixel_size)¶
Create a Type 2 charstring program.
If the glyph is empty or has no white pixels, None will be returned. Otherwise, a list (the program) will be returned.
Warning
These charstrings are not optimized or checked for overlaps. In FontForge, use
manually afterward.
- get_bearings()¶
From
mcfonts.utils.resources.get_image_bearings()
:Bearings are a "padding" from the edge of the canvas to image pixels.Left bearing is the distance from the left edge of the canvas to the most-left pixel data.Right bearing is the distance from the right edge of the canvas to the most-right pixel data.This is lazily-loaded.
- Return type:¶
tuple[int, int]
- get_height()¶
The height of the glyph; this is not necessarily the glyph's image width.
This is lazily-loaded.
- Return type:¶
int
- class mcfonts.glyphs.Glyph¶
Bases:
abc.ABC
The base Glyph class. Should never be called or instantiated.
- abstract construct_program(pixel_size)¶
Create a Type 2 charstring program.
If the glyph is empty or has no white pixels, None will be returned. Otherwise, a list (the program) will be returned.
Warning
These charstrings are not optimized or checked for overlaps. In FontForge, use
manually afterward.
- abstract get_height()¶
Height of the glyph. This is not always equal to the glyph's image, if applicable.
- Return type:¶
int
-
mcfonts.glyphs.SPACE_EXPORT_MAX_ADVANCE =
12500
¶
- class mcfonts.glyphs.SpaceGlyph¶
Bases:
Glyph
A space glyph.
Contans one required field, the glyph's width.
- program : list[str | int] | None¶
Optional Type 2 charstring program of the glyph.
- width : int¶
The width of the glyph.
- construct_program(pixel_size)¶
Create a Type 2 charstring program.
If the glyph is empty or has no white pixels, None will be returned. Otherwise, a list (the program) will be returned.
Warning
These charstrings are not optimized or checked for overlaps. In FontForge, use
manually afterward.
- get_height()¶
Height of the glyph. This is not always equal to the glyph's image, if applicable.
- Return type:¶
int
-
mcfonts.glyphs.UNIHEX_EXPORT_PIXEL_ON =
'1'
¶
- class mcfonts.glyphs.UnihexGlyph¶
Bases:
Glyph
A unihex glyph.
Must contain a bit string. Width, image, and bearings are optional. Width, image, and bearings are lazily-loaded.
Unihex glyphs are always 16 pixels tall.
- bearings : tuple[int, int] | None¶
An optional tuple of the glyph's bearings, comparable to a
BitmapGlyph
.
- bit_string : str¶
The bit string; does not include the codepoint: starting portion.
- image : PIL.Image.Image | None¶
An optional image of the glyph, comparable to a
BitmapGlyph
. If possible, try not to use this.
- program : list[str | int] | None¶
Optional Type 2 charstring program of the glyph.
- size_override : tuple[int, int] | None¶
An optional tuple of the glyph's size override.
The first value is the starting column, and the second value is the ending column. When exporting, data outside of these columns will be discarded. If this is None, this is lazily-calculated to be
(0, self.get_width())
.
- width : int | None¶
The width of the glyph. Equal to
len(self.bit_string) // 4
.
- construct_program(pixel_size)¶
Create a Type 2 charstring program.
If the glyph is empty or has no white pixels, None will be returned. Otherwise, a list (the program) will be returned.
Warning
These charstrings are not optimized or checked for overlaps. In FontForge, use
manually afterward.
- get_bearings()¶
See
mcfonts.utils.unihex.get_unihex_bearings()
.- Return type:¶
tuple[int, int]
- get_height()¶
Height of the glyph. This is not always equal to the glyph's image, if applicable.
- Return type:¶
int
- get_program()¶
A Type 2 charstring program. This is used in exporting and can be cached for better performance.
- Return type:¶
list[str | int] | None