diff --git a/fonts.js b/fonts.js index aa0ad2933..8bc169aa6 100644 --- a/fonts.js +++ b/fonts.js @@ -100,18 +100,6 @@ var Font = function(aName, aFile, aProperties) { break; case "TrueType": - // TrueType is disabled for the moment since the sanitizer prevent it - // from loading because of an overdated cmap table - return Fonts[aName] = { - data: null, - properties: { - encoding: {}, - charset: null - }, - loading: false, - cache: Object.create(null) - }; - this.mimetype = "font/opentype"; var ttf = new TrueType(aFile); this.font = ttf.data; @@ -184,7 +172,7 @@ Font.prototype = { document.body.appendChild(canvas); // Retrieve font charset - var charset = Fonts[fontName].charset || []; + var charset = Fonts[fontName].properties.charset || []; // if the charset is too small make it repeat a few times var count = 30; while (count-- && charset.length <= 30) @@ -205,7 +193,7 @@ Font.prototype = { } } ctx.font = "bold italic 20px " + fontName + ", Symbol, Arial"; - var textWidth = ctx.measureText(testString); + var textWidth = ctx.measureText(testString).width; if (debug) ctx.fillText(testString, 20, 20); @@ -220,7 +208,7 @@ Font.prototype = { window.clearInterval(interval); Fonts[fontName].loading = false; warn("Is " + fontName + " for charset: " + charset + " loaded?"); - } else if (textWidth != ctx.measureText(testString)) { + } else if (textWidth != ctx.measureText(testString).width) { window.clearInterval(interval); Fonts[fontName].loading = false; } diff --git a/pdf.js b/pdf.js index 399708b84..2288654f3 100644 --- a/pdf.js +++ b/pdf.js @@ -1902,6 +1902,7 @@ var CanvasGraphics = (function() { // Generate the custom cmap of the font if needed var encodingMap = {}; + var charset = []; if (fontDict.has("Encoding")) { var encoding = xref.fetchIfRef(fontDict.get("Encoding")); if (IsDict(encoding)) { @@ -1923,16 +1924,23 @@ var CanvasGraphics = (function() { if (!encoding) error("Unknown font encoding"); - var widths = xref.fetchIfRef(fontDict.get("Widths")); var firstChar = xref.fetchIfRef(fontDict.get("FirstChar")); + + var index = 0; + for (var j = 0; j < encoding.length; j++) { + encodingMap[firstChar + index++] = GlyphsUnicode[encoding[j]]; + } + + var widths = xref.fetchIfRef(fontDict.get("Widths")); assertWellFormed(IsArray(widths) && IsInt(firstChar), "invalid font Widths or FirstChar"); - var charset = []; for (var j = 0; j < widths.length; j++) { if (widths[j]) charset.push(encoding[j + firstChar]); } } + } else if (fontDict.has("ToUnicode")) { + TODO("ToUnicode stream translation not implemented"); } var subType = fontDict.get("Subtype");