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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ofl_font_baker-0.1.1.tar.gz
  • Upload date:
  • Size: 31.1 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.1.tar.gz
Algorithm Hash digest
SHA256 eea2f7c5998039e5b5147e389fea4fa55b80e5f67e0b92417a4efaa02a27682b
MD5 d4319c2689e440b08fddd9b27126f445
BLAKE2b-256 33c6a3c1ecdf65bb008e3db632318278693f75ec8522bb4d81b343eb0a983cb1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ofl_font_baker-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c2f8d3e0a8854978cbe10e181c4db190e71df0fda810ae575959970308f2d14
MD5 146b2796d534ca274926555f0690052f
BLAKE2b-256 387ea4a1afae40796d2aeac7746e6b79e8f2fd3c1587137d0723904b7395d5a5

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