mcfonts.glyph.unihex¶
The unihex glyph format orginates from GNU Unifont's .hex format.
These glyphs store their data as a simple sequence of bits. All unihex glyphs are 16 pixels in height, so this allows rows and columns of the glyph to be deduced and addressed.
This module uses a bitarray to store and pass this data.
Module Contents¶
- class UnihexGlyph(data: str | bitarray.bitarray)¶
Bases:
mcfonts.glyph.Glyph,mcfonts.serde.opentype.ToTrueTypeGlyph,mcfonts.serde.yaff.ToYaffData,mcfonts.serde.unihex.ToUnihexDataThe unihex glyph contains its bits (stored as
bitarray).Initialize.
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
None) UnihexGlyph¶ Return a deep copy; bits are implicitly copied.
- bake() PIL.Image.Image¶
Return a image rendering of this glyph.
This does not include any right padding.
- Return type:¶
PIL.Image.Image
- get_metrics() mcfonts.glyph.GlyphMetrics¶
Return the metrics of this glyph.
- show() str¶
Return a pretty visual representation of this glyph.
It is best to pass this into
print().
- to_truetype_glyph() fontTools.ttLib.tables._g_l_y_f.Glyph¶
Process and convert this glyph into rectangle shapes.
- to_unihex_data() str¶
Process and convert this glyph into GNU Unihex data.
-
height : ClassVar[int] =
16¶
-
valid_widths : ClassVar[list[int]] =
[8, 16, 24, 32]¶
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
- bits_to_rows(bits: bitarray.bitarray) collections.abc.Generator[bitarray.bitarray]¶
Convert bits into a yield of bitarrays as its rows.
- calculate_metrics(bits: bitarray.bitarray) mcfonts.glyph.GlyphMetrics¶
Calculate left, right, bottom, and top metrics.
- get_width(bits: bitarray.bitarray) int¶
Return how wide a .hex glyph's bit string is.
Width is equivalent to
len(bits) // 4, which can be shortened tolen(bits) >> 2. Since this expects a bitarray, the calculation becomes >> 4.
- split_whole(unihex_glyph: str) tuple[str, str]¶
Return the character and data of a whole unihex string.
- whole_to_bits(unihex_glyph: str) bitarray.bitarray¶
Return the data portion of a unihex glyph -- the part after
:.>>> whole_to_bits("0041:0000000018242442427E424242420000") bitarray('0000000018242442427E424242420000')