Skip to main content

glyphtools

https://img.shields.io/pypi/v/glyphtools.svg https://github.com/simoncozens/glyphtools/actions/workflows/ci.yml/badge.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.

Metadata

Release files for glyphtools 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for glyphtools 0.9.0
File Size Uploaded Provenance Actions
glyphtools-0.9.0.tar.gz 12.7 kB Without provenance Details for glyphtools-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for glyphtools 0.9.0
File Interpreter ABI Platform Actions
glyphtools-0.9.0-py3-none-any.whl Python 3 none any Details for glyphtools-0.9.0-py3-none-any.whl

Total release size: 22.5 kB

Release files / glyphtools-0.9.0.tar.gz

Download URL glyphtools-0.9.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ada22f65ddffc79b09a5155ef8818e6a63e6564e8b7e467335bafc0d0c146b1f
BLAKE2b-256 checksum
How to use checksums
b22651a16ee8998b5818288853d4b944239b8bfdc00ec6c4bb5e8157adcbe34c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / glyphtools-0.9.0-py3-none-any.whl

Download URL glyphtools-0.9.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1467d8fe3938f4933dc863b1bce4ea326a080bf1d095216d9cfe8bda9bb2044b
BLAKE2b-256 checksum
How to use checksums
fc756c53329fbde76358aa9ec286f8d8506c9b11fdc72679b7daca151d15d07d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for glyphtools 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page