Skip to main content

Utility FontForge_plugin on references and selections

Project description

Fontforge Utility Plugin on References and Selections

This plugin helps finding:

  • Glyphs with nested references and flatten such references
  • Glyphs with distorted references and unlink references
  • Unused glyphs and remove them

Required Python version is:

  • 3.9 to 3.11 for limited features
    • "Select unused glyphs" menu will be disabled in this case due to possible crash
  • 3.12 or later for full features

Details

Glyphs with nested references

Nested references are known to cause problems in certain environments. More information can be found at fontbakery issue 2961 and arrowtype issue 412.

Glyphs with distorted references

While each references can have affine transformation, ttfautohint tool cannot deal with distorted references well. Unlinking such references will be needed if you plan to use ttfautohint.

Unused glyphs (Python ≥ 3.12 only)

When a glyph is expressed as unused or unreachable, such glyphs neither has Unicode encodings nor is referenced from another glyph or a GSUB table. They can be dropped to reduce the file size.

Install

pip3 install fontforge-ref-sel-util

Make sure Fontforge Python module is usable

In interactive mode of Python, run:

import fontforge

If it raises ModuleNotFoundError exception, install Fontforge first. If installed, make sure the build option set that the Python module gets also installed. If already so, Python interpreter does not recognize the module path where the required module.

export PYTHONPATH=/path/to/fontforge/python/module:$PYTHONPATH

Usage

In Fontforge GUI

This plugin adds following items into "Tools" menu:

  • Select
    • Glyphs with nested references
    • Glyphs with distorted references
    • Unused glyphs
  • Decompose nested references

In Python script

import fontforge
import fontforge_refsel

font = fontforge.open('path/to/font.sfd')

# Select glyphs with nested references
fontforge_refsel.selectGlyphsWithNestedRefs(font)      # set selection
fontforge_refsel.selectGlyphsWithNestedRefs(font, 0)   # set selection
fontforge_refsel.selectGlyphsWithNestedRefs(font, 1)   # append selection
fontforge_refsel.selectGlyphsWithNestedRefs(font, -1)  # deselect

# Select glyphs with distorted references
# (i.e. non-identity linearly transformed references)
fontforge_refsel.selectGlyphsWithDistortedRefs(font)      # set selection
fontforge_refsel.selectGlyphsWithDistortedRefs(font, 0)   # set selection
fontforge_refsel.selectGlyphsWithDistortedRefs(font, 1)   # append selection
fontforge_refsel.selectGlyphsWithDistortedRefs(font, -1)  # deselect

# Select unreachable glyphs
fontforge_refsel.selectUnusedGlyphs(font)      # set selection
fontforge_refsel.selectUnusedGlyphs(font, 0)   # set selection
fontforge_refsel.selectUnusedGlyphs(font, 1)   # append selection
fontforge_refsel.selectUnusedGlyphs(font, -1)  # deselect

# Check a glyph
glyph = font['foo']
result = fontforge_refsel.glyphHasNestedRefs(glyph)
result = fontforge_refsel.glyphHasDistortedRefs(glyph)
result = glyph.glyphname in fontforge_refsel.unusedGlyphs(font)

# List of glyphs with...
result = [glyph.glyphname for glyph in filter(fontforge_refsel.glyphHasNestedRefs, font.glyphs())]
result = [glyph.glyphname for glyph in filter(fontforge_refsel.glyphHasDistortedRefs, font.glyphs())]
result = list(fontforge_refsel.unusedGlyphs(font))  # unusedGlyphs() returns a frozenset object

# Decompose nested references
fontforge_refsel.decomposeNestedRefs(font)         # selected glyphs
fontforge_refsel.decomposeNestedRefs(font, False)  # selected glyphs
fontforge_refsel.decomposeNestedRefs(font, True)   # all glyphs
# if no glyphs are selected, processes all glyphs

# Unlink distorted references (Python < 3.12 may crash)
fontforge_refsel.selectGlyphsWithDistortedRefs(font)
font.unlinkReferences()
font.removeOverlap()  # may or may not needed

# Drop unused glyphs (Python < 3.12 may crash)
for glyph in fontforge_refsel.unusedGlyphs(font):
    font.removeGlyph(glyph)

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

fontforge_ref_sel_util-0.1.4.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fontforge_ref_sel_util-0.1.4-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file fontforge_ref_sel_util-0.1.4.tar.gz.

File metadata

  • Download URL: fontforge_ref_sel_util-0.1.4.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fontforge_ref_sel_util-0.1.4.tar.gz
Algorithm Hash digest
SHA256 26fa8295ca4166af046c3780fdee6170d2134526a52e49c447156255f7c47e2b
MD5 1343f52d2e459af33f9bf3c5eda624a4
BLAKE2b-256 4b46d65ec9d937e62dfce9a96110687c7e0a8efa5c3042de4be035e4646989bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fontforge_ref_sel_util-0.1.4.tar.gz:

Publisher: python-publish.yml on MihailJP/fontforge-ref-sel-util

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fontforge_ref_sel_util-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fontforge_ref_sel_util-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8cf91371d4ff8b7b521ced03886727d52888f311960b663fa304b4dcdcca8a7d
MD5 271b787e3c1edab655645952ee7a55a9
BLAKE2b-256 16a232525ab9e45e6a02c336ba9280808bf50541930f947b8fde136f07625e33

See more details on using hashes here.

Provenance

The following attestation bundles were made for fontforge_ref_sel_util-0.1.4-py3-none-any.whl:

Publisher: python-publish.yml on MihailJP/fontforge-ref-sel-util

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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