Welcome to glyphtools’s documentation!¶
glyphtools is a set of routines for extracting information from font glyphs.
-
glyphtools.
categorize_glyph
(font, glyphname)¶ Return the category of the given glyph.
Parameters: - font – a
fontTools
TTFont object OR aglyphsLib
GSFontMaster object OR ababelfont
Font 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.- font – a
-
glyphtools.
set_glyph_category
(font, glyphname, category, maClass=None)¶ Set the category of the glyph in the font.
Parameters: - font – a
fontTools
TTFont object or aglyphsLib
GSFontMaster object OR ababelfont
Font object. - glyphname – name of the glyph.
- category – one of
base
,mark
,ligature
,component
. - maClass – If the category is
base
, the mark attachment class number.
- font – a
-
glyphtools.
get_glyph_metrics
(font, glyphname, **kwargs)¶ Return glyph metrics as a dictionary.
Parameters: - font – a
fontTools
TTFont object or aglyphsLib
GSFontMaster object OR ababelfont
Font object. - glyphname – name of the glyph.
- Returns: A dictionary with the following keys:
width
: Advance width of the glyph.lsb
: Left side-bearingrsb
: Right side-bearingxMin
: minimum X coordinatexMax
: maximum X coordinateyMin
: minimum Y coordinateyMax
: maximum Y coordinatefullwidth
: xMax - xMinrise
: difference in Y coordinate between cursive entry and exit
- font – a
-
glyphtools.
get_rise
(font, glyphname, **kwargs)¶ Return the Arabic rise of the glyph (Y difference between entry and exit).
-
glyphtools.
get_run
(font, glyphname, **kwargs)¶ Return the Arabic run of the glyph (X difference between entry and exit).
-
glyphtools.
bin_dictionary
(d, bincount=5)¶ Organise a dictionary into a number of bins.
The bins are not guaranteed to contain the same number of entries; the one-dimensional ckmeans clustering algorithm is used to cluster entries based on value similarity. For example, if there are five entries in the dictionary with values of 100, 102, 105, 210, and 220 respectively, and you ask for two bins, the first bin will contain three entries and the second will contain two. This is usually what you want.
- Returns: An list
bincount
two-element tuples. The first element is a - list of dictionary keys in this bin; the second is the average value of the items in this bin.
- Returns: An list
-
glyphtools.
bin_glyphs_by_metric
(font, glyphs, category, bincount=5)¶ Organise glyphs according to a given metric.
Organises similar glyphs into a number of bins. See documentation for
bin_dictionary()
above.Parameters: - font – a
fontTools
TTFont object or aglyphsLib
GSFontMaster object OR ababelfont
Font object. - glyphs – a collection of glyph names
- category – the metric (see metric keys in
get_glyph_metrics()
.) - bincount – number of bins to return
Returns: A list of
- font – a
-
glyphtools.
get_beziers
(font, glyph)¶ Return the glyph as a set of
beziers.BezierPath
objects.Parameters: - font – a
fontTools
TTFont object or aglyphsLib
GSFontMaster object OR ababelfont
Font object. - glyph – name of the glyph.
Returns: A list of
BezierPath
objects.- font – a
-
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 the
maxtuck
parameter. For example, ifmaxtuck
is 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 thantargetdistance
units away.Parameters: - font – a
fontTools
TTFont object or aglyphsLib
GSFontMaster object OR ababelfont
Font 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 place left glyph.
- offset2 – offset (X-coordinate, Y-coordinate) to place right glyph.
- maxtuck – maximum proportion of the left glyph’s width to kern.
Returns: A kerning value, in units.
- font – a
-
glyphtools.
duplicate_glyph
(babelfont, existing, new)¶ Add a new glyph to the font duplicating an existing one.
Parameters: - font – a
babelfont
/fontParts
Font object. - existing – name of the glyph to duplicate.
- new – name of the glyph to add.
- font – a
Installation¶
Stable release¶
To install glyphtools, run this command in your terminal:
$ pip install glyphtools
This is the preferred method to install glyphtools, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for glyphtools can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/simoncozens/glyphtools
Or download the tarball:
$ curl -OJL https://github.com/simoncozens/glyphtools/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install