Metadata-Version: 2.4
Name: ofl-font-baker
Version: 0.1.4
Summary: Font merge engine — combine two font files into one via cmap-based glyph replacement
Project-URL: Homepage, https://github.com/yamatoiizuka/ofl-font-baker
Project-URL: Repository, https://github.com/yamatoiizuka/ofl-font-baker
Project-URL: Issues, https://github.com/yamatoiizuka/ofl-font-baker/issues
Author-email: Yamato Iizuka <me@yamatoiizuka.com>
License-Expression: MIT
License-File: LICENSE
Keywords: cff,cjk,font,merge,opentype,truetype
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Fonts
Requires-Python: >=3.9
Requires-Dist: brotli>=1.1.0
Requires-Dist: fonttools>=4.47.0
Description-Content-Type: text/markdown

# Font Merge Engine

<p>English | <strong><a href="https://github.com/yamatoiizuka/ofl-font-baker/blob/main/python/README.ja.md">日本語</a></strong></p>

The core font merge engine behind [OFL Font Baker](https://github.com/yamatoiizuka/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](https://github.com/yamatoiizuka/ofl-font-baker).

## Installation

```bash
pip install ofl-font-baker
```

Requires Python 3.9+. [fonttools](https://github.com/fonttools/fonttools) and [brotli](https://github.com/google/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.

```bash
cat config.json | python3 merge_fonts.py
```

### Export Mode

Input:

```json
{
  "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):

```json
{
  "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

```bash
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](LICENSE) for details.

Other parts of the parent repository ([OFL Font Baker](https://github.com/yamatoiizuka/ofl-font-baker)) are licensed under AGPL-3.0-or-later and are not covered by this MIT notice.
