Skip to main content

Routines for extracting information from fontTools glyphs

Project description

glyphtools

https://img.shields.io/pypi/v/glyphtools.svg https://img.shields.io/travis/simoncozens/glyphtools.svg Documentation Status

Routines for extracting information from font glyphs

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. 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 – a fontTools TTFont object OR a glyphsLib GSFontMaster object OR a babelfont 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 bincount two-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 – a fontTools TTFont object OR a glyphsLib GSFontMaster object OR a babelfont 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.

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, if maxtuck 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 than targetdistance units away.

Parameters:
  • font – a fontTools TTFont object OR a glyphsLib GSFontMaster object OR a babelfont 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.

glyphtools.duplicate_glyph(font, existing, new)

Add a new glyph to the font duplicating an existing one.

Parameters:
  • font – a babelfont Font 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 – a fontTools TTFont object OR a glyphsLib GSFontMaster object OR a babelfont Font 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 exit

Return type:

A dictionary with the following keys

glyphtools.set_glyph_category(font, glyphname, category, maClass=None)

Sets the category of the glyph in the font.

Parameters:
  • font – a fontTools TTFont object OR a glyphsLib GSFontMaster object OR a babelfont 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.

History

0.1.0 (2020-08-10)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glyphtools-0.6.2.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

glyphtools-0.6.2-py2.py3-none-any.whl (9.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file glyphtools-0.6.2.tar.gz.

File metadata

  • Download URL: glyphtools-0.6.2.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for glyphtools-0.6.2.tar.gz
Algorithm Hash digest
SHA256 93d2c85299b2e980cba81bfce1e4f17d5c9f9f17d26f8f5e5b1139aeb5e9a4e7
MD5 b4d6d3ad8c5c9a2eda9d7e75c5adbca6
BLAKE2b-256 4b4a752378891d680bc306b229d0f9e4933a3e69f48b41d14b1614f8435ad790

See more details on using hashes here.

File details

Details for the file glyphtools-0.6.2-py2.py3-none-any.whl.

File metadata

  • Download URL: glyphtools-0.6.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for glyphtools-0.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b6e342c317fdf806799a0e60dfc7b9ec30d441a66ad2c325469fefafb630d13e
MD5 8470f02f43f5b5b3c31eb4bc8bd4def7
BLAKE2b-256 a1cb3d0ccf065482fb5cddbd4994d89889ac7eb2ca17a425a26d6d226ff6932e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page