Skip to content

Commit

Permalink
Remove unnecessary TypedArray re-initialization in `FontFaceObject.cr…
Browse files Browse the repository at this point in the history
…eateFontFaceRule`

The `this.data` property is, when defined, sent from the worker-thread as a `Uint8Array` and there's thus no reason to re-initialize the TypedArray here.
Note also the `FontFaceObject.createNativeFontFace` method just above, where we simply use `this.data` as-is.

The explanation for this code looking like it does is, as is often the case, for historical reasons. Originally we only supported `@font-face`, before the Font Loading API existed, and back then we also polyfilled TypedArrays (using regular Arrays) which should explain this particular line of code.
  • Loading branch information
Snuffleupagus committed May 1, 2021
1 parent 3624f9e commit 90b5fcb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class FontFaceObject {
if (!this.data || this.disableFontFace) {
return null;
}
const data = bytesToString(new Uint8Array(this.data));
const data = bytesToString(this.data);
// Add the @font-face rule to the document.
const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
let rule;
Expand Down

0 comments on commit 90b5fcb

Please sign in to comment.