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:
Jonas Jenwald 2018-08-16 20:34:31 +02:00
parent b40fb3814a
commit caf90ff6ee

View File

@ -330,21 +330,21 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL || CHROME')) {
}); });
} }
var IsEvalSupportedCached = { const IsEvalSupportedCached = {
get value() { get value() {
return shadow(this, 'value', isEvalSupported()); return shadow(this, 'value', isEvalSupported());
}, },
}; };
var FontFaceObject = (function FontFaceObjectClosure() { class FontFaceObject {
function FontFaceObject(translatedData, { isEvalSupported = true, constructor(translatedData, { isEvalSupported = true,
disableFontFace = false, disableFontFace = false,
ignoreErrors = false, ignoreErrors = false,
onUnsupportedFeature = null, onUnsupportedFeature = null,
fontRegistry = null, }) { fontRegistry = null, }) {
this.compiledGlyphs = Object.create(null); this.compiledGlyphs = Object.create(null);
// importing translated data // importing translated data
for (var i in translatedData) { for (let i in translatedData) {
this[i] = translatedData[i]; this[i] = translatedData[i];
} }
this.isEvalSupported = isEvalSupported !== false; this.isEvalSupported = isEvalSupported !== false;
@ -353,42 +353,33 @@ var FontFaceObject = (function FontFaceObjectClosure() {
this._onUnsupportedFeature = onUnsupportedFeature; this._onUnsupportedFeature = onUnsupportedFeature;
this.fontRegistry = fontRegistry; 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) { if (!this.data || this.disableFontFace) {
return null; return null;
} }
const nativeFontFace = new FontFace(this.loadedName, this.data, {});
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
if (this.fontRegistry) { if (this.fontRegistry) {
this.fontRegistry.registerFont(this); this.fontRegistry.registerFont(this);
} }
return nativeFontFace; return nativeFontFace;
}, }
createFontFaceRule: function FontFaceObject_createFontFaceRule() { createFontFaceRule() {
if (!this.data || this.disableFontFace) { if (!this.data || this.disableFontFace) {
return null; return null;
} }
const data = bytesToString(new Uint8Array(this.data));
var data = bytesToString(new Uint8Array(this.data)); // Add the @font-face rule to the document.
var fontName = this.loadedName; const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
// 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 + '}';
if (this.fontRegistry) { if (this.fontRegistry) {
this.fontRegistry.registerFont(this, url); this.fontRegistry.registerFont(this, url);
} }
return rule; return rule;
}, }
getPathGenerator(objs, character) { getPathGenerator(objs, character) {
if (this.compiledGlyphs[character] !== undefined) { if (this.compiledGlyphs[character] !== undefined) {
@ -440,11 +431,8 @@ var FontFaceObject = (function FontFaceObjectClosure() {
c[current.cmd].apply(c, current.args); c[current.cmd].apply(c, current.args);
} }
}; };
}, }
}; }
return FontFaceObject;
})();
export { export {
FontFaceObject, FontFaceObject,