If the font isn't supported, don't handle it
This commit is contained in:
parent
845230d8b0
commit
8e36114cfa
22
fonts.js
22
fonts.js
@ -184,6 +184,7 @@ if (!isWorker) {
|
||||
*/
|
||||
var FontLoader = {
|
||||
scratchCtx: null,
|
||||
loading: {},
|
||||
|
||||
/**
|
||||
* Create the canvas used for measuring the width of text.
|
||||
@ -221,18 +222,22 @@ var FontLoader = {
|
||||
* the font is loaded.
|
||||
*/
|
||||
bind: function(objId, fontObj) {
|
||||
console.log("load font", objId);
|
||||
this.loading[objId] = true;
|
||||
var encoding = fontObj.encoding;
|
||||
var testStr = "";
|
||||
// If the font has a encoding defined. If, use the characters of the
|
||||
// encoding, otherwise use some dump string for testing.
|
||||
if (Object.keys(encoding).length != 0) {
|
||||
|
||||
// If the font has an encoding, build the test string based on it. If the
|
||||
// font doesn't have an encoding, the font can't been used right now and
|
||||
// we skip here.
|
||||
if (fontObj.supported) {
|
||||
var testStr = "";
|
||||
for (var enc in encoding) {
|
||||
testStr += String.fromCharCode(encoding[enc].unicode);
|
||||
}
|
||||
} else {
|
||||
console.log("empty font.encoding");
|
||||
testStr = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+='!";
|
||||
// This font isn't fully supported yet. Resolve the object such that
|
||||
// the execution continues but do nothing else.
|
||||
Objects.resolve(objId);
|
||||
return;
|
||||
}
|
||||
|
||||
var before = this.measure(fontObj, testStr);
|
||||
@ -244,6 +249,7 @@ var FontLoader = {
|
||||
for (var i = 0; i < measure.length; i++) {
|
||||
if (measure[i] !== before[i]) {
|
||||
console.log("loaded font", objId);
|
||||
delete this.loading[objId];
|
||||
Objects.resolve(objId);
|
||||
return;
|
||||
}
|
||||
@ -448,6 +454,8 @@ var FontShape = (function FontShape() {
|
||||
|
||||
this.$name1 = italic + ' ' + bold + ' ';
|
||||
this.$name2 = 'px "' + name + '", "';
|
||||
|
||||
this.supported = Object.keys(this.encoding).length != 0;
|
||||
};
|
||||
|
||||
function int16(bytes) {
|
||||
|
12
pdf.js
12
pdf.js
@ -5165,6 +5165,12 @@ var CanvasGraphics = (function() {
|
||||
this.moveText(0, this.current.leading);
|
||||
},
|
||||
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 current = this.current;
|
||||
var originalText = text;
|
||||
@ -5213,6 +5219,12 @@ var CanvasGraphics = (function() {
|
||||
this.ctx.restore();
|
||||
},
|
||||
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) {
|
||||
var e = arr[i];
|
||||
if (IsNum(e)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user