diff --git a/fonts.js b/fonts.js index 99d6dd218..7c30dfc7e 100644 --- a/fonts.js +++ b/fonts.js @@ -64,8 +64,8 @@ var Fonts = { var unicode = encoding[charcode]; // Check if the glyph has already been converted - if (unicode instanceof Name) - unicode = encoding[unicode] = GlyphsUnicode[unicode.name]; + if (!IsNum(unicode)) + unicode = encoding[unicode] = GlyphsUnicode[unicode.name]; // Handle surrogate pairs if (unicode > 0xFFFF) { @@ -165,6 +165,7 @@ var Font = (function () { warn("Font " + properties.type + " is not supported"); break; } + this.data = data; Fonts[name] = { data: data, @@ -779,9 +780,18 @@ var Font = (function () { }); }, - bindDOM: function font_bindDom(data) { + bindDOM: function font_bindDom(data, callback) { var fontName = this.name; + // Just adding the font-face to the DOM doesn't make it load. It + // seems it's loaded once Gecko notices it's used. Therefore, + // add a div on the page using the loaded font. + var div = document.createElement("div"); + var style = 'font-family:"' + name + + '";position: absolute;top:-99999;left:-99999;z-index:-99999'; + div.setAttribute("style", style); + document.body.appendChild(div); + /** Hack begin */ // Actually there is not event when a font has finished downloading so // the following code are a dirty hack to 'guess' when a font is ready @@ -801,15 +811,19 @@ var Font = (function () { // For some reasons the font has not loaded, so mark it loaded for the // page to proceed but cry - if ((Date.now() - this.start) >= kMaxWaitForFontFace) { - window.clearInterval(interval); - Fonts[fontName].loading = false; - warn("Is " + fontName + " loaded?"); - this.start = 0; - } else if (textWidth != ctx.measureText(testString).width) { - window.clearInterval(interval); - Fonts[fontName].loading = false; - this.start = 0; + if (textWidth == ctx.measureText(testString).width) { + if ((Date.now() - this.start) < kMaxWaitForFontFace) { + return; + } else { + warn("Is " + fontName + " loaded?"); + } + } + + window.clearInterval(interval); + Fonts[fontName].loading = false; + this.start = 0; + if (callback) { + callback(); } }, 30, this); diff --git a/pdf.js b/pdf.js index 3179f42ec..bc54fd8ab 100644 --- a/pdf.js +++ b/pdf.js @@ -816,7 +816,7 @@ var DecryptStream = (function() { DecodeStream.call(this); } - const chunkSize = 512; + var chunkSize = 512; constructor.prototype = Object.create(DecodeStream.prototype); constructor.prototype.readBlock = function() { @@ -910,18 +910,18 @@ var Ascii85Stream = (function() { var CCITTFaxStream = (function() { - const ccittEOL = -2; - const twoDimPass = 0; - const twoDimHoriz = 1; - const twoDimVert0 = 2; - const twoDimVertR1 = 3; - const twoDimVertL1 = 4; - const twoDimVertR2 = 5; - const twoDimVertL2 = 6; - const twoDimVertR3 = 7; - const twoDimVertL3 = 8; + var ccittEOL = -2; + var twoDimPass = 0; + var twoDimHoriz = 1; + var twoDimVert0 = 2; + var twoDimVertR1 = 3; + var twoDimVertL1 = 4; + var twoDimVertR2 = 5; + var twoDimVertL2 = 6; + var twoDimVertR3 = 7; + var twoDimVertL3 = 8; - const twoDimTable = [ + var twoDimTable = [ [-1, -1], [-1, -1], // 000000x [7, twoDimVertL3], // 0000010 [7, twoDimVertR3], // 0000011 @@ -989,7 +989,7 @@ var CCITTFaxStream = (function() { [1, twoDimVert0], [1, twoDimVert0] ]; - const whiteTable1 = [ + var whiteTable1 = [ [-1, -1], // 00000 [12, ccittEOL], // 00001 [-1, -1], [-1, -1], // 0001x @@ -1011,7 +1011,7 @@ var CCITTFaxStream = (function() { [12, 2560] // 11111 ]; - const whiteTable2 = [ + var whiteTable2 = [ [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx [8, 29], [8, 29], // 00000010x [8, 30], [8, 30], // 00000011x @@ -1175,7 +1175,7 @@ var CCITTFaxStream = (function() { [4, 7], [4, 7], [4, 7], [4, 7] ]; - const blackTable1 = [ + var blackTable1 = [ [-1, -1], [-1, -1], // 000000000000x [12, ccittEOL], [12, ccittEOL], // 000000000001x [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx @@ -1236,7 +1236,7 @@ var CCITTFaxStream = (function() { [10, 64], [10, 64], [10, 64], [10, 64] ]; - const blackTable2 = [ + var blackTable2 = [ [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], @@ -1315,7 +1315,7 @@ var CCITTFaxStream = (function() { [7, 12], [7, 12], [7, 12], [7, 12] ]; - const blackTable3 = [ + var blackTable3 = [ [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx [6, 9], // 000100 [6, 8], // 000101 @@ -3819,6 +3819,9 @@ var CanvasGraphics = (function() { this.current.fontSize = size; this.ctx.font = this.current.fontSize +'px "' + fontName + '", Symbol'; + if (this.ctx.$setFont) { + this.ctx.$setFont(fontName); + } }, setTextRenderingMode: function(mode) { TODO("text rendering mode"); diff --git a/viewer_worker.html b/viewer_worker.html index 51f2b9d8a..fe3319d62 100644 --- a/viewer_worker.html +++ b/viewer_worker.html @@ -1,7 +1,10 @@ Simple pdf.js page worker viewer - + + + +