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.2.tar.gz (31.2 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.2-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ofl_font_baker-0.1.2.tar.gz
  • Upload date:
  • Size: 31.2 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.2.tar.gz
Algorithm Hash digest
SHA256 073bb57eea2b094797d1aea62e00f33801ace14452a09d627ebc13c7fbfc99ce
MD5 75ed245c50e0b70372e6c54b897fe5c4
BLAKE2b-256 eeb5f4d65e8241baf0b59cfcab9c9abac27e39f9bcfee2d21ef81b73f3f7d3d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ofl_font_baker-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 26887fd56c2ba1312f94ea93f4b74c1c3db2b716ed137c5386ff9c7b68c5f760
MD5 d012ba02b45844c88a51781f6ddb8aa5
BLAKE2b-256 6c901a7803805fce37bc8c580eed63bca2a93717c81c681e7caec9001187f807

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