Convert FontFaceObject
to an ES6 class
Also changes `var` to `let`/`const` in code already touched in the patch, and makes use of template strings in a few spots.
This commit is contained in:
parent
b40fb3814a
commit
caf90ff6ee
@ -330,21 +330,21 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL || CHROME')) {
|
||||
});
|
||||
}
|
||||
|
||||
var IsEvalSupportedCached = {
|
||||
const IsEvalSupportedCached = {
|
||||
get value() {
|
||||
return shadow(this, 'value', isEvalSupported());
|
||||
},
|
||||
};
|
||||
|
||||
var FontFaceObject = (function FontFaceObjectClosure() {
|
||||
function FontFaceObject(translatedData, { isEvalSupported = true,
|
||||
class FontFaceObject {
|
||||
constructor(translatedData, { isEvalSupported = true,
|
||||
disableFontFace = false,
|
||||
ignoreErrors = false,
|
||||
onUnsupportedFeature = null,
|
||||
fontRegistry = null, }) {
|
||||
this.compiledGlyphs = Object.create(null);
|
||||
// importing translated data
|
||||
for (var i in translatedData) {
|
||||
for (let i in translatedData) {
|
||||
this[i] = translatedData[i];
|
||||
}
|
||||
this.isEvalSupported = isEvalSupported !== false;
|
||||
@ -353,42 +353,33 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
||||
this._onUnsupportedFeature = onUnsupportedFeature;
|
||||
this.fontRegistry = fontRegistry;
|
||||
}
|
||||
FontFaceObject.prototype = {
|
||||
createNativeFontFace: function FontFaceObject_createNativeFontFace() {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) {
|
||||
throw new Error('Not implemented: createNativeFontFace');
|
||||
}
|
||||
|
||||
createNativeFontFace() {
|
||||
if (!this.data || this.disableFontFace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
||||
const nativeFontFace = new FontFace(this.loadedName, this.data, {});
|
||||
|
||||
if (this.fontRegistry) {
|
||||
this.fontRegistry.registerFont(this);
|
||||
}
|
||||
return nativeFontFace;
|
||||
},
|
||||
}
|
||||
|
||||
createFontFaceRule: function FontFaceObject_createFontFaceRule() {
|
||||
createFontFaceRule() {
|
||||
if (!this.data || this.disableFontFace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var data = bytesToString(new Uint8Array(this.data));
|
||||
var fontName = this.loadedName;
|
||||
|
||||
// Add the font-face rule to the document
|
||||
var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
|
||||
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
|
||||
const data = bytesToString(new Uint8Array(this.data));
|
||||
// Add the @font-face rule to the document.
|
||||
const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
|
||||
const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
|
||||
|
||||
if (this.fontRegistry) {
|
||||
this.fontRegistry.registerFont(this, url);
|
||||
}
|
||||
|
||||
return rule;
|
||||
},
|
||||
}
|
||||
|
||||
getPathGenerator(objs, character) {
|
||||
if (this.compiledGlyphs[character] !== undefined) {
|
||||
@ -440,11 +431,8 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
||||
c[current.cmd].apply(c, current.args);
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
return FontFaceObject;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
FontFaceObject,
|
||||
|
Loading…
x
Reference in New Issue
Block a user