mcfonts.provider¶
Contains providers -- mappings of character --> glyph.
Note
Reference providers have no class and they are not represented.
Reference providers are immediately unpacked in mcfonts.factory functions.
It is not possible to create a reference provider.
Submodules¶
Package Contents¶
- class Glyph¶
Bases:
abc.ABCThe Glyph class represents any visible character glyph.
Glyphs are immutable. To change them, create another with different fields and overwrite the previous glyph.
- abstractmethod bake() PIL.Image.Image¶
Return a image rendering of this glyph.
This does not include any right padding.
- Return type:¶
PIL.Image.Image
- abstractmethod get_metrics() GlyphMetrics¶
Return the metrics of this glyph.
- is_empty() bool¶
Return if glyph is entirely empty.
- class HasPriority¶
Bases:
ProtocolPriority indicates a natural ordering to providers.
Providers with a higher priority can overwrite glyphs from lower priorities. A higher number means a higher priority.
Priority is a property of the class, not instances. All instances share the same priority.
- classmethod get_priority() int¶
Return the priority of this type of provider.
-
DEFAULT_PRIORITY : ClassVar[int] =
-1¶
- class Provider[G: mcfonts.glyph.Glyph]¶
Bases:
abc.ABC,collections.abc.MutableMapping[str,G],collections.abc.Container[str]The Provider base class. All providers subclass this.
At the most basic, providers contain mappings of character --> <G>; specific providers define other properties and provider-specific behavior.
All providers have a
ProviderFilterfield.Warning
For most providers, constructor fields do not create glyphs (generally).
Although this may seem counter-intuitive and lengthy, this has the benefit of being able to easily change individual glyphs and fields without needing to "recompile" the entire provider.
It also disconnects providers from I/O (reading files, interpreting them, forming them into glyphs).
Other providers may mutate fields when glyphs are changed - but this is no guarantee. Not all fields will react to changes in the provider's glyphs or other state. For example, fields of a path to an external resource will not update when new glyphs added. Thus, field paths may point to "stale resources" that do not reflect the actual state of the provider currently.
-
abstractmethod __deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
None) Self¶ Return a deep copy of this provider.
In order:
Initialization, field copy
Filter copy
Glyph copy
- get_filter() ProviderFilter | None¶
Return the filter applied to this provider, or None if not set.
- Returns:¶
ProviderFilter, or None if not set.
- Return type:¶
ProviderFilter | None
- classmethod get_pack_versions() tuple[int | None, 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.
- replace_glyphs(original: G, replacement: G) None¶
Replace all instances of a glyph with another. Replacement glyph is copied.
- set_filter(provider_filter: ProviderFilter | None) None¶
Set filter.
- Parameters:¶
- provider_filter : ProviderFilter | None¶
New filter, or None to unset.
- Return type:¶
None
-
abstractmethod __deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
- class ProviderFilter¶
Options in Language --> Font Settings that must be in the given state for the provider to be used.
If None, that option is ignored.
- __copy__() ProviderFilter¶
Return a (deep) copy of this filter.
- classmethod from_dict(contents: collections.abc.Mapping[str, Any]) ProviderFilter¶
Create an instance of ProviderFilter from this dictionary.
- is_default() bool¶
Whether this filter is equal to the default state of settings (all disabled).
- is_enabled_for(game_state: ProviderFilter) bool¶
Return if this filter should allow its provider to show, when given the state of the game options.
- Parameters:¶
- game_state : ProviderFilter¶
Game options as filter.
- Returns:¶
If filter allows provider to show.
- Return type:¶
bool
- is_none() bool¶
Whether this filter is equal to the default state of settings.
- merge(other: ProviderFilter) ProviderFilter¶
Produce a new provider filter merged with another.
Options in other override self, unless they are None.
- Parameters:¶
- other : ProviderFilter¶
Filter that will override.
- Returns:¶
New filter.
- Return type:¶
- to_dict() dict[str, bool]¶
Convert to JSON-compatible dictionary.
Filters of None are
{}.
-
jp : bool | None =
None¶
-
uniform : bool | None =
None¶
- dict_autoset_filter(provider: Provider[Any], base: collections.abc.MutableMapping[str, Any]) None¶
Modify the provider mapping to add applied filter from the provider.
If the provider's filter is equal to the default, it is not added.
- transfer_filters[G1: mcfonts.glyph.Glyph, G2: mcfonts.glyph.Glyph](provider_a: Provider[G1], provider_b: Provider[G2]) None¶
Copy the filter in provider_a over to provider_b.
This function mutates provider_b in-place and returns None. It does not mutate provider_a.
- transfer_glyphs[P: Provider[Any]](provider_from: P, provider_to: P) None¶
Deep copy all glyphs in provider_from over to provider_to.
This function mutates provider_to in-place and returns None. It does not mutate provider_from.
Both providers must be of the same type.