Skip to content

Glyphs

Bases: dict

A glyph dictionary, mapping single chars or groups of chars (ligatures) to glyphs.

line_height property

line_height

Line height of glyphs.

bg_boundary classmethod

bg_boundary(left, right, spacing)

Calculates the background boundary between two glyphs.

Parameters:

Name Type Description Default

left

List[str]

Left glyph.

required

right

List[str]

Right glyph.

required

spacing

int

Space between left and right in number of cells.

required

Returns:

Type Description
List[int]

List[int]: Boundary in offsets from the end of the left glyph.

boundary classmethod

boundary(left, right, spacing)

Calculates the boundary between two glyphs.

Parameters:

Name Type Description Default

left

List[str]

Left glyph.

required

right

List[str]

Right glyph.

required

spacing

int

Space between left and right in number of cells.

required

Returns:

Type Description
List[int]

List[int]: Boundary in offsets from the end of the left glyph.

from_lines classmethod

from_lines(chars, *glyphs, separator=None)

Create a Glyphs instance from lines.

Parameters:

Name Type Description Default

chars

Union[str, List[str]]

String of chars or list of char groups in the same order as glyphs.

required

*glyphs

str

Lines of concatenated glyphs, delimited by full column of separator char.

()

separator

str

Separator char used to separate individual glyphs. Defaults to space.

None

Raises:

Type Description
ValueError

Glyph lines are of unequal length.

ValueError

Number of glyphs does not match number of chars.

get_char_map classmethod

get_char_map(chars, *glyphs, separator=None)

Map chars to split glyphs. Glyphs are split at every full column of the separator char.

Parameters:

Name Type Description Default

chars

Union[List[str], str]

String or List of chars.

required

glyphs

List[str]

Lines of concatenated glyphs, delimited by full column of separator.

()

separator

Optional[str]

description. Defaults to None.

None

Raises:

Type Description
ValueError

Number of glyphs does not match number of chars.

Returns:

Type Description
Dict[str, Glyph]

Dict[str, List[str]]: Char to glyph map.

line_lead classmethod

line_lead(line)

Get number of leading whitespace.

Parameters:

Name Type Description Default

line

str

Line of text.

required

Returns:

Name Type Description
int int

Leading whitespace count.

line_trail classmethod

line_trail(line)

Get number of trailing whitespace.

Parameters:

Name Type Description Default

line

str

Line of text.

required

Returns:

Name Type Description
int int

Trailing whitespace count.

max_overlap classmethod

max_overlap(left, right)

Calculates the maximum number of cells two glyphs can overlap without occluding each other.

Parameters:

Name Type Description Default

left

List[str]

Left glyph.

required

right

List[str]

Right glyph.

required

Returns:

Name Type Description
int int

Max overlap in number of cells.

merge classmethod

merge(left, right, spacing=0)

Merges two glyphs. In case of overlapping non-space characters, the right glyph will occlude the left glyph.

Parameters:

Name Type Description Default

left

List[str]

Left glyph.

required

right

List[str]

Right glyph.

required

spacing

int

Space between left and right in number of cells. Defaults to 0.

0

Returns:

Name Type Description
Glyph Glyph

Merged glyph.

merge_line classmethod

merge_line(left, right, spacing=0)

Merge two lines. In case of overlapping non-space characters, the right line will occlude the left line.

Parameters:

Name Type Description Default

left

str

Left line.

required

right

str

Right line.

required

spacing

int

Space between left and right in number of cells. Defaults to 0.

0

Returns:

Name Type Description
str str

Merged line.