Add a way to disable fonts that won't load
This commit is contained in:
parent
c345a4c75e
commit
2feec66b74
27
fonts.js
27
fonts.js
@ -25,6 +25,12 @@ var kMaxWaitForFontFace = 1000;
|
|||||||
var fontCount = 0;
|
var fontCount = 0;
|
||||||
var fontName = "";
|
var fontName = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If for some reason one want to debug without fonts activated, it just need
|
||||||
|
* to turn this pref to true/false.
|
||||||
|
*/
|
||||||
|
var kDisableFonts = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hold a map of decoded fonts and of the standard fourteen Type1 fonts and
|
* Hold a map of decoded fonts and of the standard fourteen Type1 fonts and
|
||||||
* their acronyms.
|
* their acronyms.
|
||||||
@ -93,6 +99,16 @@ var Font = function(aName, aFile, aProperties) {
|
|||||||
}
|
}
|
||||||
fontCount++;
|
fontCount++;
|
||||||
|
|
||||||
|
if (aProperties.ignore || kDisableFonts) {
|
||||||
|
Fonts[aName] = {
|
||||||
|
data: aFile,
|
||||||
|
loading: false,
|
||||||
|
properties: {},
|
||||||
|
cache: Object.create(null)
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (aProperties.type) {
|
switch (aProperties.type) {
|
||||||
case "Type1":
|
case "Type1":
|
||||||
var cff = new CFF(aName, aFile, aProperties);
|
var cff = new CFF(aName, aFile, aProperties);
|
||||||
@ -203,19 +219,21 @@ Font.prototype = {
|
|||||||
if (debug)
|
if (debug)
|
||||||
ctx.fillText(testString, 20, 20);
|
ctx.fillText(testString, 20, 20);
|
||||||
|
|
||||||
var start = Date.now();
|
|
||||||
var interval = window.setInterval(function canvasInterval(self) {
|
var interval = window.setInterval(function canvasInterval(self) {
|
||||||
|
this.start = this.start || Date.now();
|
||||||
ctx.font = "bold italic 20px " + fontName + ", Symbol, Arial";
|
ctx.font = "bold italic 20px " + fontName + ", Symbol, Arial";
|
||||||
|
|
||||||
// For some reasons the font has not loaded, so mark it loaded for the
|
// For some reasons the font has not loaded, so mark it loaded for the
|
||||||
// page to proceed but cry
|
// page to proceed but cry
|
||||||
if ((Date.now() - start) >= kMaxWaitForFontFace) {
|
if ((Date.now() - this.start) >= kMaxWaitForFontFace) {
|
||||||
window.clearInterval(interval);
|
window.clearInterval(interval);
|
||||||
Fonts[fontName].loading = false;
|
Fonts[fontName].loading = false;
|
||||||
warn("Is " + fontName + " for charset: " + charset + " loaded?");
|
warn("Is " + fontName + " for charset: " + charset + " loaded?");
|
||||||
|
this.start = 0;
|
||||||
} else if (textWidth != ctx.measureText(testString).width) {
|
} else if (textWidth != ctx.measureText(testString).width) {
|
||||||
window.clearInterval(interval);
|
window.clearInterval(interval);
|
||||||
Fonts[fontName].loading = false;
|
Fonts[fontName].loading = false;
|
||||||
|
this.start = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
@ -747,9 +765,12 @@ var TrueType = function(aName, aFile, aProperties) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var offsetDelta = 0;
|
||||||
|
|
||||||
// Replace the old CMAP table
|
// Replace the old CMAP table
|
||||||
var rewrittedCMAP = this._createCMAPTable(glyphs);
|
var rewrittedCMAP = this._createCMAPTable(glyphs);
|
||||||
var offsetDelta = rewrittedCMAP.length - originalCMAP.data.length;
|
offsetDelta = rewrittedCMAP.length - originalCMAP.data.length;
|
||||||
originalCMAP.data = rewrittedCMAP;
|
originalCMAP.data = rewrittedCMAP;
|
||||||
|
|
||||||
// Rewrite the 'post' table if needed
|
// Rewrite the 'post' table if needed
|
||||||
|
17
pdf.js
17
pdf.js
@ -1900,9 +1900,16 @@ var CanvasGraphics = (function() {
|
|||||||
error("FontFile not found for font: " + fontName);
|
error("FontFile not found for font: " + fontName);
|
||||||
fontFile = xref.fetchIfRef(fontFile);
|
fontFile = xref.fetchIfRef(fontFile);
|
||||||
|
|
||||||
|
// Fonts with an embedded cmap but without any assignment in
|
||||||
|
// it are not yet supported, so ask the fonts loader to ignore
|
||||||
|
// them to not pay a stupid one sec latence.
|
||||||
|
var ignoreFont = true;
|
||||||
|
|
||||||
var encodingMap = {};
|
var encodingMap = {};
|
||||||
var charset = [];
|
var charset = [];
|
||||||
if (fontDict.has("Encoding")) {
|
if (fontDict.has("Encoding")) {
|
||||||
|
ignoreFont = false;
|
||||||
|
|
||||||
var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
|
var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
|
||||||
if (IsDict(encoding)) {
|
if (IsDict(encoding)) {
|
||||||
// Build a map between codes and glyphs
|
// Build a map between codes and glyphs
|
||||||
@ -1960,8 +1967,9 @@ var CanvasGraphics = (function() {
|
|||||||
error("useCMap is not implemented");
|
error("useCMap is not implemented");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "begincodespacerange":
|
|
||||||
case "beginbfrange":
|
case "beginbfrange":
|
||||||
|
ignoreFont = false;
|
||||||
|
case "begincodespacerange":
|
||||||
token = "";
|
token = "";
|
||||||
tokens = [];
|
tokens = [];
|
||||||
break;
|
break;
|
||||||
@ -2002,7 +2010,7 @@ var CanvasGraphics = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var subType = fontDict.get("Subtype");
|
var subType = fontDict.get("Subtype");
|
||||||
var bbox = descriptor.get("FontBBox");
|
var bbox = descriptor.get("FontBBox");
|
||||||
@ -2013,7 +2021,8 @@ var CanvasGraphics = (function() {
|
|||||||
type: subType.name,
|
type: subType.name,
|
||||||
encoding: encodingMap,
|
encoding: encodingMap,
|
||||||
charset: charset,
|
charset: charset,
|
||||||
bbox: bbox
|
bbox: bbox,
|
||||||
|
ignore: ignoreFont
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -2275,7 +2284,7 @@ var CanvasGraphics = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.current.fontSize = size;
|
this.current.fontSize = size;
|
||||||
this.ctx.font = this.current.fontSize +'px "' + fontName + '"';
|
this.ctx.font = this.current.fontSize +'px "' + fontName + '", Symbol';
|
||||||
},
|
},
|
||||||
setTextRenderingMode: function(mode) {
|
setTextRenderingMode: function(mode) {
|
||||||
TODO("text rendering mode");
|
TODO("text rendering mode");
|
||||||
|
Loading…
Reference in New Issue
Block a user