Skip to main content

mapotofu

English | 中文 | 日本語

License Release PyPI Version
CI

mapotofu is a build program for CJK composite fonts: it merges a CJK font with a Latin font, and optionally CJK italic sources (a regular-script or slanted font drawn as such), into hinted variable and static fonts, from one TOML file per font project.

Table of Contents

Overview

A font project is a directory holding a mapotofu.toml. mapotofu reads it, downloads the source fonts the project lists, builds every font of every family, region and style in two steps, and packs the result into zip files for a release:

  1. Fonts: each font is assembled from the sources as an unhinted CFF2 variable font, with the metadata a web package will need.
  2. Desktop: the variable fonts are hinted with otfautohint, the static weights are instanced from them, and both are packaged as standalone OTF files and OTC collections.

The CJK part comes from the variable region fonts of Source Han Sans; the Latin part and, when the project gives any, the ideographs and kana of the italics come from the fonts the project names.

Features

  • Variable and static: CFF2 variable-weight fonts, and static CFF instances of the named weights.
  • Families: any of Gothic, UI and Mono.
    • Gothic: curly quotes, the middle dot, the ellipsis and the em dash are full width, in the forms of the region.
    • UI: curly quotes keep their proportional width, as in Latin text.
    • Mono: fixed pitch, Latin and punctuation in half-width cells (a Latin source's scale makes it fit).
  • Regions: any of SC, TC and J, each with its own glyph forms, language system and local names.
  • Extensions: ideographs outside each region's common list go into separate extension fonts, so the main fonts stay small.
  • Italics: Latin italics with the upright CJK glyphs, or, for the regions listed in [fonts.italic_cjk], with those of the CJK italic sources; the variable italics switch between their weights along the weight axis (rvrn), and each static italic takes the nearest one. A source whose em box differs (such as a narrow font) can be scaled (scale_x, scale_y) and centred in the full width (advance).
  • Hint cache: hints are kept per glyph in the project's hints/, so each glyph is hinted once and later builds take its hints from there.
  • Incremental: work is redone only where what it is made from changed (sources, configuration, code, library versions); an interrupted or failed run is resumed by running it again.
  • Collections: fonts of one pool share their glyph tables, which an OTC stores once.
  • Tools: mapo tool measures, compares, draws and converts fonts (stroke widths and glyph size, how a family changes with weight, the glyphs that change between two weights unlike their kind, whether two fonts have exactly the same glyphs, the same characters in several fonts side by side, every glyph of a font at several weights, the points of an outline, sample lines, TrueType outlines to OTF); the modules behind them can be imported as a Python library.

Prerequisites

  • Python ≥3.12
  • uv
  • Dependencies, installed with mapotofu: afdko ≥5.0.1 (otfautohint and tx), fontTools ≥4.68.0, cffsubr ≥0.4.0, uharfbuzz ≥0.57.0, brotli ≥1.2.1; for the tools, freetype-py ≥2.5.1, NumPy ≥2.5.4, Pillow ≥13.0.0, scikit-image ≥0.26.0, SciPy ≥1.18.1
  • Memory: subroutinizing a static font takes about 100 times its size. mapotofu records what each job took in build/memory.json and starts a job only when that much memory is free.

Installation

  1. In the font project (a uv project with a pyproject.toml), add mapotofu:

    uv add mapotofu
    
  2. Run it from the project:

    uv run mapo all
    

Note: a font project that wants the same fonts from the same tag should pin mapotofu to a version, e.g. uv add "mapotofu==<version>".

As a Tool

uvx --from mapotofu mapo all

Building from Source

git clone https://github.com/lutianyu2001/mapotofu.git
cd mapotofu
uv sync

A font project can then take it by path in its pyproject.toml:

[tool.uv.sources]
mapotofu = { path = "../mapotofu", editable = true }

Usage

Run in a font project, i.e. the directory holding mapotofu.toml or one below it. MAPOTOFU_ROOT names the project when run from elsewhere. -h, --version and --man work in any directory. mapo and mapotofu are the same command.

mapo [-h] [-j N] [--only [KEY ...]] [--man] [--version] STEP
Step Description
fetch Download the sources listed in sources.toml into sources/
fonts First step: the unhinted variable fonts in build/fonts/
desktop Second step: the hinted fonts in dist/ (OTF, OTC)
all Both steps
prune-hints Drop entries of the hint cache that no font uses any more (after a source changed)
collections Only the OTC collections, from the pooled fonts in build/pooled/
release Pack dist/ into dist/release/*.zip by family and region
  • -j, --jobs (default: 4)
    • Parallel processes; for desktop, the pools hinted at once, each over cores/N runs
  • --only
    • For fonts, desktop and all: only the pools of these fonts, such as Gothic-SC-Upright, or these pools, such as Italic-SC
  • --man
    • Show the manual (see Manual)
  • --version
    • Print the version

Recommended order for a new project:

  1. Download the sources:

    uv run mapo fetch
    
  2. Build everything:

    uv run mapo all
    
  3. Pack the release:

    uv run mapo release
    

If a run stops (out of memory, interrupted), run the same command again: finished work is kept.

Tools

mapo tool NAME runs one of the tools that come with mapotofu. They take font files and need no font project, so they run in any directory; mapo tool lists them and mapo tool NAME -h shows the arguments of one.

Tool Description
ttf2otf FONT OUT.otf A font with TrueType outlines made into an OTF with PostScript outlines (CFF), subroutinized; the other direction is AFDKO's otf2ttf
points FONT TEXT The points of glyphs' outlines as the font stores them: number, x, y, on the curve or off; --box X0 Y0 X1 Y1 for one part of a glyph
same FONT FONT Whether two fonts have exactly the same glyphs (outlines and advance widths), and which differ: the check that a change left the fonts alone. Exit status 0 if the same, 1 if not
sheet OUT.png TEXT FONT... The same characters in several fonts, a row each, to compare by eye; with --zoom CHAR X Y WIDTH, one spot of a glyph in each font instead
specimen FONT OUT.png Sample lines of a font at several weights, shaped as text is; --text LINE (repeatable) sets your own lines, for instance Han beside Latin and digits
stems FONT... Stroke widths (vertical, horizontal, their ratio) and glyph size of fonts, in units of 1000 per em: which weight of a source matches a master, and what scale fits one font to another
weights FONT FONT... How the measures of a family change with weight: the strokes, the width of the ink, the side bearings and the advance of each weight in percent of one of them
change LIGHT HEAVY The glyphs that change between two weights of a font unlike the others of their kind (ink, thick and thin strokes, width, height, advance), the furthest off first: where to look in a weight that was derived from another. --reference LIGHT HEAVY takes the spread a kind may have from another family
proof OUT FONT... Every glyph of a font, a cell a font, into OUT-01.png, OUT-02.png, ...: the weights of a variable font, to see that every glyph interpolates, or two builds

A FONT is a file, a face of a collection (Font.ttc#2) or a place on the axes of a variable font (Font[wght].ttf@wght=500).

Example:

mapo tool stems <FONT_A> "<FONT_B>@wght=400"
mapo tool sheet <OUT.png> "永国あA" <FONT_A> "<FONT_B>@wght=400"

The tools are modules of the package mapotofu.tools, and their functions can be imported, as can the two modules they are made of: mapotofu.tools.raster (fonts opened by such a spec, their glyphs rasterised) and mapotofu.tools.skeleton (the skeleton of a glyph as a graph, with the width of its strokes and strokes traced through junctions).

from mapotofu.tools.raster import FontSource
from mapotofu.tools.stems import font_stems

print(font_stems(FontSource("<FONT>")))

Manual

man mapo (or man mapotofu) is the whole manual, in English and in Chinese: the steps and options, and every key of mapotofu.toml and sources.toml, with a complete example. mapotofu installs it into its environment, so man finds it wherever that environment's bin is on PATH, as under uv run:

uv run man mapo

mapo --man shows the same page from anywhere: in the pager, in the language of the locale.

Font Project Layout

Path Contents
mapotofu.toml The fonts' configuration (see Configuration)
sources.toml Where the source fonts are downloaded from, with their SHA-256
data/common-<region>.txt The common ideographs of each region, one hexadecimal code point per line (# starts a comment); the others go into the extension fonts
hints/ The hint cache, and the list of glyphs left unhinted; source data, to be committed
OFL.txt The fonts' license; release packs nothing without it
sources/, build/, dist/ Downloaded sources, intermediate files and output; not committed

sources.toml lists zip archives, with the members to take, and single files:

[[archive]]
url = "<URL of a zip file>"
sha256 = "<SHA-256 of the file>"
members = { "<path inside the zip>" = "<name under sources/>" }

[[file]]
url = "<URL of a font file>"
sha256 = "<SHA-256 of the file>"

Configuration

mapotofu.toml has four tables. Which one a change is in decides how much is built again:

Table Holds Changing it
[fonts] Regions, families, the weight axis and its masters, the CJK, Latin and (optional) CJK italic sources Builds the fonts anew
[meta] Version, designer, copyright, license, vendor ID, named weights, family and style names Only finalizes the built fonts again
[hints] Where the hint cache keeps the hints of each source's glyphs Second step only
[package] The name of the collections and their zips Second step only

The manual explains every key and has a complete example (see Manual); tests/project/mapotofu.toml is a full configuration with comments.

Output Files

Path Contents
build/fonts/*.otf, *.json First step: unhinted variable fonts sharing a glyph pool, and their metadata
dist/variable/*.otf Hinted CFF2 variable fonts, upright and italic
dist/static/*.otf Static CFF fonts of the named weights
dist/otc/*.otc Collections, variable and static
dist/release/*.zip The release: a -VF.zip and a -static.zip for each family and region, and the collections; each carries OFL.txt

Note: fonts made from other fonts are Modified Versions of them. With sources under the SIL Open Font License, the result must be released under it too, and its names must not use the sources' Reserved Font Names (Source Han Sans reserves "Source").

Testing

uv run pytest

The tests run on tests/project, which builds nothing. Tests on built fonts belong to the font project.

Compatibility

Tested on:

  • Ubuntu 24.04.4 LTS, 32 cores, 32 GB of memory
    • Python 3.12.3, afdko 5.0.1, fontTools 4.68.0, cffsubr 0.4.0, uharfbuzz 0.57.0
    • Source Han Sans 2.005R
  • GitHub Actions ubuntu-latest, one pool per job

Disclaimer

This project is not affiliated with, endorsed by, or sponsored by Adobe Inc. Adobe and Source are either registered trademarks or trademarks of Adobe in the United States and/or other countries and are referenced here solely for descriptive purposes.

License

Copyright 2026 Tianyu (Sky) Lu

The entire repository is licensed under the Apache License, Version 2.0 (the "License"); you may not use any file in this repository except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Tianyu (Sky) Lu

Metadata

Release files for mapotofu 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mapotofu 0.1.1
File Size Uploaded Provenance Actions
mapotofu-0.1.1.tar.gz 146.5 kB Without provenance Details for mapotofu-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mapotofu 0.1.1
File Interpreter ABI Platform Actions
mapotofu-0.1.1-py3-none-any.whl Python 3 none any Details for mapotofu-0.1.1-py3-none-any.whl

Total release size: 311.3 kB

Release files / mapotofu-0.1.1.tar.gz

Download URL mapotofu-0.1.1.tar.gz
Size 146.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e85856a335cdd7da5c9fa172c4efd7406493a321ce77bf3fe5c4e6f76d47273a
BLAKE2b-256 checksum
How to use checksums
c433c9e80bd9a3ade754bf7e4080d704012907460567e2259e283fc7303a6c31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / mapotofu-0.1.1-py3-none-any.whl

Download URL mapotofu-0.1.1-py3-none-any.whl
Size 164.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eeac5a5a5ff3345ea7c2041f5a119fa3bc83ccc7979c9d109862b641919ce8ea
BLAKE2b-256 checksum
How to use checksums
81d58cc1cbdb86ea90b68ec40aa27ed785043f6d0567e8e555ef6db1fa26b03c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Security for mapotofu 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page