Merge pull request #21214 from Snuffleupagus/CFFFont-improvements

Remove the `CompilerOutput.prototype.finalData` getter, and a few other font improvements (PR 21053 follow-up)
This commit is contained in:
Tim van der Meij 2026-05-03 16:07:22 +02:00 committed by GitHub
commit c196fa8196
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 11 deletions

View File

@ -28,11 +28,12 @@ class CFFFont {
this.seacs = this.cff.seacs; this.seacs = this.cff.seacs;
try { try {
this.data = compiler.compile(); this.data = compiler.compile();
} catch { } catch (ex) {
warn("Failed to compile font " + properties.loadedName); warn(`Failed to compile font "${properties.loadedName}": "${ex}".`);
// There may have just been an issue with the compiler, set the data // There may have just been an issue with the compiler, set the data
// anyway and hope the font loaded. // anyway and hope the font loaded.
this.data = file; file.reset();
this.data = file.getBytes();
} }
this._createBuiltInEncoding(); this._createBuiltInEncoding();
} }

View File

@ -1400,12 +1400,6 @@ class CompilerOutput {
return this.#buf.subarray(0, this.#pos); return this.#buf.subarray(0, this.#pos);
} }
get finalData() {
const data = this.#buf.slice(0, this.#pos);
this.#buf = null;
return data;
}
get length() { get length() {
return this.#pos; return this.#pos;
} }
@ -1534,7 +1528,7 @@ class CFFCompiler {
// the sanitizer will bail out. Add a dummy byte to avoid that. // the sanitizer will bail out. Add a dummy byte to avoid that.
output.add([0]); output.add([0]);
return output.finalData; return output.data;
} }
encodeNumber(value) { encodeNumber(value) {

View File

@ -1519,6 +1519,12 @@ class Font {
data[8] = data[9] = data[10] = data[11] = 0; data[8] = data[9] = data[10] = data[11] = 0;
data[17] |= 0x20; // Set font optimized for cleartype flag. data[17] |= 0x20; // Set font optimized for cleartype flag.
} }
// The "CFF " table may be replaced completely, hence its data shouldn't
// need to be read and/or modified piecewise through a `DataView`.
const view =
tag === "CFF "
? null
: new DataView(data.buffer, data.byteOffset, data.byteLength);
return { return {
tag, tag,
@ -1526,7 +1532,7 @@ class Font {
length, length,
offset, offset,
data, data,
view: new DataView(data.buffer, data.byteOffset, data.byteLength), view,
}; };
} }