From 8cec09ec0e84c74099391ab6b1b604214d78a5ee Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Sat, 25 Jun 2011 11:26:54 -0400 Subject: [PATCH] keep track of charScale, wordScale and textHScale --- pdf.js | 60 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/pdf.js b/pdf.js index d06d07e0e..ec8c91f8d 100644 --- a/pdf.js +++ b/pdf.js @@ -2103,30 +2103,6 @@ var PDFDoc = (function() { return constructor; })(); -var IDENTITY_MATRIX = [ 1, 0, 0, 1, 0, 0 ]; - -// contexts store most of the state we need natively. -// However, PDF needs a bit more state, which we store here. -var CanvasExtraState = (function() { - function constructor() { - // Are soft masks and alpha values shapes or opacities? - this.alphaIsShape = false; - this.fontSize = 0.0; - this.textMatrix = IDENTITY_MATRIX; - this.leading = 0.0; - this.colorSpace = null; - // Current point (in user coordinates) - this.x = 0.0; - this.y = 0.0; - // Start of text line (in text coordinates) - this.lineX = 0.0; - this.lineY = 0.0; - } - constructor.prototype = { - }; - return constructor; -})(); - var Encodings = { get ExpertEncoding() { return shadow(this, "ExpertEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, @@ -2301,6 +2277,34 @@ var Encodings = { } }; +var IDENTITY_MATRIX = [ 1, 0, 0, 1, 0, 0 ]; + +// contexts store most of the state we need natively. +// However, PDF needs a bit more state, which we store here. +var CanvasExtraState = (function() { + function constructor() { + // Are soft masks and alpha values shapes or opacities? + this.alphaIsShape = false; + this.fontSize = 0; + this.textMatrix = IDENTITY_MATRIX; + this.leading = 0; + this.colorSpace = null; + // Current point (in user coordinates) + this.x = 0; + this.y = 0; + // Start of text line (in text coordinates) + this.lineX = 0; + this.lineY = 0; + // Character and word spacing + this.charSpace = 0; + this.wordSpace = 0; + this.textHScale = 100; + } + constructor.prototype = { + }; + return constructor; +})(); + function ScratchCanvas(width, height) { var canvas = document.createElement("canvas"); canvas.width = width; @@ -2799,13 +2803,13 @@ var CanvasGraphics = (function() { endText: function() { }, setCharSpacing: function(spacing) { - TODO("character (glyph?) spacing"); + this.ctx.charSpacing = spacing; }, setWordSpacing: function(spacing) { - TODO("word spacing"); + this.ctx.wordSpacing = spacing; }, setHScale: function(scale) { - TODO("horizontal text scale"); + this.ctx.textHScale = (scale % 100) * 0.01; }, setLeading: function(leading) { this.current.leading = leading; @@ -2868,6 +2872,8 @@ var CanvasGraphics = (function() { this.moveText(0, this.current.leading); }, 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);