function CanvasProxy(width, height) {
var stack = this.$stack = [];
+ // Dummy context exposed.
+ var ctx = {};
+ this.getContext = function(type) {
+ if (type != "2d") {
+ throw "CanvasProxy can only provide a 2d context.";
+ }
+ return ctx;
+ }
+
// Expose only the minimum of the canvas object - there is no dom to do
// more here.
- this.canvas = {
+ ctx.canvas = {
width: width,
height: height
}
"$showText"
];
- this.createLinearGradient = function(x0, y0, x1, y1) {
+ ctx.createLinearGradient = function(x0, y0, x1, y1) {
return new GradientProxy(stack, x0, y0, x1, y1);
}
- this.drawImage = function(image, x, y, width, height, sx, sy, swidth, sheight) {
+ ctx.drawImage = function(image, x, y, width, height, sx, sy, swidth, sheight) {
if (image instanceof ImageCanvasProxy) {
stack.push(["$drawCanvas", [image.imgData, x, y, image.width, image.height]]);
} else if(image instanceof JpegStreamProxy) {
var name;
for (var i = 0; i < ctxFunc.length; i++) {
name = ctxFunc[i];
- this[name] = buildFuncCall(name);
+ ctx[name] = buildFuncCall(name);
}
var ctxProp = {
function buildGetter(name) {
return function() {
- return this["$" + name];
+ return ctx["$" + name];
}
}
function buildSetter(name) {
return function(value) {
stack.push(["$", name, value]);
- return this["$" + name] = value;
+ return ctx["$" + name] = value;
}
}
for (var name in ctxProp) {
- this["$" + name] = ctxProp[name];
- this.__defineGetter__(name, buildGetter(name));
+ ctx["$" + name] = ctxProp[name];
+ ctx.__defineGetter__(name, buildGetter(name));
// Special treatment for `fillStyle` and `strokeStyle`: The passed style
// might be a gradient. Need to check for that.
stack.push(["$" + name + "Gradient"]);
} else {
stack.push(["$", name, value]);
- return this["$" + name] = value;
+ return ctx["$" + name] = value;
}
}
}
- this.__defineSetter__(name, buildSetterStyle(name));
+ ctx.__defineSetter__(name, buildSetterStyle(name));
} else {
- this.__defineSetter__(name, buildSetter(name));
+ ctx.__defineSetter__(name, buildSetter(name));
}
}
}
// Use the JpegStreamProxy proxy.
JpegStream = JpegStreamProxy;
-// var array = new Uint8Array(2);
-// array[0] = 1;
-// array[1] = 300;
-// postMessage(array);
-
var timer = null;
function tic() {
timer = Date.now();
timer = null;
}
-
+// Create the WebWorkerProxyCanvas.
var canvas = new CanvasProxy(1224, 1584);
-// canvas.moveTo(0, 10);
-// canvas.lineTo(0, 20);
-// canvas.lineTo(500, 500);
-// canvas.flush();
-// canvas.stroke();
-// canvas.flush();
-log("test");
var pageInterval;
var pdfDocument = null;
// page.compile will collect all fonts for us, once we have loaded them
// we can trigger the actual page rendering with page.display
var fonts = [];
- var gfx = new CanvasGraphics(canvas, ImageCanvasProxy);
+ var gfx = new CanvasGraphics(canvas.getContext("2d"), ImageCanvasProxy);
page.compile(gfx, fonts);
// Inspect fonts and translate the missing one.