mcfonts.provider.space

A space provider, defining simple widths for characters.

Module Contents

class SpaceProvider(*, advances: collections.abc.Mapping[str, int])

Bases: mcfonts.provider.Provider[mcfonts.glyph.space.SpaceGlyph], mcfonts.provider.HasPriority, mcfonts.serde.minecraft.MinecraftLoader[SpaceProvider], mcfonts.serde.minecraft.MinecraftSaver, mcfonts.serde.opentype.OpenTypeSaver, mcfonts.serde.yaff.YaffSaver, mcfonts.render.Renderable

The space provider defines only the width of a character.

The keys of the "advances" field are the characters as 1-length strings, and the values are integer widths.

Initialize.

Parameters:
advances : collections.abc.Mapping[str, int]

Advances dictionary of character to width.

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

Return type:

bool

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

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:

SpaceProvider

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

Return type:

None

__getitem__(item: str) mcfonts.glyph.space.SpaceGlyph
Parameters:
item : str

Return type:

mcfonts.glyph.space.SpaceGlyph

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

collections.abc.Generator[str]

__len__() int
Return type:

int

__repr__() str

Return SpaceProvider(x characters).

Return type:

str

__setitem__(key: str, value: mcfonts.glyph.space.SpaceGlyph)
Parameters:
key : str

value : mcfonts.glyph.space.SpaceGlyph

Return type:

None

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

dict[str, Any]

get_advances() dict[str, int]
Return type:

dict[str, int]

classmethod get_glyph_type() type[mcfonts.glyph.space.SpaceGlyph]

Return the type of Glyph this provider uses.

Returns:

Type of Glyph.

Return type:

type[mcfonts.glyph.space.SpaceGlyph]

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

classmethod minecraft_load(root: mcfonts.path.PackRoot, resource_location: str, contents: collections.abc.Mapping[str, Any]) SpaceProvider

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:

SpaceProvider

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_advances(value: collections.abc.Mapping[str, int]) None
Parameters:
value : collections.abc.Mapping[str, int]

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

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] = 4
check_character(character: str) None
Parameters:
character : str

Return type:

None

to_glyph_sizes(advances: collections.abc.Mapping[str, int], *, default_width: tuple[int, int] = (0, 14)) bytearray

Create a glyph_sizes.bin bytearray from a template of characters and their starting and ending positions.

>>> to_glyph_sizes({"\0": 15}, (0, 0))
bytearray(b'\x0e\x00\x00\x00...')
Parameters:
advances : collections.abc.Mapping[str, int]

A dictionary of {character: width}.

default_width : tuple[int, int]

The width to fall back to if advances doesn't define one for a character.

Returns:

Bytearray of glyph_sizes.bin.

Return type:

bytearray