mcfonts.utils.unihex
¶
Utilities for dealing with .hex glyphs.
This is often used in conjunction with mcfonts.providers.unihex.UnihexProvider
.
Module Contents¶
Functions¶
|
Return bit_string but with each set of "bytes" as real bytes. |
|
Given bit_string, return a |
|
Convert bit_string into a yield of strings, with each character in the string being either "1" or "0". |
|
Return the "bit string" portion of a .hex glyph. This is the part after the |
|
Return the character that a .hex glyph is associated with. |
|
Return the two integers of the bearings of an .hex glyph's bit string. |
|
Return how wide a .hex glyph's bit string is. |
- mcfonts.utils.unihex.bit_string_to_bytes(bit_string)¶
Return bit_string but with each set of "bytes" as real bytes.
For example, "00EA" returns "\x00\xEA". This is useful for iterating over the pixels of a bit string, or converting to an image.
>>> bit_string_to_bytes("0000000018242442427E424242420000") b'\x00\x00\x00\x00\x18$$BB~BBBB\x00\x00'
- mcfonts.utils.unihex.bit_string_to_image(bit_string)¶
Given bit_string, return a
Image
that is a 1:1 representation of the glyph.
-
mcfonts.utils.unihex.bit_string_to_rows(bit_string, reverse=
True
)¶ Convert bit_string into a yield of strings, with each character in the string being either "1" or "0".
If reverse (the default), the rows will be flipped vertically.
>>> list(bit_string_to_rows("0000000018242442427E424242420000")) [ '00000000', '00000000', '01000010', '01000010', '01000010', '01000010', '01111110', '01000010', '01000010', '00100100', '00100100', '00011000', '00000000', '00000000', '00000000', '00000000' ]
- mcfonts.utils.unihex.get_bit_string(hex_glyph)¶
Return the "bit string" portion of a .hex glyph. This is the part after the
:
.>>> get_bit_string("0041:0000000018242442427E424242420000") '0000000018242442427E424242420000'
- mcfonts.utils.unihex.get_codepoint(hex_glyph)¶
Return the character that a .hex glyph is associated with.
- mcfonts.utils.unihex.get_unihex_bearings(bit_string)¶
Return the two integers of the bearings of an .hex glyph's bit string.
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.
If return is (0, 0), there's no pixel data, the glyph is all spaces.
This function is similar to
mcfonts.utils.image.get_image_bearings()
.>>> get_unihex_bearings("0000000018242442427E424242420000") (1, 7)
- mcfonts.utils.unihex.get_width(bit_string)¶
Return how wide a .hex glyph's bit string is.
Width is equivalent to
len(bit_string) // 4
, which can be shortened tolen(bit_string) >> 2
.