API¶
- class ziafont.font.Font(name=None, searchpaths=None)¶
Class to read/parse a OpenType/TTF and write glyphs to SVG
- Parameters:
name – File name of the font. Defaults to DejaVuSans.
- advance(glyph, glyph2)¶
Get advance width in font units
- Return type:
int
- getsize(s)¶
Calculate width and height (including ascent/descent) of string
- Return type:
tuple[float,float]
- glyph(char)¶
Get the Glyph for the character
- Return type:
- glyph_fromid(glyphid)¶
Read a glyph from the “glyf” table
- Return type:
Union[SimpleGlyph,CompoundGlyph]- Parameters:
glyphid – Glyph index used to find glyph data
- glyphindex(char)¶
Get index of character glyph
- Return type:
int
- 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, size=None, linespacing=1, halign='left', valign='base', color=None, rotation=0, rotation_mode='anchor')¶
Create a Text object using this font
- Parameters:
s – String to convert.
size – Font size in points
linespacing – Space between lines
halign – Horizontal Alignment
valign – Vertical Alignment
color – Color for string
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 font kerning adjustment
- usecmap(cmapidx)¶
Select cmap table by index. Only supported tables are included.
- Return type:
None
- verifychecksum()¶
Verify checksum of all font tables. Raises ValueError if invalid
- Return type:
None
- class ziafont.font.Text(s, font=None, size=None, linespacing=1, halign='left', valign='base', color=None, rotation=0, rotation_mode='anchor')¶
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
- drawon(svg, x=0, y=0)¶
Draw text on the SVG
- getsize()¶
Calculate width and height (including ascent/descent) of string
- Return type:
tuple[float,float]
- getyofst()¶
Y-shift from bottom of bbox to 0
- Return type:
float
- svg()¶
Get SVG string
- Return type:
str
- svgxml()¶
Get SVG XML element
- Return type:
Element
- class ziafont.glyph.SimpleGlyph(index, operators, bbox, font)¶
Simple Glyph
- advance(nextchr=None)¶
Get advance width in glyph units
- Return type:
int
- property char: set[str]¶
Get set of unicode character represented by this glyph
- describe()¶
Get Glyph Test representation showing vertices and borders
- Return type:
- funits_to_points(value, scale_factor=1)¶
Convert font units to points
- Return type:
float
- place(x, y, point_size)¶
Get <use> svg tag translated/scaled to the right position
- Return type:
Optional[Element]
- svg(point_size=None)¶
Get SVG as string
- Return type:
str
- svgpath(x0=0, y0=0, scale_factor=1)¶
Get svg <path> element for glyph, normalized to 12-point font
- Return type:
Optional[Element]
- svgsymbol()¶
Get svg <symbol> element for this glyph, scaled to 12-point font
- Return type:
Element
- svgxml(point_size=None)¶
Standalong SVG
- Return type:
Element
- test(pxwidth=400, pxheight=400)¶
Get Glyph Test representation showing vertices and borders
- Return type:
- property viewbox: tuple[float, float, float, float]¶
Get viewbox of Glyph
- class ziafont.glyph.CompoundGlyph(index, glyphs, font)¶
Compound glyph, made of multiple other Glyphs
- class ziafont.config.Config(svg2=True, debug=False, fontsize=48, precision=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
Font and Glyph Inspection¶
- class ziafont.inspect.DescribeFont(font)¶
Display Font Metadata in HTML table
- format_languages()¶
Format the scripts/languages in the font
- table()¶
Generate the HTML table
- class ziafont.inspect.InspectGlyph(glyph, pxwidth=400, pxheight=400)¶
Draw glyph svg with test/debug lines
- svg()¶
Glyph SVG string
- Return type:
str
- svgxml()¶
Glyph svg as XML element tree
- Return type:
Element
- class ziafont.inspect.DescribeGlyph(glyph)¶
HTML Table of Glyph information
- describe()¶
HTML table with glyph parameters
- class ziafont.inspect.ShowGlyphs(font, size=36, columns=15, nmax=None)¶
Show all glyphs in the font in HTML table
- table()¶
Build HTML table
- Return type:
str
- class ziafont.inspect.ShowFeature(featname, font, size=36)¶
Show all lookup tables in a feature