1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Use the Font Loading API in MOZCENTRAL builds, and GENERIC builds for Firefox version 63 and above (issue 9945)

This commit is contained in:
Jonas Jenwald 2018-08-16 20:34:56 +02:00
parent 05b021bcce
commit 435ec6a0d5

View file

@ -75,10 +75,7 @@ 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) {
@ -86,7 +83,7 @@ class BaseFontLoader {
}
font.attached = true;
if (isFontLoadingAPISupported) {
if (this.isFontLoadingAPISupported) {
const nativeFontFace = font.createNativeFontFace();
if (nativeFontFace) {
this.addNativeFontFace(nativeFontFace);
@ -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);
@ -176,6 +173,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);
}