mcfonts.providers.base

Contains the basic parent provider that all functional providers subclass and inherit from.

Module Contents

Classes

Provider

The base provider class. All providers subclass this.

Functions

format_provider_message(provider, message)

Format a provider warning message properly, following Provider <type>: <message>.

pretty_print_provider_dictionary(provider)

Format a provider information message properly, following <type><provider specific>.

class mcfonts.providers.base.Provider(provider_type, origin, chars_covered=None)

Bases: abc.ABC

The base provider class. All providers subclass this.

Construct a Provider base class.

Parameters:
provider_type : str

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 : set[str] | None

A set of the individual characters covered by this provider.

abstract 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.Glyph]]

abstract get_contents()

Return the contents of the provider.

Returns:

Dictionary of the provider.

Return type:

mcfonts.utils.types.TypedProviderDict

abstract 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

abstract 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, int | None]

abstract 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

abstract 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]

abstract 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.Glyph | None]]

abstract 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.Glyph | None]]

mcfonts.providers.base.format_provider_message(provider, message)

Format a provider warning message properly, following Provider <type>: <message>.

Calls mcfonts.utils.pretty_print_provider().

Parameters:
provider : Provider | dict[str, Any]

The provider, either as a dictionary or instance of mcfonts.providers.base.Provider.

message : str

The message to append at the end.

Returns:

The formatted warning message.

Return type:

str

mcfonts.providers.base.pretty_print_provider_dictionary(provider)

Format a provider information message properly, following <type><provider specific>.

Provider specific info:

  • bitmap: <file> h <height> a <ascent>

  • space: nothing

  • legacy_unicode: <template>

  • ttf: <file> s <shift0, 1>, sz <size>, o <oversample>, sk <skip>

Parameters:
provider : dict[str, Any]

The provider as a dictionary, not an instance of mcfonts.providers.base.Provider.

Returns:

The pretty provider information.

Return type:

str


Last update: 2023 November 30