mcfonts.provider.unihex¶
A unihex provider, handling GNU Unifont .hex glyphs.
The GNU Unifont .hex format defines its glyphs as either 8 or 16 pixels in width by 16 pixels in height. The first number is the hexadecimal Unicode code point, with range 0000 through FFFF. The second number is the "bit string", which holds the glyph data as a seqeuence of binary digits.
For example, for 0041:0000000018242442427E424242420000:
0x0041 == 65; "A".32 >> 2 == 8; glyph is 8 pixels wide.
Module Contents¶
- class SizeOverride¶
-
- classmethod from_dict(d: dict[str, Any] | SizeOverrideDict) SizeOverride¶
- trim(glyph: mcfonts.glyph.unihex.UnihexGlyph) mcfonts.glyph.unihex.UnihexGlyph¶
- from_ : str¶
- left : int¶
- right : int¶
- to : str¶
- class UnihexProvider(*, hex_file: str, size_overrides: collections.abc.Sequence[SizeOverride | SizeOverrideDict])¶
Bases:
mcfonts.provider.Provider[mcfonts.glyph.unihex.UnihexGlyph],mcfonts.provider.HasPriority,mcfonts.serde.minecraft.MinecraftLoader[UnihexProvider],mcfonts.serde.minecraft.MinecraftSaver,mcfonts.serde.opentype.OpenTypeSaver,mcfonts.serde.unihex.UnihexSaver,mcfonts.serde.yaff.YaffSaver,mcfonts.render.RenderableThe
unihexprovider loads glyphs from text files in the ".hex" format.It has two required fields,
hex_fileandsize_overrides.hex_fileis a resource location to a .ZIP file containing any number of ".hex" files at its root.size_overridesis a list of maps stating the beginning and end of a character range, and the starting and ending columns of the glyphs that match that range.
Each ".hex" file is a text document with each line containing a hex glyph. A hex glyph is a string of text in the format of
<codepoint>:<bit string>. The bit string is a string of hexadecimal numbers. The numbers, when converted to binary, describe the glyph's pixels. A 1 bit is an "on" pixel, and a 0 bit is an "off" pixel. When exporting, the empty left and right columns are trimmed unlesssize_overridesexplicitly overrides this.Initialize.
- Parameters:¶
- hex_file : str¶
Resource location to a
.hexfile.- size_overrides : collections.abc.Sequence[SizeOverride | SizeOverrideDict]¶
List of size overrides.
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
None) UnihexProvider¶ Return a deep copy of this provider.
In order:
Initialization, field copy
Filter copy
Glyph copy
- __repr__() str¶
Return
UnihexProvider(x characters, hex_file x, x size overrides).- Return type:¶
str
- __setitem__(key: str, value: mcfonts.glyph.unihex.UnihexGlyph)¶
- Parameters:¶
- key : str¶
- value : mcfonts.glyph.unihex.UnihexGlyph¶
- Return type:¶
None
- classmethod get_glyph_type() type[mcfonts.glyph.unihex.UnihexGlyph]¶
Return the type of Glyph this provider uses.
- classmethod get_pack_versions() tuple[int, None]¶
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.
- get_size_overrides() list[SizeOverride]¶
- Return type:¶
list[SizeOverride]
- classmethod minecraft_load(root: mcfonts.path.PackRoot, resource_location: str, contents: collections.abc.Mapping[str, Any]) UnihexProvider¶
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_size_overrides(value: collections.abc.Sequence[SizeOverride | SizeOverrideDict]) None¶
- Parameters:¶
- value : collections.abc.Sequence[SizeOverride | SizeOverrideDict]¶
- 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
-
priority : ClassVar[int] =
1¶
- SizeOverrideDict : Final[TypedDict]¶