mcfonts.provider.legacy_unicode¶
A legacy unicode provider, handling bitmap glyphs in a 16*16 pixel grid.
Module Contents¶
-
class GlyphSizes(contents: bytes | bytearray | None =
None)¶ Bases:
collections.abc.MutableMapping[str,tuple[int,int]]Container for the legacy unicode "glyph_sizes.bin" format.
Initialize.
- Parameters:¶
- contents : bytes | bytearray | None¶
Contents of the sizes file. If None, sizes is entirely empty.
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
None) GlyphSizes¶ Return a deepcopy of this instance.
-
to_space_advances(match_unicode_category: collections.abc.Sequence[str] | None =
None) dict[str, int]¶ Translate a glyphsizes.bin file into an "advances" mapping, which goes inside a "space" provider.
Note
This function does not return a new provider.
>>> GlyphSizes(b"\x00\x00\x00...").to_space_advances() { "\x00": 0, "\x01": 0, "\x02": 0, "\uBEEF": 15 }- Parameters:¶
- match_unicode_category : collections.abc.Sequence[str] | None¶
Only translate Unicode characters with these categories. By default, this is
[Mc, Zp, Zs, Zl]. This should cover most whitespace and marking characters. To work on all character, set this to[], not None.
- Returns:¶
An "advances" dictionary.
- Return type:¶
dict[str, int]
- trim(character: str, image: PIL.Image.Image) PIL.Image.Image¶
Trim the left and right columns of image to comply with the sizes for character.
-
default_size : ClassVar[bytes] =
b'\x0f'¶
- class LegacyUnicodeProvider(*, template: str, sizes: str)¶
Bases:
mcfonts.provider.Provider[mcfonts.glyph.bitmap.BitmapGlyph],mcfonts.provider.HasPriority,mcfonts.serde.minecraft.MinecraftLoader[LegacyUnicodeProvider],mcfonts.serde.minecraft.MinecraftSaver,mcfonts.serde.opentype.OpenTypeSaver,mcfonts.serde.unihex.UnihexSaver,mcfonts.serde.yaff.YaffSaver,mcfonts.render.RenderableThe legacy unicode provider is a "fallback" provider intended to be used as a last-resort.
It uses a system of templates to create and add 16*16 pixel tables of "fallback" characters. Each glyph is 16*16 wide, so each page is 256*256 -- 16 characters on each line, 16 lines, 16 length for each glyph. Its glyphs are bitmaps.
GlyphSizes controls the size of each glyph, but only when getting it. No trimming is performed when setting.
The
GlyphSizeshas a higher priority over glyph widths. For example, setting a character to a glyph while that character's "glyph size" is(1, 8)will cause the glyph's image to be automatically trimmed to have width bearings of(1, 8).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 or supported.
Initialize.
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
None) LegacyUnicodeProvider¶ Return a deep copy of this provider.
In order:
Initialization, field copy
Filter copy
Glyph copy
- __setitem__(key: str, value: mcfonts.glyph.bitmap.BitmapGlyph)¶
- Parameters:¶
- key : str¶
- value : mcfonts.glyph.bitmap.BitmapGlyph¶
- Return type:¶
None
- get_glyph_sizes() GlyphSizes¶
Get a deep copy of the internal glyph sizes.
- Returns:¶
A
GlyphSizesinstance.- Return type:¶
- classmethod get_glyph_type() type[mcfonts.glyph.bitmap.BitmapGlyph]¶
Return the type of Glyph this provider uses.
- get_in_codepage(codepage: int) collections.abc.Generator[tuple[str, mcfonts.glyph.bitmap.BitmapGlyph]]¶
Get all characters and glyphs in a codepage.
- Parameters:¶
- codepage : int¶
The codepage number.
- Returns:¶
Generator yielding tuples of (character, glyph) for the codepage.
- Return type:¶
collections.abc.Generator[tuple[str, mcfonts.glyph.bitmap.BitmapGlyph]]
- classmethod get_pack_versions() tuple[int, int]¶
Return a tuple of the minimum and maximum pack versions for which this provider is used.
The tuple contains 2 optional integers - the start and end pack versions, both inclusive. None items indicate no bound:
(None, 4)means from any up to 4.(4, None)means from 4 up to any.
- classmethod get_priority() int¶
Return the priority of this type of provider.
- static get_valid_codepages() collections.abc.Generator[int]¶
Get a generator of all valid codepage numbers.
- classmethod minecraft_load(root: mcfonts.path.PackRoot, resource_location: str, contents: collections.abc.Mapping[str, Any]) LegacyUnicodeProvider¶
Return an instance of a provider, given the contents of the provider and where it is.
- minecraft_save(root: mcfonts.path.PackRoot, resource_location: str) None¶
Save a provider back to a location.
If the target file already exists, this provider will be appended to it.
Warning
This will overwrite files.
- Parameters:¶
- root : mcfonts.path.PackRoot¶
Resource pack root.
- resource_location : str¶
Resource location of font JSON.
- Return type:¶
None
- opentype_save(tables: mcfonts.serde.opentype.OpenTypeTables) None¶
Save provider into an OpenType font by modifying its tables.
- Parameters:¶
- tables : mcfonts.serde.opentype.OpenTypeTables¶
Table storage.
- Return type:¶
None
- render(character: str, metrics: mcfonts.render.RenderMetrics) mcfonts.render.RenderResult | None¶
Draw a character contained in this provider.
- Parameters:¶
- character : str¶
The character to render.
- metrics : mcfonts.render.RenderMetrics¶
Current rendering metrics.
- Returns:¶
RenderResult, or
Noneif character cannot be rendered by this provider.- Return type:¶
mcfonts.render.RenderResult | None
- set_glyph_sizes(value: GlyphSizes | None) None¶
Set the glyph sizes.
- Parameters:¶
- value : GlyphSizes | None¶
New
GlyphSizesinstance, or None to use blank sizes.
- Return type:¶
None
- yaff_save(data: mcfonts.serde.yaff.YaffData) None¶
Save provider into data.
- Parameters:¶
- data : mcfonts.serde.yaff.YaffData¶
Current whole YAFF font data.
- Return type:¶
None
- invalid_codepages : ClassVar[set[int]]¶
-
priority : ClassVar[int] =
0¶
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
- auto_trim_glyph_sizes(provider: LegacyUnicodeProvider) None¶
For all characters, re-assign its spot in glyph_sizes to match its current metrics.
- Parameters:¶
- provider : LegacyUnicodeProvider¶
The provider.
- Return type:¶
None
- build_template_for_character(character: str) PIL.Image.Image¶
Build an image of a template character.
Templates are simple white boxes with a codepoint texture inside them. To customize the template texture, change the images within
TEMPLATES.
-
create_page(provider: LegacyUnicodeProvider, codepage: int =
0) PIL.Image.Image¶ Create an image of a specific codepage for some LegacyUnicodeProvider.
- iterate_grid(image: PIL.Image.Image, row_column_count: tuple[int, int]) collections.abc.Generator[PIL.Image.Image]¶
Yield images of the sections of a divided resource.
Given a resource and number of characters in each row and column of that resource, yield every
PIL.Image.Imagein that resource.If no data exists in a cell, yield None.
- PF¶
- TEMPLATES : Final[dict[int, PIL.Image.Image]]¶