diff --git a/README.md b/README.md index 97db68d36..f3500ae4d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pdf.js - + ## Overview diff --git a/extensions/firefox/install.rdf b/extensions/firefox/install.rdf index 952d55fbf..8b793c525 100644 --- a/extensions/firefox/install.rdf +++ b/extensions/firefox/install.rdf @@ -6,13 +6,13 @@ uriloader@pdf.js pdf.js - 0.1 + 0.1.0 chrome://pdf.js/skin/logo.png {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 6.0 - 11.0.* + 11.0a1 true @@ -20,5 +20,6 @@ Vivien Nicolas pdf.js uri loader https://github.com/mozilla/pdf.js/ + 2 diff --git a/src/canvas.js b/src/canvas.js index 16a870817..1e8febea8 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -568,12 +568,12 @@ var CanvasGraphics = (function canvasGraphics() { var ctx = this.ctx; var current = this.current; var textHScale = current.textHScale; - var font = current.font; + var fontMatrix = current.font.fontMatrix || IDENTITY_MATRIX; ctx.transform.apply(ctx, current.textMatrix); ctx.scale(1, -1); ctx.translate(current.x, -1 * current.y); - ctx.transform.apply(ctx, font.fontMatrix || IDENTITY_MATRIX); + ctx.transform.apply(ctx, fontMatrix); ctx.scale(1 / textHScale, 1); }, getTextGeometry: function canvasGetTextGeometry() { @@ -626,6 +626,8 @@ var CanvasGraphics = (function canvasGraphics() { var charSpacing = current.charSpacing; var wordSpacing = current.wordSpacing; var textHScale = current.textHScale; + var fontMatrix = font.fontMatrix || IDENTITY_MATRIX; + var textHScale2 = textHScale * fontMatrix[0]; var glyphsLength = glyphs.length; var textLayer = this.textLayer; var text = {str: '', length: 0, canvasWidth: 0, geom: {}}; @@ -644,7 +646,6 @@ var CanvasGraphics = (function canvasGraphics() { ctx.transform.apply(ctx, current.textMatrix); ctx.translate(current.x, current.y); - var fontMatrix = font.fontMatrix || IDENTITY_MATRIX; ctx.scale(1 / textHScale, 1); for (var i = 0; i < glyphsLength; ++i) { @@ -662,13 +663,14 @@ var CanvasGraphics = (function canvasGraphics() { this.restore(); var transformed = Util.applyTransform([glyph.width, 0], fontMatrix); - var charWidth = transformed[0] * fontSize + charSpacing; - ctx.translate(charWidth, 0); - current.x += charWidth; + var width = transformed[0] * fontSize + charSpacing; - text.str += glyph.fontChar; + ctx.translate(width, 0); + current.x += width * textHScale2; + + text.str += glyph.unicode; text.length++; - text.canvasWidth += charWidth; + text.canvasWidth += width; } ctx.restore(); } else { @@ -689,12 +691,11 @@ var CanvasGraphics = (function canvasGraphics() { ctx.fillText(char, width, 0); width += charWidth; - text.str += char === ' ' ? ' ' : char; + text.str += glyph.unicode === ' ' ? ' ' : glyph.unicode; text.length++; text.canvasWidth += charWidth; } - - current.x += width; + current.x += width * textHScale2; ctx.restore(); } @@ -707,7 +708,8 @@ var CanvasGraphics = (function canvasGraphics() { var ctx = this.ctx; var current = this.current; var fontSize = current.fontSize; - var textHScale = current.textHScale; + var textHScale2 = current.textHScale * + (current.font.fontMatrix || IDENTITY_MATRIX)[0]; var arrLength = arr.length; var textLayer = this.textLayer; var font = current.font; @@ -724,7 +726,7 @@ var CanvasGraphics = (function canvasGraphics() { for (var i = 0; i < arrLength; ++i) { var e = arr[i]; if (isNum(e)) { - var spacingLength = -e * 0.001 * fontSize * textHScale; + var spacingLength = -e * 0.001 * fontSize * textHScale2; current.x += spacingLength; if (textSelection) { diff --git a/src/core.js b/src/core.js index e6d47d636..6b7845efd 100644 --- a/src/core.js +++ b/src/core.js @@ -560,20 +560,9 @@ var PDFDoc = (function pdfDoc() { var properties = data[4]; if (file) { + // Rewrap the ArrayBuffer in a stream. var fontFileDict = new Dict(); - fontFileDict.map = file.dict.map; - - var fontFile = new Stream(file.bytes, file.start, - file.end - file.start, fontFileDict); - - // Check if this is a FlateStream. Otherwise just use the created - // Stream one. This makes complex_ttf_font.pdf work. - var cmf = file.bytes[0]; - if ((cmf & 0x0f) == 0x08) { - file = new FlateStream(fontFile); - } else { - file = fontFile; - } + file = new Stream(file, 0, file.length, fontFileDict); } // For now, resolve the font object here direclty. The real font diff --git a/src/evaluator.js b/src/evaluator.js index 3e687c72d..954c3bec3 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -155,6 +155,11 @@ var PartialEvaluator = (function partialEvaluator() { font.loadedName = loadedName; var translated = font.translated; + // Convert the file to an ArrayBuffer which will be turned back into + // a Stream in the main thread. + if (translated.file) + translated.file = translated.file.getBytes(); + handler.send('obj', [ loadedName, 'Font', @@ -493,6 +498,8 @@ var PartialEvaluator = (function partialEvaluator() { var baseName = encoding.get('BaseEncoding'); if (baseName) baseEncoding = Encodings[baseName.name]; + else + hasEncoding = false; // base encoding was not provided // Load the differences between the base and original if (encoding.has('Differences')) { diff --git a/src/fonts.js b/src/fonts.js index 9aabb3f57..2e95a7c94 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -764,6 +764,7 @@ var Font = (function Font() { this.hasEncoding = properties.hasEncoding; this.fontMatrix = properties.fontMatrix; + this.widthMultiplier = 1.0; if (properties.type == 'Type3') return; @@ -826,6 +827,8 @@ var Font = (function Font() { this.data = data; this.fontMatrix = properties.fontMatrix; + this.widthMultiplier = !properties.fontMatrix ? 1.0 : + 1.0 / properties.fontMatrix[0]; this.encoding = properties.baseEncoding; this.hasShortCmap = properties.hasShortCmap; this.loadedName = getUniqueName(); @@ -2131,10 +2134,12 @@ var Font = (function Font() { if (typeof unicodeChars === 'number') unicodeChars = String.fromCharCode(unicodeChars); + width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier; + return { fontChar: String.fromCharCode(unicode), unicode: unicodeChars, - width: isNum(width) ? width : this.defaultWidth, + width: width, codeIRQueue: codeIRQueue }; }, diff --git a/src/glyphlist.js b/src/glyphlist.js index 5691f8546..01b94442a 100644 --- a/src/glyphlist.js +++ b/src/glyphlist.js @@ -4287,6 +4287,7 @@ var GlyphsUnicode = { zretroflexhook: 0x0290, zstroke: 0x01B6, zuhiragana: 0x305A, - zukatakana: 0x30BA + zukatakana: 0x30BA, + '.notdef': 0x0000 }; diff --git a/test/pdfs/piperine.pdf.link b/test/pdfs/piperine.pdf.link new file mode 100644 index 000000000..0d38690ee --- /dev/null +++ b/test/pdfs/piperine.pdf.link @@ -0,0 +1 @@ +http://www.erowid.org/archive/rhodium/chemistry/3base/piperonal.pepper/piperine.pepper/465e03piperine.pdf diff --git a/test/pdfs/protectip.pdf.link b/test/pdfs/protectip.pdf.link new file mode 100644 index 000000000..1af1bd87b --- /dev/null +++ b/test/pdfs/protectip.pdf.link @@ -0,0 +1 @@ +http://leahy.senate.gov/imo/media/doc/BillText-PROTECTIPAct.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 87af30659..dd861c9f2 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -276,5 +276,19 @@ "link": false, "rounds": 1, "type": "eq" + }, + { "id": "protectip", + "file": "pdfs/protectip.pdf", + "md5": "676e7a7b8f96d04825361832b1838a93", + "link": true, + "rounds": 1, + "type": "eq" + }, + { "id": "piperine", + "file": "pdfs/piperine.pdf", + "md5": "603ca43dc5732dbba1579f122958c0c2", + "link": true, + "rounds": 1, + "type": "eq" } ]