If the font isn't supported, don't handle it

This commit is contained in:
Julian Viereck 2011-09-15 21:54:47 -07:00
parent 845230d8b0
commit 8e36114cfa
2 changed files with 27 additions and 7 deletions

View File

@ -184,6 +184,7 @@ if (!isWorker) {
*/ */
var FontLoader = { var FontLoader = {
scratchCtx: null, scratchCtx: null,
loading: {},
/** /**
* Create the canvas used for measuring the width of text. * Create the canvas used for measuring the width of text.
@ -221,18 +222,22 @@ var FontLoader = {
* the font is loaded. * the font is loaded.
*/ */
bind: function(objId, fontObj) { bind: function(objId, fontObj) {
console.log("load font", objId); this.loading[objId] = true;
var encoding = fontObj.encoding; var encoding = fontObj.encoding;
var testStr = "";
// If the font has a encoding defined. If, use the characters of the // If the font has an encoding, build the test string based on it. If the
// encoding, otherwise use some dump string for testing. // font doesn't have an encoding, the font can't been used right now and
if (Object.keys(encoding).length != 0) { // we skip here.
if (fontObj.supported) {
var testStr = "";
for (var enc in encoding) { for (var enc in encoding) {
testStr += String.fromCharCode(encoding[enc].unicode); testStr += String.fromCharCode(encoding[enc].unicode);
} }
} else { } else {
console.log("empty font.encoding"); // This font isn't fully supported yet. Resolve the object such that
testStr = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+='!"; // the execution continues but do nothing else.
Objects.resolve(objId);
return;
} }
var before = this.measure(fontObj, testStr); var before = this.measure(fontObj, testStr);
@ -244,6 +249,7 @@ var FontLoader = {
for (var i = 0; i < measure.length; i++) { for (var i = 0; i < measure.length; i++) {
if (measure[i] !== before[i]) { if (measure[i] !== before[i]) {
console.log("loaded font", objId); console.log("loaded font", objId);
delete this.loading[objId];
Objects.resolve(objId); Objects.resolve(objId);
return; return;
} }
@ -448,6 +454,8 @@ var FontShape = (function FontShape() {
this.$name1 = italic + ' ' + bold + ' '; this.$name1 = italic + ' ' + bold + ' ';
this.$name2 = 'px "' + name + '", "'; this.$name2 = 'px "' + name + '", "';
this.supported = Object.keys(this.encoding).length != 0;
}; };
function int16(bytes) { function int16(bytes) {

12
pdf.js
View File

@ -5165,6 +5165,12 @@ var CanvasGraphics = (function() {
this.moveText(0, this.current.leading); this.moveText(0, this.current.leading);
}, },
showText: function(text) { showText: function(text) {
// If the current font isn't supported, we can't display the text and
// bail out.
if (!this.current.font.supported) {
return;
}
var ctx = this.ctx; var ctx = this.ctx;
var current = this.current; var current = this.current;
var originalText = text; var originalText = text;
@ -5213,6 +5219,12 @@ var CanvasGraphics = (function() {
this.ctx.restore(); this.ctx.restore();
}, },
showSpacedText: function(arr) { showSpacedText: function(arr) {
// If the current font isn't supported, we can't display the text and
// bail out.
if (!this.current.font.supported) {
return;
}
for (var i = 0; i < arr.length; ++i) { for (var i = 0; i < arr.length; ++i) {
var e = arr[i]; var e = arr[i];
if (IsNum(e)) { if (IsNum(e)) {