Skip to main content

FontForge_plugin for color fonts

Project description

Fontforge color font plugin

FontForge_plugin for color fonts

OpenType color font is the technology used for emoji chiefly, and less frequently some fun fonts. There are several protocols and their support varies browser to browser.

Fontforge supports none but with other open-source tools color fonts can be created. This plugin provides frontend to such tools.

This plugin uses these programs as backend:

This module requires Python 3.10 or later.

Install

pip3 install fontforge_color_font

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

Interactive usage

As a Fontforge plugin, fontforge_color_font adds 'Color Font' submenu to 'Tools' menu which is dedicated for plugins.

  • Color Font
    • Open color font...
    • Export color font...
    • Import SVG as color font glyph...
    • Export SVG color font glyph...
    • Delete SVG color font glyph

[!IMPORTANT] Since the plugin feature has been hardly (maybe never) used (hence it can be tested not well,) Fontforge may crash especially after a dialog is shown. You are advised to back up your font project before use.

Open color font

Shows a dialog to open a color font. COLR (both COLRv0 and COLRv1) and SVG tables are supported.

If the font has both COLR and SVG tables, which one to read will be asked.

[!NOTE] Reading SVG table may take some minutes in order to split multi-glyph SVG documents.

Export color font

Shows a dialog where you can set output file name and other options.

  • COLR table: None, Version 0, or 1
    • Select “None” not to include the table.
    • Version 1 supports gradients while version 0 does not.
  • SVG table: None, Uncompressed, or Compressed
    • Select “None” not to include the table.
  • Some browsers support SVG table but other browsers support COLR table. Including both can support as many environments as possible.

[!NOTE] Converting SVG glyphs into COLR table is so complicated that ‘nanoemoji’ tool must be used. Compiling a font including COLR may take some minutes. Also, that tool can generate a TTF anew, but does not support appending into an existing TTF. So it is needed to merge the main TTF and the COLR-only one using fonttools.

Import SVG as color font glyph

Reads an SVG document and stores into glyph metadata.

This menu is available both in font view and in (spline) glyph view. In glyph view, select an SVG document. Nominal width should match with glyph advance width, nominal height with hhea ascender plus absolute value of hhea descender. In font view and if single glyph is selected, does the same thing as in glyph view. If multiple glyphs are selected, select a directory. SVG documents must be named same as glyph name except:

  • uppercase letters other than code points (uniXXXX, uXXXXX, or u10XXXX): to work with case-insensitive file systems, an underscore must precede
  • underscore itself: another underscore must precede for disambiguation
  • same name as DOS/Windows reserved file names

For color glyph definitions, some SVG capability is prohibited. See Microsoft Typography site for details.

SVG data is stored in glyph.persistent['SVG']. If there is already non-dict glyph.persistent, it is deleted without warning.

[!IMPORTANT] Due to Fontforge limitation, there is no way to show color glyphs in font view. In glyph view, background object can have color bitmap pictures, but through scripts cannot place at specified coordinates. Another problem in this case is that SVG must be rasterized into PNG with some tool (like ImageMagick.)

Export SVG color font glyph

Exports SVG stored in glyph.persistent['SVG'].

This menu is available both in font view and in (spline) glyph view. Behaves similarly to “Import SVG as color font glyph” menu.

Delete SVG color font glyph

Deletes color glyph SVG.

This menu is available both in font view and in (spline) glyph view. Behaves similarly to “Import SVG as color font glyph” menu.

[!WARNING] You will see no warning before deletion.

Hooks

This plugin installs new/open font hooks which does:

  • sets font generation hooks to output color glyphs if exist
    • Not yet implemented
  • loads color glyph data if available
    • If you load a color font from the ordinary ‘load’ menu, COLR table is preferred over SVG .

[!NOTE] These hooks work in interactive mode only.

Script usage

As a Python module, in addition to fontforge module, scripting to export variable fonts from SFD projects will be possible.

import fontforge
import fontforge_color_font

# Open color font
font = fontforge_color_font.loadColorFont('MyColorFont.sfd')
font = fontforge_color_font.loadColorFont('MyColorFont.sfd', colrPreferred=False)

# Import SVG
fontforge_color_font.loadSvg(glyph, 'glyph.svg')

# Export SVG
fontforge_color_font.exportSvg(glyph, 'glyph.svg')
fontforge_color_font.exportSvg(glyph, 'glyph.svg', lambda x: x.replace('glyph', '_glyph'))

try:
    fontforge_color_font.exportSvg(glyph, 'glyph.svg')
except NoColorGlyphError:
    pass

# Delete SVG
fontforge_color_font.deleteSvg(glyph)

# Check if color glyph table exists
result = fontforge_color_font.hasColrTable(font)
result = fontforge_color_font.hasSvgTable(font)

# Check if color glyph SVG is stored
result = fontforge_color_font.svgIsRegistered(glyph)

# Export color font
fontforge_color_font.exportColorFont(font, 'MyColorFont.ttf', colr=1, svg=0)
fontforge_color_font.exportColorFont(font, 'MyColorFont.ttf', colr=1, svg=0, flags=('no-mac-names', 'opentype'))

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_color_font-0.3.0.tar.gz (15.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_color_font-0.3.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file fontforge_color_font-0.3.0.tar.gz.

File metadata

  • Download URL: fontforge_color_font-0.3.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fontforge_color_font-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e21f0350108ce496ae14919aafb1602a1853fa0520aabad86046910dfaf987ee
MD5 1d5ddd81cdb9569e39afdc878ea62153
BLAKE2b-256 bacc168095669ba16811a1f4ec306fd12460c27da098695eaa4d141b71e3934d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fontforge_color_font-0.3.0.tar.gz:

Publisher: python-publish.yml on MihailJP/fontforge-color-font

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_color_font-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fontforge_color_font-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c80ea0d3e3e6086857cebb9a4f18111de00a94fdd30ed3ff9f263b855dc3719
MD5 fa628858dd92c0146b75c71ef5dbf864
BLAKE2b-256 351081cac5cfc65523f85c49ea95c565d7601e8a5cdff2cd3ac9b13199b2b3d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fontforge_color_font-0.3.0-py3-none-any.whl:

Publisher: python-publish.yml on MihailJP/fontforge-color-font

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