From f6eb9cecd39a85db6a3da574a13bef512e97767b Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Fri, 8 Jul 2011 14:58:19 -0700 Subject: [PATCH 1/2] avoid font lookup by id in showText --- fonts.js | 1 + pdf.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fonts.js b/fonts.js index 380a0ea30..1f1db3652 100755 --- a/fonts.js +++ b/fonts.js @@ -413,6 +413,7 @@ function getUnicodeRangeFor(value) { var Font = (function() { var constructor = function font_constructor(name, file, properties) { this.name = name; + this.textMatrix = properties.textMatrix || IDENTITY_MATRIX; this.encoding = properties.encoding; // If the font is to be ignored, register it like an already loaded font diff --git a/pdf.js b/pdf.js index eef6deed5..1666ce658 100644 --- a/pdf.js +++ b/pdf.js @@ -3925,24 +3925,24 @@ var CanvasGraphics = (function() { showText: function(text) { // TODO: apply charSpacing, wordSpacing, textHScale - this.ctx.save(); - this.ctx.transform.apply(this.ctx, this.current.textMatrix); - this.ctx.scale(1, -1); + var ctx = this.ctx; + var current = this.current; + + ctx.save(); + ctx.transform.apply(ctx, current.textMatrix); + ctx.scale(1, -1); if (this.ctx.$showText) { - this.ctx.$showText(this.current.y, Fonts.charsToUnicode(text)); + ctx.$showText(current.y, Fonts.charsToUnicode(text)); } else { text = Fonts.charsToUnicode(text); - this.ctx.translate(this.current.x, -1 * this.current.y); + ctx.translate(this.current.x, -1 * this.current.y); var font = this.current.font; - if (font) { - var fontInfo = Fonts.lookupById(font.id); - if (fontInfo && fontInfo.properties.textMatrix) - this.ctx.transform.apply(this.ctx, fontInfo.properties.textMatrix); - } - this.ctx.fillText(text, 0, 0); - this.current.x += Fonts.measureText(text); + if (font) + ctx.transform.apply(ctx, font.textMatrix); + ctx.fillText(text, 0, 0); + current.x += Fonts.measureText(text); } this.ctx.restore(); From 6fecf59ca7b68605639730232b078eac7339a91e Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Fri, 8 Jul 2011 15:13:33 -0700 Subject: [PATCH 2/2] address review comments --- pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 1666ce658..e357732f2 100644 --- a/pdf.js +++ b/pdf.js @@ -3936,7 +3936,7 @@ var CanvasGraphics = (function() { ctx.$showText(current.y, Fonts.charsToUnicode(text)); } else { text = Fonts.charsToUnicode(text); - ctx.translate(this.current.x, -1 * this.current.y); + ctx.translate(current.x, -1 * current.y); var font = this.current.font; if (font)