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.3.tar.gz (32.3 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.3-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ofl_font_baker-0.1.3.tar.gz
  • Upload date:
  • Size: 32.3 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.3.tar.gz
Algorithm Hash digest
SHA256 2eff1e2760b909fa4a20971c27be05dd0c029c21f06391d1b2773539129937a1
MD5 793d2a167191574b66a465a278ef4655
BLAKE2b-256 63d71fe8ef5916ece2e4512f403763a7b973e90fb5234f53201fe28e5f18cbdf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ofl_font_baker-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 35.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9d27204fd28a01121e5df93993411bf20a36682372b1eab88e095b42475593fe
MD5 60395aa7f2a3454c813b95a0e33de1f6
BLAKE2b-256 277b6b4feaf5d18558437236524923958e36a86adb5eaac04bcafc5914404736

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