mcfonts.provider.bitmap¶
A bitmap provider, handling PNG glyphs.
Module Contents¶
- class BitmapProvider(*, ascent: int, chars: collections.abc.Sequence[str], file: str, height: int | None)¶
Bases:
mcfonts.provider.Provider[mcfonts.glyph.bitmap.BitmapGlyph],mcfonts.provider.HasPriority,mcfonts.serde.minecraft.MinecraftLoader[BitmapProvider],mcfonts.serde.minecraft.MinecraftSaver,mcfonts.serde.opentype.OpenTypeSaver,mcfonts.serde.unihex.UnihexSaver,mcfonts.serde.yaff.YaffSaver,mcfonts.render.RenderableThe bitmap provider defines simple bitmap glyphs from a texture.
The texture is evenly divided according to the number of entries and the length of the items of the "chars" field.
When adding new glyphs for characters, that character must exist in the
charslist. If it does not exist, aValueErrorwill be raised. Characters must be added to the chars list beforehand; this is not done automatically.Initialize.
- Parameters:¶
-
__deepcopy__(memodict: collections.abc.Mapping[Any, Any] | None =
None) BitmapProvider¶ Return a deep copy of this provider.
In order:
Initialization, field copy
Filter copy
Glyph copy
- __setitem__(key: str, value: mcfonts.glyph.bitmap.BitmapGlyph)¶
- Parameters:¶
- key : str¶
- value : mcfonts.glyph.bitmap.BitmapGlyph¶
- Return type:¶
None
- get_ascent() int¶
Get the ascent field.
The ascent is always less than the height.
- classmethod get_glyph_type() type[mcfonts.glyph.bitmap.BitmapGlyph]¶
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.
- classmethod minecraft_load(root: mcfonts.path.PackRoot, resource_location: str, contents: collections.abc.Mapping[str, Any]) BitmapProvider¶
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
- 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
-
default_height : ClassVar[int] =
8¶
- invalid_codepoints : ClassVar[set[int]]¶
-
priority : ClassVar[int] =
3¶
- image_from_provider(provider: BitmapProvider) PIL.Image.Image¶
Return an
Imagethat reflects the current state of provider.Assumes the first glyph's dimensions are equal for all other glyphs.
This function does not use the provider's
filefield: the image is built from its glyphs.- Parameters:¶
- provider : BitmapProvider¶
- Return type:¶
PIL.Image.Image
-
image_to_sequential_chars(image: PIL.Image.Image, character: str, cell_bounds: tuple[int, int] =
(8, 8)) collections.abc.Generator[str]¶ Given a path to a image and a starting character, return an appropriate chars list.
Return a provider that has a charlist that correctly encompasses all chars covered by the resource. Glyphs in the resource that are empty are skipped.
- Parameters:¶
- image : PIL.Image.Image¶
The image to grab glyph textures from.
- character : str¶
A single character of the starting point. The codepoint of this will increase by 1 on every glyph.
- cell_bounds : tuple[int, int]¶
The dimensions of an individual glyph in image. Glyph dimensions must be the same throughout the whole of image.
- Returns:¶
A valid
charslist.- Return type:¶
collections.abc.Generator[str]