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.1.tar.gz (6.1 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.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fontforge_ref_sel_util-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 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.1.tar.gz
Algorithm Hash digest
SHA256 2d4da88fc21f4d4a27536412f974cf690033450d315d75ece4ebbe0b477db8db
MD5 89ecd7508f41d2d5b54f082f35d8a413
BLAKE2b-256 0035ae17dd355155163131fc7527b07505bfb375243395c246b5d88f2cffdfa3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fontforge_ref_sel_util-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9bfdefb106d3bd2d0bed984d24949e63899a0c605dbfb3956c6a1bd0673848df
MD5 1392a88a44cd6f65c0a2ead77086230a
BLAKE2b-256 84ce0191327f81323a3116c913f7afa3fd70f9d0bee0027a6d118cc36a8450f9

See more details on using hashes here.

Provenance

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