Skip to content

Commit

Permalink
Merge pull request #15511 from Snuffleupagus/FontLoader-cleanup-2
Browse files Browse the repository at this point in the history
More `FontLoader` clean-up
  • Loading branch information
timvandermeij authored Oct 1, 2022
2 parents 29a784c + 9ce2427 commit 0cca2d4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ class FontLoader {
if (this.isSyncFontLoadingSupported) {
return; // The font was, synchronously, loaded.
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: async font loading");
}
await new Promise(resolve => {
const request = this._queueLoadingCallback(resolve);
this._prepareFontLoadEvent([rule], [font], request);
this._prepareFontLoadEvent(font, request);
});
// The font was, asynchronously, loaded.
}
Expand Down Expand Up @@ -218,7 +221,7 @@ class FontLoader {
return shadow(this, "_loadTestFont", testFont);
}

_prepareFontLoadEvent(rules, fonts, request) {
_prepareFontLoadEvent(font, request) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: _prepareFontLoadEvent");
}
Expand Down Expand Up @@ -252,9 +255,8 @@ class FontLoader {

let called = 0;
function isFontReady(name, callback) {
called++;
// With setTimeout clamping this gives the font ~100ms to load.
if (called > 30) {
if (++called > 30) {
warn("Load test font never loaded.");
callback();
return;
Expand Down Expand Up @@ -300,19 +302,13 @@ class FontLoader {
const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
this.insertRule(rule);

const names = [];
for (const font of fonts) {
names.push(font.loadedName);
}
names.push(loadTestFontId);

const div = this._document.createElement("div");
div.style.visibility = "hidden";
div.style.width = div.style.height = "10px";
div.style.position = "absolute";
div.style.top = div.style.left = "0px";

for (const name of names) {
for (const name of [font.loadedName, loadTestFontId]) {
const span = this._document.createElement("span");
span.textContent = "Hi";
span.style.fontFamily = name;
Expand Down

0 comments on commit 0cca2d4

Please sign in to comment.