Drawing Glyphs

At a lower level, Ziafont can also draw individual glyphs. The glyph for a string character can be obtained from ziafont.font.Font.glyph(). Similar to ziafont.font.Text(), this method returns a Glyph object with methods for returning SVG as a string or as an SVG XML element.

font.glyph('D')
_images/glyphs_1_0.svg
font.glyph('D').svgxml()
<Element 'svg' at 0x7ff1b0640770>

The above svg and svgxml methods both return the glyph in a standalone SVG. Often, however, the glyph should be added to an existing drawing or used elsewhere. The svgpath method returns the glyph as an SVG <path> element that can be inserted in an existing SVG. Alternatively, the svgsymbol method wraps the <path> in an SVG <symbol> element that can be reused multiple times in the same drawing.


Test Mode

To view the control points of a glyph path, use the test method:

font.glyph('p').test()
_images/glyphs_3_0.svg

Notice how some glyphs can extend below the baseline (red). Additional glyph information can be displayed:

font.glyph('p').describe()
Index83
Unicode0070
Characterp
xmin27
xmax1145
ymin-492
ymax1118
Advance1257

Glyph Indexes

The glyph index refers to its position within the font file, not necessarily the unicode representation of the character. The index for a given character in the font can be obtained:

font.glyphindex('&')
9
font.glyph_fromid(9)
_images/glyphs_6_0.svg