public final class CmapWriter extends Object
cmap table of an sfnt (TrueType) font so that it contains the character to
glyph-index mappings held by FOP for that font, including the Private Use Area code points that
MultiByteFont.createPrivateUseMapping allocates for complex-script (GSUB) output.
The AFP renderer writes text as UTF-16 code points and the AFP consumer resolves each code
point to a glyph through the embedded font's cmap. Substituted glyphs are exposed by FOP
as PUA code points which are, by construction, absent from the original font's cmap;
without this rewrite they would not resolve.
The rewrite is deliberately minimal: the original font bytes are preserved, a fresh
cmap table (a single Windows BMP, format 4 subtable) is appended on a 4-byte
boundary, and only the cmap entry in the sfnt table directory is repointed to it. The
original cmap bytes remain in the file as unreferenced dead space. The font's glyph
numbering is left untouched, so the glyph indices line up
with the embedded glyphs.
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
appendCmap(byte[] font,
CMapSegment[] segments)
Returns a copy of the given TrueType font whose
cmap table maps the supplied segments. |
public static byte[] appendCmap(byte[] font,
CMapSegment[] segments)
throws IOException
cmap table maps the supplied segments.font - the original TrueType font bytes (must keep its original glyph numbering)segments - the character-to-glyph mappings to encode (original mappings plus PUA additions)IOException - if the font has no cmap or head tableCopyright © 2026 Apache Software Foundation. All rights reserved.