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
__post_init__() None

Validate.

Return type:

None

classmethod from_dict(d: dict[str, Any] | SizeOverrideDict) SizeOverride
Parameters:
d : dict[str, Any] | SizeOverrideDict

Return type:

SizeOverride

to_dict() SizeOverrideDict
Return type:

SizeOverrideDict

trim(glyph: mcfonts.glyph.unihex.UnihexGlyph) mcfonts.glyph.unihex.UnihexGlyph
Parameters:
glyph : mcfonts.glyph.unihex.UnihexGlyph

Return type:

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.Renderable

The unihex provider loads glyphs from text files in the ".hex" format.

It has two required fields, hex_file and size_overrides.

  • hex_file is a resource location to a .ZIP file containing any number of ".hex" files at its root.

  • size_overrides is 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 unless size_overrides explicitly overrides this.

Initialize.

Parameters:
hex_file : str

Resource location to a .hex file.

size_overrides : collections.abc.Sequence[SizeOverride | SizeOverrideDict]

List of size overrides.

__contains__(item: object) bool
Parameters:
item : object

Return type:

bool

__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None = None) UnihexProvider

Return a deep copy of this provider.

In order:

  1. Initialization, field copy

  2. Filter copy

  3. Glyph copy

Returns:

A provider copy that is equal but not identical.

Parameters:
memodict : collections.abc.Mapping[Any, Any] | None

Return type:

UnihexProvider

__delitem__(key: str) None
Parameters:
key : str

Return type:

None

__getitem__(key: str) mcfonts.glyph.unihex.UnihexGlyph
Parameters:
key : str

Return type:

mcfonts.glyph.unihex.UnihexGlyph

__iter__() collections.abc.Generator[str]
Return type:

collections.abc.Generator[str]

__len__() int

Return the number of glyphs.

Return type:

int

__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

as_dict() dict[str, Any]
Return type:

dict[str, Any]

classmethod get_glyph_type() type[mcfonts.glyph.unihex.UnihexGlyph]

Return the type of Glyph this provider uses.

Returns:

Type of Glyph.

Return type:

type[mcfonts.glyph.unihex.UnihexGlyph]

get_hex_file() str
Return type:

str

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.

Returns:

A 2-element tuple of the minimum and maximum valid pack versions.

Return type:

tuple[int, None]

classmethod get_priority() int

Return the priority of this type of provider.

Returns:

Priority.

Return type:

int

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.

Parameters:
root : mcfonts.path.PackRoot

Resource pack root.

resource_location : str

Resource location of font JSON.

contents : collections.abc.Mapping[str, Any]

Font JSON.

Returns:

A provider.

Return type:

UnihexProvider

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 None if character cannot be rendered by this provider.

Return type:

mcfonts.render.RenderResult | None

set_hex_file(value: str) None
Parameters:
value : str

Return type:

None

classmethod set_priority(priority: int) None

Set the priority of this type of provider.

Parameters:
priority : int

New priority.

Return type:

None

set_size_overrides(value: collections.abc.Sequence[SizeOverride | SizeOverrideDict]) None
Parameters:
value : collections.abc.Sequence[SizeOverride | SizeOverrideDict]

Return type:

None

unihex_save(entries: collections.abc.MutableSequence[str]) None

Save provider into entries.

Parameters:
entries : collections.abc.MutableSequence[str]

List of the current lines in the file.

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]