API

class ziafont.font.Font(name: Optional[Union[str, Path]] = None, style: str = 'regular')

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

Parameters
  • name – File name of the font

  • style – Font style such as “bold” or “italic”, used when searching system paths for a font file

advance(glyph1: int, glyph2: Optional[int] = None, kern: bool = True)

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) Union[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

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

Create a Text object using this font

Parameters
usecmap(cmapidx: int) None

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

verifychecksum()

Verify checksum of all font tables. Raises ValueError if invalid

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

Draw text as SVG paths

Parameters
  • s – String to draw

  • font – Font name or ziafont.Font to use

  • size – Font size in points

  • linespacing – Spacing between lines

  • color – Color for string

  • halign – Horizontal Alignment

  • valign – Vertical Alignment

  • rotation – Rotation angle in degrees

  • rotation_mode – Either ‘default’ or ‘anchor’, to mimic Matplotlib behavoir. See: https://matplotlib.org/stable/gallery/text_labels_and_annotations/demo_text_rotation_mode.html

  • kern – Use kerning adjustment

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, path: GlyphPath, font, char: Optional[str] = None)

Simple Glyph

advance(nextchr=None, kern=True)

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

place(x, y, fontsize)

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

svg(fontsize: Optional[float] = None, svgver=2) str

Get SVG as string

svgpath(x0=0, y0=0, scale=1) Element

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(fontsize: Optional[float] = None, svgver=2) Element

Standalong SVG

test() TestGlyph

Get Glyph Test representation showing vertices and borders

class ziafont.glyph.CompoundGlyph(index: int, glyphs: GlyphComp, font, char: Optional[str] = None)

Compound glyph, made of multiple other Glyphs

class ziafont.config.Config

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