Skip to content

Commit c196fa8

Browse files
Merge pull request #21214 from Snuffleupagus/CFFFont-improvements
Remove the `CompilerOutput.prototype.finalData` getter, and a few other font improvements (PR 21053 follow-up)
2 parents 6d5e869 + e5e82b9 commit c196fa8

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/core/cff_font.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ class CFFFont {
2828
this.seacs = this.cff.seacs;
2929
try {
3030
this.data = compiler.compile();
31-
} catch {
32-
warn("Failed to compile font " + properties.loadedName);
31+
} catch (ex) {
32+
warn(`Failed to compile font "${properties.loadedName}": "${ex}".`);
3333
// There may have just been an issue with the compiler, set the data
3434
// anyway and hope the font loaded.
35-
this.data = file;
35+
file.reset();
36+
this.data = file.getBytes();
3637
}
3738
this._createBuiltInEncoding();
3839
}

src/core/cff_parser.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,12 +1400,6 @@ class CompilerOutput {
14001400
return this.#buf.subarray(0, this.#pos);
14011401
}
14021402

1403-
get finalData() {
1404-
const data = this.#buf.slice(0, this.#pos);
1405-
this.#buf = null;
1406-
return data;
1407-
}
1408-
14091403
get length() {
14101404
return this.#pos;
14111405
}
@@ -1534,7 +1528,7 @@ class CFFCompiler {
15341528
// the sanitizer will bail out. Add a dummy byte to avoid that.
15351529
output.add([0]);
15361530

1537-
return output.finalData;
1531+
return output.data;
15381532
}
15391533

15401534
encodeNumber(value) {

src/core/fonts.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,14 +1519,20 @@ class Font {
15191519
data[8] = data[9] = data[10] = data[11] = 0;
15201520
data[17] |= 0x20; // Set font optimized for cleartype flag.
15211521
}
1522+
// The "CFF " table may be replaced completely, hence its data shouldn't
1523+
// need to be read and/or modified piecewise through a `DataView`.
1524+
const view =
1525+
tag === "CFF "
1526+
? null
1527+
: new DataView(data.buffer, data.byteOffset, data.byteLength);
15221528

15231529
return {
15241530
tag,
15251531
checksum,
15261532
length,
15271533
offset,
15281534
data,
1529-
view: new DataView(data.buffer, data.byteOffset, data.byteLength),
1535+
view,
15301536
};
15311537
}
15321538

0 commit comments

Comments
 (0)