Convert the return value in createCmapTable and createNameTable to a TypedArray

Compared to the other TrueType table building functions, see previous patches, these ones are not trivial to convert to use TypedArrays properly.
However, in order to simplify the `OpenTypeFileBuilder` implementation a little bit we can at least have these functions return TypedArray data.
This commit is contained in:
Jonas Jenwald 2026-04-14 12:18:56 +02:00
parent e8ed6c6e24
commit 634ce3c163
2 changed files with 9 additions and 17 deletions

View File

@ -21,6 +21,7 @@ import {
info,
shadow,
string32,
stringToBytes,
warn,
} from "../shared/util.js";
import { CFFCompiler, CFFParser } from "./cff_parser.js";
@ -741,7 +742,7 @@ function createCmapTable(glyphs, toUnicodeExtraMap, numGlyphs) {
string32(format31012.length / 12); // nGroups
}
return (
return stringToBytes(
cmap +
"\x00\x04" + // format
string16(format314.length + 4) + // length
@ -995,8 +996,7 @@ function createNameTable(name, proto) {
}
}
nameTable += strings.join("") + stringsUnicode.join("");
return nameTable;
return stringToBytes(nameTable + strings.join("") + stringsUnicode.join(""));
}
/**

View File

@ -63,15 +63,7 @@ class OpenTypeFileBuilder {
// write the table data first (mostly for checksum)
for (let i = 0; i < numTables; i++) {
const table = tables.get(tablesNames[i]);
let tableOffset = tableOffsets[i];
if (table instanceof Uint8Array) {
file.set(table, tableOffset);
} else if (typeof table === "string") {
for (let j = 0, jj = table.length; j < jj; j++) {
file[tableOffset++] = table.charCodeAt(j) & 0xff;
}
}
file.set(table, tableOffsets[i]);
}
// sfnt version (4 bytes)