mcfonts.providers.unihex

A unihex provider, handling .hex glyphs.

Module Contents

Classes

UnihexProvider

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

class mcfonts.providers.unihex.UnihexProvider(provider, origin, resources)

Bases: mcfonts.providers.base.Provider

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.

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

resources : dict[str, str] | None

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.UnihexGlyph]]

get_contents()

Return the contents of the provider.

Returns:

Dictionary of the provider.

Return type:

mcfonts.utils.types.TypedProviderUnihex

get_icon()

Return a Unicode character that can be used to represent this provider in shorthand descriptions.

Returns:

A 1-character string.

Return type:

str

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.

Returns:

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

Return type:

tuple[int, None]

get_size_override(character)

Return the size overrides of a character, if they exist.

Size overrides is a tuple of two integers of the starting and ending columns to cut off when exporting. If there are no size overrides for a character, None is returned.

Returns:

A tuple of two integers, or None.

Parameters:
character : str

Return type:

tuple[int, int] | None

pretty_print()

Return a short one line description of the provider.

Returns:

A string of the provider's info, normally <icon> <type>: <info,...>.

Return type:

str

print_info()

Print information about this provider.

Return type:

None

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().

Returns:

Nothing; problems are either raised or warned.

Return type:

None

yield_characters()

Yield strings of the individual characters this provider supports.

Returns:

A yield of strings of length 1, or None if no characters are present.

Return type:

collections.abc.Iterable[str]

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.UnihexGlyph]]

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.UnihexGlyph]]

yield_size_overrides()

Yield all the size overrides for every character.

Overrides are given as tuple[int, int].

Returns:

A yield of (character: str, (left: int, right: int)).

Return type:

collections.abc.Iterable[tuple[str, tuple[int, int]]]


Last update: 2023 November 30