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.post1.tar.gz (6.0 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.post1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for fontforge_ref_sel_util-0.1.0.post1.tar.gz
Algorithm Hash digest
SHA256 991d36940f9a5448c3a3f81e21d37d25cb325d822862b42a3e6e00182b5a2407
MD5 5cf9dd146b5308a4b31093852f7ed951
BLAKE2b-256 a9729e1d2da31b30d28edc055e2f4dd9f62fe115d091249012736d76e840d09f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fontforge_ref_sel_util-0.1.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 465186c4a53b976a5c8c3ae5c4b3856252bf3804104965f2788a528363f84874
MD5 322efe058863828991ad5dc7c9a437fa
BLAKE2b-256 22a9447b776e3ddf704d9a24768b0fd3a6be39ea6eed74b99acdc525d56954e5

See more details on using hashes here.

Provenance

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