mcfonts.serde.opentype¶
See https://learn.microsoft.com/en-us/typography/opentype/spec/.
Important
Not all OpenType features/tables are supported.
Module Contents¶
- class Direction(*args, **kwds)¶
Bases:
enum.EnumEnumeration of four cardinal directions with associated movement deltas.
- check_backward(point: Point, f: WithinFunc) tuple[Point, Direction] | None¶
Check if moving backward (180 degree turn) is possible.
- check_forward(point: Point, f: WithinFunc) tuple[Point, Direction] | None¶
Check if moving forward is possible.
- check_left(point: Point, f: WithinFunc, cut_corners: bool) tuple[Point, Direction] | None¶
Check if a left turn (relative to current direction) is possible.
- check_right(point: Point, f: WithinFunc) tuple[Point, Direction] | None¶
Check if a right turn is possible.
-
EAST =
(1, 0)¶
- NORTH¶
-
SOUTH =
(0, 1)¶
- WEST¶
- class MetadataOptions¶
- to_name() Name¶
Generate a OpenType NAME table from metadata.
-
author : str | None =
None¶
-
include_credits : bool | None =
None¶
-
license : str | None =
None¶
-
name : str | None =
None¶
- class OpenTypeSaver¶
Bases:
ProtocolProtocol for saving a provider to the OpenType format.
- opentype_save(tables: OpenTypeTables) None¶
Save provider into an OpenType font by modifying its tables.
- Parameters:¶
- tables : OpenTypeTables¶
Table storage.
- Return type:¶
None
- class OpenTypeTables¶
A limited collection of OpenType tables.
- apply_to_builder(builder: fontTools.fontBuilder.FontBuilder) None¶
Apply these tables to a FontBuilder.
- prefill(metadata: MetadataOptions) None¶
- Parameters:¶
- metadata : MetadataOptions¶
- Return type:¶
None
- cmap : Cmap¶
- glyf : Glyf¶
-
glyph_order : GlyphOrder =
[]¶
- head : Head¶
- hhea : Hhea¶
- hmtx : Hmtx¶
- name : Name¶
- os_2 : Os_2¶
- post : Post¶
- class ToTrueTypeGlyph¶
Bases:
ProtocolProtocol for turning a glyph into a OpenType GLYF glyph.
- contours_to_glyph(contours: collections.abc.Iterable[Contour]) fontTools.ttLib.tables._g_l_y_f.Glyph¶
- find_all_contours(f: WithinFunc, xmin: int, xmax: int, ymin: int, ymax: int) collections.abc.Generator[Contour]¶
Find all closed contours in a binary region defined by predicate f.
Scans the bounding box pixel by pixel. Interior regions (holes) are detected as non-border-touching background components and traced in reverse direction (CCW); exterior regions (solids) are CW.
- flood_fill4(filled: list[bytearray], point: Point, f: WithinFunc, xmin: int, xmax: int, ymin: int, ymax: int) bool¶
Perform 4-connected flood fill optimized with span filling.
Marks a region and detects if it touches the image border.
- Parameters:¶
- filled : list[bytearray]¶
2D bytearray grid for marking visited/work pixels.
- point : Point¶
Seed point inside the region.
- f : WithinFunc¶
Predicate defining the region (True if fillable).
- xmin : int¶
Minimum x bound (inclusive).
- xmax : int¶
Maximum x bound (exclusive).
- ymin : int¶
Minimum y bound (inclusive).
- ymax : int¶
Maximum y bound (exclusive).
- Returns:¶
True if the filled region touches the border.
- Return type:¶
bool
- flood_fill8(filled: list[bytearray], point: Point, f: WithinFunc, xmin: int, xmax: int, ymin: int, ymax: int) None¶
Perform simple 8-connected flood fill.
- get_glyph_name(character: str) tuple[int, str]¶
Return tuple of codepoint and suitable glyph name (currently
u<codepoint:04X>as inuA46F).
-
save_font(font: mcfonts.font.MinecraftFont, metadata: MetadataOptions | None =
None) fontTools.ttLib.TTFont¶ - Parameters:¶
- font : mcfonts.font.MinecraftFont¶
- metadata : MetadataOptions | None¶
- Return type:¶
fontTools.ttLib.TTFont
- set_notdef(tables: OpenTypeTables) None¶
- Parameters:¶
- tables : OpenTypeTables¶
- Return type:¶
None
- to_truetype_glyph(glyph: mcfonts.glyph.Glyph, func: WithinFunc) fontTools.ttLib.tables._g_l_y_f.Glyph¶
Generate a glyph, given that glyph and a callable determining how to navigate it.
If the glyph is empty, an empty TTGlyph is returned.
- Parameters:¶
- glyph : mcfonts.glyph.Glyph¶
The glyph to work on.
- func : WithinFunc¶
Callable that returns whether a position has data.
- Return type:¶
fontTools.ttLib.tables._g_l_y_f.Glyph
-
trace(start: Point, f: WithinFunc, direction: Direction =
Direction.EAST, cut_corners: bool =True) Contour¶ Trace a single closed contour starting from a given point.
The algorithm follows a boundary by preferring left turns, then forward, then right turns. It first normalizes the starting point to the top-left most position on the boundary.
- transform_glyph(glyph: fontTools.ttLib.tables._g_l_y_f.Glyph, transform: fontTools.misc.transform.Transform) fontTools.ttLib.tables._g_l_y_f.Glyph¶
-
ACHVENDID_DEFAULT : str =
'pMCF'¶
- type Cmap = dict[int, GlyphName]¶
- type Contour = list[Point]¶
-
EM_SIZE : int =
1024¶
-
GRID_UNVISITED : Final[int] =
0¶
-
GRID_VISITED : Final[int] =
2¶
-
GRID_WORK : Final[int] =
1¶
- type Glyf = dict[GlyphName, TTGlyph]¶
- type GlyphName = str¶
- type GlyphOrder = list[GlyphName]¶
- type Head = dict[str, int]¶
- type Hhea = dict[str, int]¶
- type Hmtx = dict[GlyphName, tuple[int, int]]¶
- NOTDEF_GLYPH : Final[fontTools.ttLib.tables._g_l_y_f.Glyph]¶
-
NOTDEF_NAME : str =
'.notdef'¶
-
NOTDEF_SCALE : int =
128¶
- type Name = dict[int | str, str]¶
- type Os_2 = dict[str, int | str | dict[str, int]]¶
- type Point = tuple[int, int]¶
- type Post = dict[str, int | float]¶
- type WithinFunc = collections.abc.Callable[[Point], bool]¶