Merge pull request #4421 from timvandermeij/metadata-font-loader-syntax

Making src/display/{metadata,font_loader}.js adhere to the style guide
This commit is contained in:
Jonas Jenwald 2014-03-09 14:04:00 +01:00
commit ad623ffbb2
2 changed files with 22 additions and 14 deletions

View File

@ -24,15 +24,16 @@ var FontLoader = {
insertRule: function fontLoaderInsertRule(rule) { insertRule: function fontLoaderInsertRule(rule) {
var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG'); var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
if (!styleElement) { if (!styleElement) {
styleElement = document.createElement('style'); styleElement = document.createElement('style');
styleElement.id = 'PDFJS_FONT_STYLE_TAG'; styleElement.id = 'PDFJS_FONT_STYLE_TAG';
document.documentElement.getElementsByTagName('head')[0].appendChild( document.documentElement.getElementsByTagName('head')[0].appendChild(
styleElement); styleElement);
} }
var styleSheet = styleElement.sheet; var styleSheet = styleElement.sheet;
styleSheet.insertRule(rule, styleSheet.cssRules.length); styleSheet.insertRule(rule, styleSheet.cssRules.length);
}, },
clear: function fontLoaderClear() { clear: function fontLoaderClear() {
var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG'); var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
if (styleElement) { if (styleElement) {
@ -77,15 +78,17 @@ var FontLoader = {
}, },
isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() { isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
if (isWorker) if (isWorker) {
return false; return false;
}
// User agent string sniffing is bad, but there is no reliable way to tell // User agent string sniffing is bad, but there is no reliable way to tell
// if font is fully loaded and ready to be used with canvas. // if font is fully loaded and ready to be used with canvas.
var userAgent = window.navigator.userAgent; var userAgent = window.navigator.userAgent;
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent); var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
if (m && m[1] >= 14) if (m && m[1] >= 14) {
return true; return true;
}
// TODO other browsers // TODO other browsers
return false; return false;
})(), })(),
@ -258,8 +261,9 @@ var FontLoader = {
// //
// for (var i = 0, ii = fonts.length; i < ii; i++) { // for (var i = 0, ii = fonts.length; i < ii; i++) {
// var font = fonts[i]; // var font = fonts[i];
// if (font.attached) // if (font.attached) {
// continue; // continue;
// }
// //
// font.attached = true; // font.attached = true;
// font.bindDOM() // font.bindDOM()
@ -284,8 +288,9 @@ var FontFace = (function FontFaceClosure() {
} }
FontFace.prototype = { FontFace.prototype = {
bindDOM: function FontFace_bindDOM() { bindDOM: function FontFace_bindDOM() {
if (!this.data) if (!this.data) {
return null; return null;
}
if (PDFJS.disableFontFace) { if (PDFJS.disableFontFace) {
this.disableFontFace = true; this.disableFontFace = true;
@ -299,15 +304,16 @@ var FontFace = (function FontFaceClosure() {
var url = ('url(data:' + this.mimetype + ';base64,' + var url = ('url(data:' + this.mimetype + ';base64,' +
window.btoa(data) + ');'); window.btoa(data) + ');');
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}'; var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
FontLoader.insertRule(rule); FontLoader.insertRule(rule);
if (PDFJS.pdfBug && 'FontInspector' in globalScope && if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
globalScope['FontInspector'].enabled) globalScope['FontInspector'].enabled) {
globalScope['FontInspector'].fontAdded(this, url); globalScope['FontInspector'].fontAdded(this, url);
}
return rule; return rule;
}, },
getPathGenerator: function (objs, character) { getPathGenerator: function (objs, character) {
if (!(character in this.compiledGlyphs)) { if (!(character in this.compiledGlyphs)) {
var js = objs.get(this.loadedName + '_path_' + character); var js = objs.get(this.loadedName + '_path_' + character);

View File

@ -59,20 +59,22 @@ var Metadata = PDFJS.Metadata = (function MetadataClosure() {
if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta> if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
rdf = rdf.firstChild; rdf = rdf.firstChild;
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
rdf = rdf.nextSibling; rdf = rdf.nextSibling;
}
} }
var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null; var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
return; return;
}
var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength; var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
for (i = 0, length = children.length; i < length; i++) { for (i = 0, length = children.length; i < length; i++) {
desc = children[i]; desc = children[i];
if (desc.nodeName.toLowerCase() !== 'rdf:description') if (desc.nodeName.toLowerCase() !== 'rdf:description') {
continue; continue;
}
for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) { for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') { if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {