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')
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()
Notice how some glyphs can extend below the baseline (red). Additional glyph information can be displayed:
font.glyph('p').describe()
Index | 83 |
Unicode | 0070 |
Character | p |
xmin | 27 |
xmax | 1145 |
ymin | -492 |
ymax | 1118 |
Advance | 1257 |
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)