Table
CFF2— Compact Font Format 2, the variable-aware outline container (OT §10.2).
Module tableCff2 | Source packages/front/office/fonts/src/table/cff2.js | Deps fontErrors, fontReader, tableCffDict | Worker-safe yes
Reads the CFF2 header, the single Top DICT, the Global Subr INDEX, the CharStrings INDEX, the Font DICT array with each Private DICT, and the bytes of the Item Variation Store. CFF2 differs from CFF: there is no Name, String, Encoding or Charset data (names live in name), the Top DICT is one block rather than an INDEX, and every INDEX carries a uint32 count.
Exports
| Symbol | Type | Description |
|---|---|---|
parseCff2 |
function | (bytes: Uint8Array) => { majorVersion, minorVersion, headerSize, topDictLength, topDict, globalSubrIndex, charStringsIndex, vstore, fdArray, vstoreOffset?, vstoreBytes? }. topDict is a Map<operator, operand[]>; charStringsIndex is null when the Top DICT has no single-offset CharStrings entry; fdArray is null without a single-offset FDArray (12 36) entry, else one { fontDict, private } per Font DICT — fontDict a Map, private { size, offset, bytes, dict } from its Private (18) entry (null when absent); vstore is null without a single-offset vstore (24) entry, else { offset, length, data } — the declared uint16 length and a zero-copy view of the Item Variation Store that follows it; vstoreOffset and vstoreBytes (from the offset to the end of the table) are present with it. |
parseCff2Index |
function | (r: BinaryReader) => { count, offSize, offsets, data, items, end }. Reads one INDEX with a uint32 count from the reader's current position. |
CFF2_TOP_DICT_OPS |
const | Frozen map of Top DICT operator code to name (OpenType CFF2): 17 CharStrings, 24 vstore, 0x0C07 FontMatrix, 0x0C24 FDArray, 0x0C25 FDSelect. |
tableCff2 |
factory | Factory { name, dependencies, factory }. |
Usage
import fw from '@awacloud/fw';
import { fw_require, modules } from '@awacloud/fonts';
for (const m of [...fw_require, ...modules]) fw.runtime.register(m);
const { parseSfnt } = fw.runtime.resolve('fontSfnt');
const { parseCff2 } = fw.runtime.resolve('tableCff2');
const sfnt = parseSfnt(bytes); // bytes: Uint8Array of an OpenType font with a CFF2 table
const cff2 = parseCff2(sfnt.tables.CFF2.bytes);
console.log(cff2.charStringsIndex?.count, cff2.vstoreOffset);
Notes
parseCff2Indexreturns{ count: 0, offSize: 0, offsets: [], data: <empty Uint8Array>, items: [], end }for an empty INDEX. Otherwiseitems[i]is a zero-copy view into the source bytes, andoffsetsholdscount + 1entries.- The Top, Font and Private DICTs are decoded through
tableCffDict(parseDict(bytes, { cff2: true }), which also reads the CFF2 operators22vsindex,23blendand24vstore) into aMapkeyed by the packed operator (0x0C00 | opfor two-byte operators). Ablendin a Private DICT is recorded with its raw operands; it is not evaluated against the variation store. - The CharStrings INDEX is read only when the
CharStringsoperand (17) holds exactly one offset. Charstring programs (includingblendandvsindex) are returned as raw bytes and are not interpreted. - The Item Variation Store is located and sized (
vstore.data) but not decoded into regions and deltas. FDSelect(12 37) is labelled but not decoded, and Local Subr INDEXes (Subrsin a Private DICT) are not read.parseCff2skips ahead toheaderSizebefore reading the Top DICT, so a header longer than 5 bytes is accepted.- Errors (all
ParseError):fonts/cff2-short(fewer than 5 bytes),fonts/cff2-version(major version is not 2),fonts/cff2-index-offsize(INDEXoffSizeoutside 1..4),fonts/cff2-index-first-offset(first INDEX offset is not 1),fonts/cff2-index-truncated(theuint32count needs more offset bytes than the reader holds, checked before anything is allocated),fonts/cff2-index-bad-offset(an INDEX offset below the previous one),fonts/cff2-vstore-range(the VariationStore or its declared length runs past the table),fonts/cff2-fdarray-range(the FDArray offset is outside the table),fonts/cff2-private-range(a Private DICT[size, offset]runs past the table).