Replaces all preprocessor directives with PDFJSDev calls.

This commit is contained in:
Yury Delendik 2016-10-14 10:57:53 -05:00
parent bf52ff156d
commit 0576c9c6c6
32 changed files with 1145 additions and 904 deletions

View file

@ -36,14 +36,14 @@ var warn = sharedUtil.warn;
function FontLoader(docId) {
this.docId = docId;
this.styleElement = null;
//#if !(MOZCENTRAL)
this.nativeFontFaces = [];
this.loadTestFontId = 0;
this.loadingContext = {
requests: [],
nextRequestId: 0
};
//#endif
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
this.nativeFontFaces = [];
this.loadTestFontId = 0;
this.loadingContext = {
requests: [],
nextRequestId: 0
};
}
}
FontLoader.prototype = {
insertRule: function fontLoaderInsertRule(rule) {
@ -65,18 +65,20 @@ FontLoader.prototype = {
styleElement.parentNode.removeChild(styleElement);
styleElement = this.styleElement = null;
}
//#if !(MOZCENTRAL)
this.nativeFontFaces.forEach(function(nativeFontFace) {
document.fonts.delete(nativeFontFace);
});
this.nativeFontFaces.length = 0;
//#endif
},
//#if !(MOZCENTRAL)
get loadTestFont() {
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
this.nativeFontFaces.forEach(function(nativeFontFace) {
document.fonts.delete(nativeFontFace);
});
this.nativeFontFaces.length = 0;
}
}
};
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
var getLoadTestFont = function () {
// This is a CFF font with 1 glyph for '.' that fills its entire width and
// height.
return shadow(this, 'loadTestFont', atob(
return atob(
'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
@ -98,16 +100,22 @@ FontLoader.prototype = {
'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
'ABAAAAAAAAAAAD6AAAAAAAAA=='
));
},
'ABAAAAAAAAAAAD6AAAAAAAAA==');
};
Object.defineProperty(FontLoader.prototype, 'loadTestFont', {
get: function () {
return shadow(this, 'loadTestFont', getLoadTestFont());
},
configurable: true
});
addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
FontLoader.prototype.addNativeFontFace =
function fontLoader_addNativeFontFace(nativeFontFace) {
this.nativeFontFaces.push(nativeFontFace);
document.fonts.add(nativeFontFace);
},
};
bind: function fontLoaderBind(fonts, callback) {
FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
var rules = [];
var fontsToLoad = [];
var fontLoadPromises = [];
@ -158,9 +166,10 @@ FontLoader.prototype = {
} else {
request.complete();
}
},
};
queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
FontLoader.prototype.queueLoadingCallback =
function FontLoader_queueLoadingCallback(callback) {
function LoadLoader_completeRequest() {
assert(!request.end, 'completeRequest() cannot be called twice');
request.end = Date.now();
@ -182,11 +191,10 @@ FontLoader.prototype = {
};
context.requests.push(request);
return request;
},
};
prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
fonts,
request) {
FontLoader.prototype.prepareFontLoadEvent =
function fontLoaderPrepareFontLoadEvent(rules, fonts, request) {
/** Hack begin */
// There's currently no event when a font has finished downloading so the
// following code is a dirty hack to 'guess' when a font is
@ -285,36 +293,34 @@ FontLoader.prototype = {
request.complete();
});
/** Hack end */
}
//#else
//bind: function fontLoaderBind(fonts, callback) {
// for (var i = 0, ii = fonts.length; i < ii; i++) {
// var font = fonts[i];
// if (font.attached) {
// continue;
// }
//
// font.attached = true;
// var rule = font.createFontFaceRule();
// if (rule) {
// this.insertRule(rule);
// }
// }
//
// setTimeout(callback);
//}
//#endif
};
//#if !(MOZCENTRAL)
FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
!!document.fonts;
//#endif
//#if !(MOZCENTRAL || CHROME)
Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
get: function () {
};
} else {
FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
for (var i = 0, ii = fonts.length; i < ii; i++) {
var font = fonts[i];
if (font.attached) {
continue;
}
font.attached = true;
var rule = font.createFontFaceRule();
if (rule) {
this.insertRule(rule);
}
}
setTimeout(callback);
};
}
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
!!document.fonts;
}
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL || CHROME')) {
var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() {
if (typeof navigator === 'undefined') {
// node.js - we can pretend sync font loading is supported.
return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
return true;
}
var supported = false;
@ -326,12 +332,17 @@ Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
supported = true;
}
// TODO other browsers
return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
},
enumerable: true,
configurable: true
});
//#endif
return supported;
};
Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
get: function () {
return shadow(FontLoader, 'isSyncFontLoadingSupported',
isSyncFontLoadingSupported());
},
enumerable: true,
configurable: true
});
}
var IsEvalSupportedCached = {
get value() {
@ -349,25 +360,27 @@ var FontFaceObject = (function FontFaceObjectClosure() {
this.options = options;
}
FontFaceObject.prototype = {
//#if !(MOZCENTRAL)
createNativeFontFace: function FontFaceObject_createNativeFontFace() {
if (!this.data) {
return null;
}
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
if (!this.data) {
return null;
}
if (this.options.disableFontFace) {
this.disableFontFace = true;
return null;
}
if (this.options.disableFontFace) {
this.disableFontFace = true;
return null;
}
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
var nativeFontFace = new FontFace(this.loadedName, this.data, {});
if (this.options.fontRegistry) {
this.options.fontRegistry.registerFont(this);
if (this.options.fontRegistry) {
this.options.fontRegistry.registerFont(this);
}
return nativeFontFace;
} else {
throw new Error('Not implemented: createNativeFontFace');
}
return nativeFontFace;
},
//#endif
createFontFaceRule: function FontFaceObject_createFontFaceRule() {
if (!this.data) {
@ -434,6 +447,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
return this.compiledGlyphs[character];
}
};
return FontFaceObject;
})();