Skip to content

Commit

Permalink
Use the Font Loading API in MOZCENTRAL builds, and GENERIC builds…
Browse files Browse the repository at this point in the history
… for Firefox version 63 and above (issue 9945)
  • Loading branch information
Snuffleupagus committed Aug 17, 2018
1 parent f29b442 commit 49e69ea
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,15 @@ class BaseFontLoader {
warn(`Failed to load font "${nativeFontFace.family}": ${reason}`);
});
};
// Firefox Font Loading API does not work with mozPrintCallback --
// disabling it in this case.
const isFontLoadingAPISupported = this.isFontLoadingAPISupported &&
!this.isSyncFontLoadingSupported;

for (const font of fonts) {
// Add the font to the DOM only once; skip if the font is already loaded.
if (font.attached || font.missingFile) {
continue;
}
font.attached = true;

if (isFontLoadingAPISupported) {
if (this.isFontLoadingAPISupported) {
const nativeFontFace = font.createNativeFontFace();
if (nativeFontFace) {
this.addNativeFontFace(nativeFontFace);
Expand All @@ -103,7 +100,7 @@ class BaseFontLoader {
}

const request = this._queueLoadingCallback(callback);
if (isFontLoadingAPISupported) {
if (this.isFontLoadingAPISupported) {
Promise.all(fontLoadPromises).then(request.complete);
} else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
this._prepareFontLoadEvent(rules, fontsToLoad, request);
Expand Down Expand Up @@ -177,6 +174,16 @@ FontLoader = class GenericFontLoader extends BaseFontLoader {

get isFontLoadingAPISupported() {
let supported = (typeof document !== 'undefined' && !!document.fonts);

if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) &&
(supported && typeof navigator !== 'undefined')) {
// The Firefox Font Loading API does not work with `mozPrintCallback`
// prior to version 63; see https://bugzilla.mozilla.org/show_bug.cgi?id=1473742
const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
if (m && m[1] < 63) {
supported = false;
}
}
return shadow(this, 'isFontLoadingAPISupported', supported);
}

Expand Down

0 comments on commit 49e69ea

Please sign in to comment.