I wanted to know what a font generator is actually emitting when it shows a "bold" preview. Not a typeface file β I already suspected that β but the exact code points sitting on the clipboard.
This article was created with the help of AI. I also operate FontLemon, the site I link to later. The snippets below were run in Node 24 and Python 3.13 before I pasted them here.
I typed Font into a font generator and copied the first heavy row. What I got back was not the letters F, o, n, and t with a weight axis flipped. It was four different characters: π
π¨π§π. In a console, that first letter is U+1D400, whose Unicode name is MATHEMATICAL BOLD CAPITAL F. It lives in the Mathematical Alphanumeric Symbols block, not in a font I installed.
The style is a different code point
The mapping a font generator uses for this one style is almost disappointingly small. Latin A through Z start at U+1D400. Latin a through z start at U+1D41A. Everything else β at least in this particular bold map β stays as typed.
Here it is in JavaScript:
function toMathBold(text) {
const BOLD_CAP_A = 0x1D400;
const BOLD_SMALL_A = 0x1D41A;
return Array.from(text, (ch) => {
const o = ch.codePointAt(0);
if (o >= 0x41 && o <= 0x5A) {
return String.fromCodePoint(BOLD_CAP_A + (o - 0x41));
}
if (o >= 0x61 && o <= 0x7A) {
return String.fromCodePoint(BOLD_SMALL_A + (o - 0x61));
}
return ch;
}).join("");
}
console.log(toMathBold("Font"));
// π
π¨π§π
And the same loop in Python:
MATH_BOLD_CAPITAL_A = 0x1D400
MATH_BOLD_SMALL_A = 0x1D41A
def to_math_bold(text: str) -> str:
out = []
for ch in text:
o = ord(ch)
if 0x41 <= o <= 0x5A:
out.append(chr(MATH_BOLD_CAPITAL_A + (o - 0x41)))
elif 0x61 <= o <= 0x7A:
out.append(chr(MATH_BOLD_SMALL_A + (o - 0x61)))
else:
out.append(ch)
return "".join(out)
print(to_math_bold("Font"))
# π
π¨π§π
That is the whole trick for this one style of font generator. You are not embedding a font. You are substituting code points. A device will only draw π
if it has a glyph for U+1D400. If it does not, you may get a fallback typeface or a missing-glyph box. The character on the clipboard is still U+1D400 either way. A font generator that previews π
is previewing that code point.
Why "CafΓ© ζ±δΊ¬" only half-changes
I ran the same function on a string a font generator's own docs use: CafΓ© ζ±δΊ¬.
console.log(toMathBold("CafΓ© ζ±δΊ¬"));
// πππΓ© ζ±δΊ¬
C, a, and f move into the math-bold range. The precomposed Γ© (U+00E9) and the two CJK ideographs do not. There is no "mathematical bold Γ©" or "mathematical bold ζ±" sitting next to those Latin letters, so the loop has nothing to map them to. A font generator should leave them alone. That is the correct behavior, not a bug.
This is easy to miss if you only test English. A mapper that assumes every visible letter has a styled twin will either throw, invent a lookalike, or silently drop a character. The honest fallback is the original code point.
One more wrinkle, because NFC and NFD are not the same string. Precomposed Γ© is one code point. An e plus a combining acute accent (U+0065 + U+0301) is two. My loop leaves both forms alone, which is what I want for this map. If you ever did style the base letter and forget the combiner, you would split a grapheme and the accent could land on the wrong character. I am not doing that here.
Three ways to count one string
Once the letters change, length gets slippery. I used three counters, the same three a careful font generator will show next to a preview:
- a grapheme: what a reader usually treats as one character
- a code point: one Unicode scalar value
- a UTF-16 unit: what JavaScript's
String#lengthactually counts
function counts(s) {
const graphemes = [
...new Intl.Segmenter("en", { granularity: "grapheme" }).segment(s),
].length;
const codePoints = [...s].length;
const utf16 = s.length;
return { graphemes, codePoints, utf16 };
}
console.table({
A: counts("A"),
mathBoldA: counts("π"),
ePlusAcute: counts("e\u0301"),
precomposedE: counts("Γ©"),
cafe: counts("CafΓ© ζ±δΊ¬"),
cafeBold: counts(toMathBold("CafΓ© ζ±δΊ¬")),
});
In Node 24 that table printed:
| String | Graphemes | Code points | UTF-16 units |
|---|---|---|---|
A |
1 | 1 | 1 |
π |
1 | 1 | 2 |
e + acute |
1 | 2 | 2 |
Γ© (NFC) |
1 | 1 | 1 |
CafΓ© ζ±δΊ¬ |
7 | 7 | 7 |
πππΓ© ζ±δΊ¬ |
7 | 7 | 10 |
π is a single code point outside the Basic Multilingual Plane, so UTF-16 stores it as a surrogate pair. JavaScript's s.length reports 2. Spreading the string with [...s] walks code points and reports 1. Intl.Segmenter agrees it is one grapheme.
Python's len(s) already counts code points. UTF-16 units are len(s.encode("utf-16-le")) // 2. The standard library has no grapheme segmenter, so for the combining-mark case I counted a base character plus any following combining marks as one cluster. That matches Intl.Segmenter on these samples. It is not a full UAX #29 implementation, and I would not use it for emoji made of zero-width joiners.
import unicodedata
def utf16_units(s: str) -> int:
return len(s.encode("utf-16-le")) // 2
def grapheme_count(s: str) -> int:
n = 0
for i, ch in enumerate(s):
if i > 0 and unicodedata.combining(ch):
continue
n += 1
return n
s = "e\u0301"
print(grapheme_count(s), len(s), utf16_units(s))
# 1 2 2
The practical point is not which counter is "right." An input field may use any of the three. I have seen a short heading look fine and still fail a length check because three math-bold letters cost six UTF-16 units. If you are building a font generator, show all three, and believe the field's own counter when you save.
What a screen reader may hear
Styled letters are still text, but they are not the letters a screen reader expects in a sentence. Some voices announce a long Unicode name. Others spell the line one character at a time. Either way, π
π¨π§π is a poor way to hear a word.
That is why these styles should stay decorative. I would not paste font generator output into a price, an address, a password, a button label, or anything a person needs to understand quickly. I also would not ship it in alt text or a documentation heading. A short display name or a single caption line is the job they are good at. If the line matters, keep a plain-text spelling next to it.
When I'd use a font generator instead of my own map
The loop above covers one style, and only the plain Latin letters in that style. A general-purpose font generator also has to deal with script and italic math variants, circled letters, small caps, upside-down maps, frames around a short line, and styles that add combining marks rather than replacing the base character. Those last ones can attach to Γ© and to CJK, which is a different code path from mathematical bold.
If I need the mapping inside a test, a build step, or a product, I will keep a function I can read and test, like the ones above. If I just want to type a short phrase and copy a style, I will not reimplement 119 rows and their length counters. I would rather open a font generator, compare the same phrase across Unicode styles, and copy one line.
The tool I operate does that in the browser, with no account, no download, and no upload of the words you type. Each input holds up to 300 UTF-16 units, which is why a font generator should treat the UTF-16 count as more than an academic detail. It also prints grapheme, code-point, and UTF-16 counts beside each row. If you want the definitions behind those three numbers, including the π and eΜ examples, they are on the Unicode length and field-compatibility notes.
A font generator of this kind is a character map with a copy button. That is also its limit. It will not export a .ttf or .otf file, and it will not change the fonts installed on a device. If you need an installable typeface, you still need a font editor. If you need a decorative line you can paste, the substitution is enough β as long as you remember which letters have no styled form, which counter the destination field uses, and who will have to hear the result.
Top comments (0)