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:
- fonttools
- scour SVG optimizer
- blackrenderer converts
COLRto SVG - svglib
- nanoemoji converts SVGs to
COLR
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
SVGtable 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.
COLRtable: None, Version 0, or 1- Select “None” not to include the table.
- Version 0 is not yet supported.
- Version 1 supports gradients while version 0 does not.
SVGtable: None, Uncompressed, or Compressed- Select “None” not to include the table.
- Some browsers support
SVGtable but other browsers supportCOLRtable. Including both can support as many environments as possible.
[!NOTE] Converting SVG glyphs into
COLRtable is so complicated that ‘nanoemoji’ tool must be used. Compiling a font includingCOLRmay 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 theCOLR-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,
COLRtable is preferred overSVG.
- If you load a color font from the ordinary ‘load’ menu,
[!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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fontforge_color_font-0.2.0.tar.gz.
File metadata
- Download URL: fontforge_color_font-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45731f46384214f0978a6b360935dfbe4e45a3ae5a6c0ab48596dba6aa698ab4
|
|
| MD5 |
b121c5badeb8718490211367ec4b2585
|
|
| BLAKE2b-256 |
8dc8572347c41d8a90b3db80c7f170ffb798a11829b8a33b3ea1d6d66e639235
|
Provenance
The following attestation bundles were made for fontforge_color_font-0.2.0.tar.gz:
Publisher:
python-publish.yml on MihailJP/fontforge-color-font
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fontforge_color_font-0.2.0.tar.gz -
Subject digest:
45731f46384214f0978a6b360935dfbe4e45a3ae5a6c0ab48596dba6aa698ab4 - Sigstore transparency entry: 1629682770
- Sigstore integration time:
-
Permalink:
MihailJP/fontforge-color-font@7d1bfb594c57a8bb9bffacf9c5323e22ff8b5627 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MihailJP
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7d1bfb594c57a8bb9bffacf9c5323e22ff8b5627 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fontforge_color_font-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fontforge_color_font-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
943db13d00f0bbd261d3d848b6f35216c65cbd79010b3cf72a99c0ab0b8609f7
|
|
| MD5 |
f38d5838503d4b03bd1a8a3e1dfed2cb
|
|
| BLAKE2b-256 |
553a156667ed1a5819a890a8dfbdc7c6c7a581d035666fca16a9da99c4a1e99d
|
Provenance
The following attestation bundles were made for fontforge_color_font-0.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on MihailJP/fontforge-color-font
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fontforge_color_font-0.2.0-py3-none-any.whl -
Subject digest:
943db13d00f0bbd261d3d848b6f35216c65cbd79010b3cf72a99c0ab0b8609f7 - Sigstore transparency entry: 1629682808
- Sigstore integration time:
-
Permalink:
MihailJP/fontforge-color-font@7d1bfb594c57a8bb9bffacf9c5323e22ff8b5627 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MihailJP
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7d1bfb594c57a8bb9bffacf9c5323e22ff8b5627 -
Trigger Event:
release
-
Statement type: