Less hacky save/restore/moveText impl
This commit is contained in:
parent
2ecb90fd45
commit
b860bc8d60
52
pdf.js
52
pdf.js
@ -920,48 +920,23 @@ var EchoGraphics = (function() {
|
|||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var CanvasGraphicsState = (function() {
|
// <canvas> contexts store most of the state we need natively.
|
||||||
function constructor(canvasCtx, hdpi, vdpi, pageBox) {
|
// However, PDF needs a bit more state, which we store here.
|
||||||
// XXX canvas2d context has much of this; need to fill in what
|
var CanvasExtraState = (function() {
|
||||||
// canvas state doesn't store.
|
function constructor() {
|
||||||
this.ctx = canvasCtx;
|
// Current text position (in text coordinates)
|
||||||
|
this.lineX = 0.0;
|
||||||
// Page state
|
this.lineY = 0.0;
|
||||||
this.hdpi = hdpi
|
|
||||||
this.vdpi = vdpi
|
|
||||||
// ...
|
|
||||||
// Fill state
|
|
||||||
// ...
|
|
||||||
// Stroke state
|
|
||||||
// ...
|
|
||||||
// Line state
|
|
||||||
// ...
|
|
||||||
// Text state
|
|
||||||
// ...
|
|
||||||
// Current path
|
|
||||||
// ...
|
|
||||||
// Transforms
|
|
||||||
// ...
|
|
||||||
// Clipping
|
|
||||||
// ...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
// Coordinate transforms
|
|
||||||
// ...
|
|
||||||
// CTM mutators
|
|
||||||
// ...
|
|
||||||
// Path mutators
|
|
||||||
// ...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var CanvasGraphics = (function() {
|
var CanvasGraphics = (function() {
|
||||||
function constructor(canvasCtx, hdpi, vdpi, pageBox) {
|
function constructor(canvasCtx, hdpi, vdpi, pageBox) {
|
||||||
this.ctx = canvasCtx;
|
this.ctx = canvasCtx;
|
||||||
this.current = new CanvasGraphicsState(this.ctx, hdpi, vdpi, pageBox);
|
this.current = new CanvasExtraState();
|
||||||
this.stateStack = [ ];
|
this.stateStack = [ ];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,11 +950,11 @@ var CanvasGraphics = (function() {
|
|||||||
},
|
},
|
||||||
save: function() {
|
save: function() {
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
//this.stateStack.push(this.current);
|
this.stateStack.push(this.current);
|
||||||
//this.current = new CanvasGraphicsState(this.ctx, hdpi, vdpi, pageBox);
|
this.current = new CanvasExtraState();
|
||||||
},
|
},
|
||||||
restore: function() {
|
restore: function() {
|
||||||
//this.current = this.stateStack.pop();
|
this.current = this.stateStack.pop();
|
||||||
this.ctx.restore();
|
this.ctx.restore();
|
||||||
},
|
},
|
||||||
transform: function(a, b, c, d, e, f) {
|
transform: function(a, b, c, d, e, f) {
|
||||||
@ -1032,10 +1007,11 @@ var CanvasGraphics = (function() {
|
|||||||
this.ctx.font = size +'px '+ font.BaseFont;
|
this.ctx.font = size +'px '+ font.BaseFont;
|
||||||
},
|
},
|
||||||
moveText: function (x, y) {
|
moveText: function (x, y) {
|
||||||
this.moveTo(x, y);
|
this.current.lineX = x;
|
||||||
|
this.current.lineY = y;
|
||||||
},
|
},
|
||||||
showText: function(text) {
|
showText: function(text) {
|
||||||
this.ctx.fillText(text, 100, 100);
|
this.ctx.fillText(text, this.current.lineX, this.current.lineY);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Type3 fonts
|
// Type3 fonts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user