Skip to main content

Font merge engine — combine two font files into one via cmap-based glyph replacement

Project description

Font Merge Engine

English | 日本語

The core font merge engine behind OFL Font Baker. The code in this directory is MIT-licensed and can be freely used in other projects.

Merges a base font (typically CJK) with a sub font (typically Latin or kana) into a single font file, replacing glyphs and OpenType features via cmap-based mapping.

For details on features and background, see the OFL Font Baker repository.

Installation

pip install ofl-font-baker

Requires Python 3.9+. fonttools and brotli are installed automatically.

Usage

Provide a JSON config on stdin. When outputDir is present, the engine produces a full export directory with font files and metadata.

cat config.json | python3 merge_fonts.py

Export Mode

Input:

{
  "base": {
    "path": "/path/to/base.otf",
    "scale": 1.0,
    "baselineOffset": 0,
    "axes": []
  },
  "latin": {
    "path": "/path/to/latin.ttf",
    "scale": 1.0,
    "baselineOffset": 0,
    "axes": []
  },
  "outputDir": "/exports",
  "outputFolderName": "MyFont-Regular",
  "overwrite": false,
  "outputFamilyName": "My Font",
  "outputWeight": 400,
  "outputItalic": false,
  "outputWidth": 5,
  "outputOptions": {
    "includeWoff2": true,
    "writeConfigJson": false,
    "bundleInputFonts": false
  }
}

Output (JSON manifest on stdout):

{
  "outputDir": "/exports/MyFont-Regular",
  "fontPath": "/exports/MyFont-Regular/MyFont-Regular.otf",
  "woff2Path": "/exports/MyFont-Regular/MyFont-Regular.woff2",
  "oflPath": "/exports/MyFont-Regular/OFL.txt",
  "settingsPath": "/exports/MyFont-Regular/Settings.txt",
  "configPath": null,
  "files": [...]
}

Progress is emitted as JSON lines on stderr.

outputOptions

Key Default Description
includeWoff2 true Generate a WOFF2 file alongside the main font.
writeConfigJson false Write an ExportConfig.json that records the merge settings.
bundleInputFonts false Copy the input fonts into a source/ subdirectory and rewrite paths in ExportConfig.json to relative paths (e.g. ./source/Base.otf). Automatically enables writeConfigJson. Makes the export directory self-contained and reproducible.
fontDir null Write the font file (OTF/TTF) directly into this directory instead of the default export subfolder. The directory is created if it doesn't exist.
woff2Dir null Write the WOFF2 file into this directory instead of alongside the font file. The directory is created if it doesn't exist.
writeOfl true Write OFL.txt into the export directory. Set to false if you manage the license file yourself.
writeSettings true Write Settings.txt into the export directory.

Top-level options

Key Default Description
metricsSource "base" Which font's vertical metrics (OS/2, hhea) to use. "base" keeps the base font metrics and expands only when the Latin font is larger. "latin" overwrites with the Latin font's metrics.

Tests

python3 -m pytest python/tests/test_merge.py -v

Test fonts are in testdata/fonts/ (repository root).

License

The source code in this directory is licensed under the MIT License. See LICENSE for details.

Other parts of the parent repository (OFL Font Baker) are licensed under AGPL-3.0-or-later and are not covered by this MIT notice.

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

ofl_font_baker-0.1.4.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ofl_font_baker-0.1.4-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

File details

Details for the file ofl_font_baker-0.1.4.tar.gz.

File metadata

  • Download URL: ofl_font_baker-0.1.4.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for ofl_font_baker-0.1.4.tar.gz
Algorithm Hash digest
SHA256 410fd7c2da0533a4e03c772ee95034d66451d40fcf0b09774884144778f7e1e6
MD5 3f268946d058441a6311d10e943848da
BLAKE2b-256 eeef234d88038f24b28b2c56d88b515884af3b471893e58a58c4b3b56696d341

See more details on using hashes here.

File details

Details for the file ofl_font_baker-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ofl_font_baker-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 36.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for ofl_font_baker-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 55b7fc3ac84bb64cf2bb89855589da9f97f45c1fa90e831eaf934cd603bc97d7
MD5 50bbbad1c5c4adcd9160c9e0d8603cbf
BLAKE2b-256 2b82d34cb4066b38655adaeec1e1a2e7b8e068900fa80bdfa7e14d646f0305fb

See more details on using hashes here.

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