From b860bc8d6086903802b1572d8e6bf821229c2ffe Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 5 May 2011 12:40:34 -0500 Subject: [PATCH] Less hacky save/restore/moveText impl --- pdf.js | 52 ++++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/pdf.js b/pdf.js index 4f4d3dc6e..73f6b4b34 100644 --- a/pdf.js +++ b/pdf.js @@ -920,48 +920,23 @@ var EchoGraphics = (function() { return constructor; })(); -var CanvasGraphicsState = (function() { - function constructor(canvasCtx, hdpi, vdpi, pageBox) { - // XXX canvas2d context has much of this; need to fill in what - // canvas state doesn't store. - this.ctx = canvasCtx; - - // Page state - this.hdpi = hdpi - this.vdpi = vdpi - // ... - // Fill state - // ... - // Stroke state - // ... - // Line state - // ... - // Text state - // ... - // Current path - // ... - // Transforms - // ... - // Clipping - // ... +// 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() { + // Current text position (in text coordinates) + this.lineX = 0.0; + this.lineY = 0.0; } - constructor.prototype = { - // Coordinate transforms - // ... - // CTM mutators - // ... - // Path mutators - // ... }; - return constructor; })(); var CanvasGraphics = (function() { function constructor(canvasCtx, hdpi, vdpi, pageBox) { this.ctx = canvasCtx; - this.current = new CanvasGraphicsState(this.ctx, hdpi, vdpi, pageBox); + this.current = new CanvasExtraState(); this.stateStack = [ ]; } @@ -975,11 +950,11 @@ var CanvasGraphics = (function() { }, save: function() { this.ctx.save(); - //this.stateStack.push(this.current); - //this.current = new CanvasGraphicsState(this.ctx, hdpi, vdpi, pageBox); + this.stateStack.push(this.current); + this.current = new CanvasExtraState(); }, restore: function() { - //this.current = this.stateStack.pop(); + this.current = this.stateStack.pop(); this.ctx.restore(); }, transform: function(a, b, c, d, e, f) { @@ -1032,10 +1007,11 @@ var CanvasGraphics = (function() { this.ctx.font = size +'px '+ font.BaseFont; }, moveText: function (x, y) { - this.moveTo(x, y); + this.current.lineX = x; + this.current.lineY = y; }, showText: function(text) { - this.ctx.fillText(text, 100, 100); + this.ctx.fillText(text, this.current.lineX, this.current.lineY); }, // Type3 fonts