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

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

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
fontforge_refsel.selectGlyphsWithDistortedRefs(font)
font.unlinkReferences()
font.removeOverlap()  # may or may not needed

# Drop unused glyphs
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.0.tar.gz (5.9 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.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fontforge_ref_sel_util-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 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.0.tar.gz
Algorithm Hash digest
SHA256 0e906f04d852f3500a3e419a6cc3cdd2baebde2e8224f8fc83a3ec202480944e
MD5 9d6de7441182d9756b79c9a2b4b36c81
BLAKE2b-256 7b611a91e6bd2348e8bd91b26a5b08b7a8ea1698c108c5ffa0449d83fb0c1b46

See more details on using hashes here.

Provenance

The following attestation bundles were made for fontforge_ref_sel_util-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fontforge_ref_sel_util-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7479e795375bee9baeb5ab543c27b456f2831b573924cb420a4abf5f84e355ca
MD5 8ca96a2caf593f132ab6fbcee43dc5ab
BLAKE2b-256 890e434e15deea0ceb4c238f8a18d10f99508d6d4c4a3f2c2f149daf6dddaaad

See more details on using hashes here.

Provenance

The following attestation bundles were made for fontforge_ref_sel_util-0.1.0-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