mcfonts.providers.legacy_unicode
¶
A legacy unicode provider, handling bitmap glyphs in a 16px x 16px grid.
Module Contents¶
Classes¶
The |
Functions¶
|
Align a Unicode page font sheet's characters to the left. |
|
Build an image of a template codepoint. |
|
Translate a glyphsizes.bin file into an "advances" mapping, which goes inside a "space" provider. |
Attributes¶
- class mcfonts.providers.legacy_unicode.LegacyUnicodeProvider(provider, origin, resources)¶
Bases:
mcfonts.providers.base.Provider
The
legacy_unicode
provider is a "fallback" provider intended to be used as a last-resort.It is similar to the
bitmap provider
in that its glyphs are bitmaps.It uses a system of templates to create and add 16px x 16px tables of "fallback" characters. Each glyph is 16px x 16px pixels wide, so each page is 256px x 256px; 16 characters on each line, 16 lines, 16 length for each glyph.
Warning
This provider is deprecated and should not be used when possible. Use the "unihex" provider instead.
Important
Characters above the BMP (U+FFFF) are not handled.
Construct a Provider base class.
- Parameters:¶
- provider_type
A string of the value in the JSON "type" field.
- origin : os.PathLike[str] | str¶
The absolute path to the provider's JSON file.
- chars_covered
A set of the individual characters covered by this provider.
- provider : mcfonts.utils.types.TypedProviderLegacyUnicode¶
- resources : dict[str, PIL.Image.Image | bytes]¶
- construct_glyphs()¶
Yield a tuple of (character, glyph) for every glyph available in the provider's resource.
Some glyphs may be empty or have no content.
- Returns:¶
A yield of
(character, Glyph)
, or None if there are no glyphs.- Return type:¶
collections.abc.Iterable[tuple[str, mcfonts.glyphs.BitmapGlyph]]
- get_contents()¶
Return the contents of the provider.
- get_icon()¶
Return a Unicode character that can be used to represent this provider in shorthand descriptions.
- get_pack_versions()¶
Return a tuple of the minimum and maximum pack versions for which this provider is valid.
The first element is guaranteed to be an integer. There will always be a minimum version, even if it's 0. The second element may be an integer, or None. If it is None, there is no maximum version bound.
- pretty_print()¶
Return a short one line description of the provider.
- validate()¶
Specific tests for validating a provider.
This function checks values to ensure that they're correct and in an acceptable range.
If applicable, textures are checked to ensure all characters have a defined glyph, and that the dimensions are correct.
Warnings are printed through
mcfonts.logger.warning()
.
- yield_characters()¶
Yield strings of the individual characters this provider supports.
- yield_glyphs()¶
Yield a tuple of (character, glyph) for every glyph available in the provider's resource.
This is different from
construct_glyphs()
because it yields glyphs that have already been constructed and stored.- Returns:¶
A yield of
(character, Glyph)
.- Return type:¶
collections.abc.Iterable[tuple[str, mcfonts.glyphs.BitmapGlyph]]
- yield_glyphs_in_unirange(unirange_notation)¶
Given unirange_notation, return a dictionary of the requested characters to their glyphs.
- Parameters:¶
- unirange_notation : str¶
A string representing the requested range of chars. See https://pypi.org/project/unirange/.
- Returns:¶
A yield of the requested glyphs that match unirange_notation.
- Return type:¶
collections.abc.Iterable[tuple[str, mcfonts.glyphs.BitmapGlyph | None]]
- mcfonts.providers.legacy_unicode.TEMPLATE_CHARS¶
- mcfonts.providers.legacy_unicode.align_unicode_page(sheet)¶
Align a Unicode page font sheet's characters to the left.
This function is a shortcut for
mcfonts.utils.resources.align_font_texture(sheet, (16, 16))()
.
-
mcfonts.providers.legacy_unicode.build_template_for_character(character, template_storage=
None
)¶ Build an image of a template codepoint.
Templates are simple white boxes with a codepoint texture inside them. This is intended for use with a "legacy_unicode" provider.
- Parameters:¶
- character : str¶
A single character. This character's codepoint is what goes inside the box.
- template_storage : dict[int, PIL.Image.Image] | None¶
Dictionary of integers mapped to the template character PNG images.
0-15 are images of hexadecimal digits.
-4 and -6 are "boxes" for 4 and 6 digit-long codepoints, respectively.
- Returns:¶
A
PIL.Image.Image
of the character template.- Return type:¶
PIL.Image.Image
-
mcfonts.providers.legacy_unicode.to_advances(glyphsizes, match_unicode_category=
None
)¶ Translate a glyphsizes.bin file into an "advances" mapping, which goes inside a "space" provider.
Note
This function does not return a new provider.
>>> to_advances(b"\x00\x00\x00...") { "\x00": 0, "\x01": 0, "\x02": 0, "\uBEEF": 15 }