mcfonts.provider.ttf

A TTF provider, including pre-compiled TTF and OTF fonts.

Module Contents

class TTFProvider(*, file: str, oversample: int, shift: tuple[int, int], size: int, skip: str | collections.abc.Iterable[str] | None)

Bases: mcfonts.provider.Provider[Any], mcfonts.provider.HasPriority, mcfonts.serde.minecraft.MinecraftLoader[TTFProvider], mcfonts.serde.minecraft.MinecraftSaver

The TTF provider embeds compiled TrueType and OpenType fonts.

Danger

This class does not provide access to the characters and glyphs in the embedded font. All glyph-related methods will return None or be empty.

Initialize.

Parameters:
file : str

Resource location to a .ttf or .otf file.

oversample : int

Resolution to render at.

shift : tuple[int, int]

Tuple of horizontal and vertical shifts.

size : int

Size of rendered glyphs.

skip : str | collections.abc.Iterable[str] | None

Characters to not include.

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

Return type:

bool

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

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:

TTFProvider

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

Return type:

None

__getitem__(item: str) Never
Parameters:
item : str

Return type:

Never

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

collections.abc.Generator[str]

__len__() int
Return type:

int

__repr__() str

Return TTFProvider(x characters).

Return type:

str

__setitem__(key: str, value: object)
Parameters:
key : str

value : object

Return type:

None

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

dict[str, Any]

get_file() str
Return type:

str

get_font() fontTools.ttLib.ttFont.TTFont
Return type:

fontTools.ttLib.ttFont.TTFont

classmethod get_glyph_type() type[Any]

Return the type of Glyph this provider uses.

Returns:

Type of Glyph.

Return type:

type[Any]

get_oversample() int
Return type:

int

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

get_shift() tuple[int, int]
Return type:

tuple[int, int]

get_size() int
Return type:

int

get_skip() str
Return type:

str

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

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:

TTFProvider

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

set_file(value: str) None
Parameters:
value : str

Return type:

None

set_font(value: fontTools.ttLib.ttFont.TTFont) None
Parameters:
value : fontTools.ttLib.ttFont.TTFont

Return type:

None

set_oversample(value: int) None
Parameters:
value : 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

set_shift(value: tuple[int, int]) None
Parameters:
value : tuple[int, int]

Return type:

None

set_size(value: int) None
Parameters:
value : int

Return type:

None

set_skip(value: str | collections.abc.Iterable[str] | None) None

Set the skip field.

Parameters:
value : str | collections.abc.Iterable[str] | None

New skip, or None to unset.

Return type:

None

max_width : ClassVar[int] = 512
priority : ClassVar[int] = 2