API

class ziafont.font.Font(name: str | Path | None = None)

Class to read/parse a OpenType/TTF and write glyphs to SVG

Parameters:

name – File name of the font. Defaults to DejaVuSans.

advance(glyph1: int, glyph2: int | None = None)

Get advance width in font units, including kerning adjustment if glyph2 is defined

getsize(s) tuple[float, float]

Calculate width and height (including ascent/descent) of string

glyph(char: str) SimpleGlyph

Get the Glyph for the character

glyph_fromid(glyphid: int) SimpleGlyph | CompoundGlyph

Read a glyph from the “glyf” table

Parameters:

glyphid – Glyph index used to find glyph data

glyphindex(char: str) int

Get index of character glyph

language(script, language)

Set script/language to use

languages(script='DFLT')

Get list of languages in the script

scripts()

Get list of scripts in the font

text(s: str, size: float | None = None, linespacing: float = 1, halign: Literal['left', 'center', 'right'] = 'left', valign: Literal['base', 'center', 'top'] = 'base', color: str | None = None, rotation: float = 0, rotation_mode: str = 'anchor')

Create a Text object using this font

Parameters:
usecmap(cmapidx: int) None

Select cmap table by index. Only supported tables are included.

verifychecksum() None

Verify checksum of all font tables. Raises ValueError if invalid

class ziafont.font.Text(s: str | Sequence[int], font: str | Font | None = None, size: float | None = None, linespacing: float = 1, halign: Literal['left', 'center', 'right'] = 'left', valign: Literal['base', 'center', 'top'] = 'base', color: str | None = None, rotation: float = 0, rotation_mode: str = 'anchor')

Draw text as SVG paths

Parameters:
drawon(svg: Element, x: float = 0, y: float = 0)

Draw text on the SVG

getsize() tuple[float, float]

Calculate width and height (including ascent/descent) of string

getyofst() float

Y-shift from bottom of bbox to 0

svg() str

Get SVG string

svgxml() Element

Get SVG XML element

class ziafont.glyph.SimpleGlyph(index: int, operators: Sequence[SVGOpType], bbox: BBox, font: Font)

Simple Glyph

advance(nextchr=None) float

Get advance width in glyph units, including kerning if nextchr is defined

property char: set[str]

Get set of unicode character represented by this glyph

describe() DescribeGlyph

Get Glyph Test representation showing vertices and borders

funits_to_points(value: float, scale_factor: float = 1) float

Convert font units to points

place(x: float, y: float, point_size: float) Element | None

Get <use> svg tag translated/scaled to the right position

svg(point_size: float | None = None) str

Get SVG as string

svgpath(x0: float = 0, y0: float = 0, scale_factor: float = 1) Element | None

Get svg <path> element for glyph, normalized to 12-point font

svgsymbol() Element

Get svg <symbol> element for this glyph, scaled to 12-point font

svgxml(point_size: float | None = None) Element

Standalong SVG

test(pxwidth: float = 400, pxheight: float = 400) InspectGlyph

Get Glyph Test representation showing vertices and borders

class ziafont.glyph.CompoundGlyph(index: int, glyphs: GlyphComp, font: Font)

Compound glyph, made of multiple other Glyphs

class ziafont.config.Config(svg2: bool = True, debug: bool = False, fontsize: float = 48, precision: float = 3)

Global configuration options for Ziafont

svg2

at the expense of SVG size

Type:

Use SVG2.0. Disable for better browser compatibility

debug
Type:

Debug mode, draws bounding boxes around text

fontsize
Type:

Default font size in points

precision
Type:

Decimal precision for SVG coordinates