Package: glyphtools
glyphtoolsRoutines for extracting information from font glyphsglyphtools.bin_glyphs_by_metric(font, glyphs, category,
bincount=5)Organise glyphs according to a given metric.Organises similar glyphs into a number of bins. The bins are not
guaranteed to contain the same number of glyphs; the
one-dimensional ckmeans clustering algorithm is used to cluster
glyphs based on metric similarity. For example, if there are five
glyphs of width 100, 102, 105, 210, and 220 units respectively, and
you ask for two bins, the first bin will contain three glyphs and
the second will contain two. This is usually what you want.Parameters:font– afontToolsTTFont object OR aglyphsLibGSFontMaster object OR ababelfontFont object.glyphs– a collection of glyph namescategory– the metric (see metric keys inget_glyph_metrics().)bincount– number of bins to returnReturns:A list ofbincounttwo-element tuples. The first element is
a list of glyphnames in this bin; the second is the average
metric value of the glyphs in this bin.glyphtools.categorize_glyph(font, glyphname)Returns the category of the given glyph.Parameters:font– afontToolsTTFont object OR aglyphsLibGSFontMaster object OR ababelfontFont object.glyphname– name of the glyph.Returns:A two-element tuple. The first element is one of the following
strings:unknown,base,mark,ligature,component. If the glyph is a mark, the second element is the
mark attachment class number.glyphtools.determine_kern(font, glyph1, glyph2, targetdistance,
offset1=0, 0, offset2=0, 0, maxtuck=0.4)Determine a kerning value required to set two glyphs at given
ink-to-ink distance.The value is bounded by themaxtuckparameter. For example, ifmaxtuckis 0.20, the right glyph will not be placed any further
left than 80% of the width of left glyph, even if this places the
ink further thantargetdistanceunits away.Parameters:font– afontToolsTTFont object OR aglyphsLibGSFontMaster object  OR ababelfontFont object.glyph1– name of the left glyph.glyph2– name of the right glyph.targetdistance– distance to set the glyphs apart.offset1– offset (X-coordinate, Y-coordinate) to placeleft glyph.offset2– offset (X-coordinate, Y-coordinate) to placeright glyph.maxtuck– maximum proportion of the left glyph’s width tokern.Returns: A kerning value, in units.glyphtools.duplicate_glyph(font, existing, new)Add a new glyph to the font duplicating an existing one.Parameters:font– ababelfontFont object.existing– name of the glyph to duplicate.new– name of the glyph to add.glyphtools.get_glyph_metrics(font, glyphname)Returns glyph metrics as a dictionary.Parameters:font– afontToolsTTFont object OR aglyphsLibGSFontMaster object OR ababelfontFont object.glyphname– name of the glyph.Returns:width: Advance width of the glyph. lsb: Left side-bearing rsb:
Right side-bearing xMin: minimum X coordinate xMax: maximum X
coordinate yMin: minimum Y coordinate yMax: maximum Y coordinate
rise: difference in Y coordinate between cursive entry and exitReturn type:A dictionary with the following keysglyphtools.set_glyph_category(font, glyphname, category,
maClass=None)Sets the category of the glyph in the font.Parameters:font– afontToolsTTFont object OR aglyphsLibGSFontMaster object OR ababelfontFont object.glyphname– name of the glyph.category– one ofbase,mark,ligature,component.maClass– If the category isbase, the markattachment class number.Free software: Apache Software License 2.0Documentation:https://glyphtools.readthedocs.io.History0.1.0 (2020-08-10)First release on PyPI.