|
|
@ -51,6 +51,16 @@ var JpegStreamProxy = (function() { |
|
|
|
return constructor; |
|
|
|
return constructor; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Really simple GradientProxy. There is currently only one active gradient at
|
|
|
|
|
|
|
|
// the time, meaning you can't create a gradient, create a second one and then
|
|
|
|
|
|
|
|
// use the first one again. As this isn't used in pdf.js right now, it's okay.
|
|
|
|
|
|
|
|
function GradientProxy(stack, x0, y0, x1, y1) { |
|
|
|
|
|
|
|
stack.push(["$createLinearGradient", [x0, y0, x1, y1]]); |
|
|
|
|
|
|
|
this.addColorStop = function(i, rgba) { |
|
|
|
|
|
|
|
stack.push(["$addColorStop", [i, rgba]]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function CanvasProxy(width, height) { |
|
|
|
function CanvasProxy(width, height) { |
|
|
|
var stack = this.$stack = []; |
|
|
|
var stack = this.$stack = []; |
|
|
|
|
|
|
|
|
|
|
@ -79,7 +89,7 @@ function CanvasProxy(width, height) { |
|
|
|
"translate", |
|
|
|
"translate", |
|
|
|
"transform", |
|
|
|
"transform", |
|
|
|
"setTransform", |
|
|
|
"setTransform", |
|
|
|
"createLinearGradient", |
|
|
|
// "createLinearGradient",
|
|
|
|
"createPattern", |
|
|
|
"createPattern", |
|
|
|
"clearRect", |
|
|
|
"clearRect", |
|
|
|
"fillRect", |
|
|
|
"fillRect", |
|
|
@ -104,6 +114,10 @@ function CanvasProxy(width, height) { |
|
|
|
"$showText" |
|
|
|
"$showText" |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.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) { |
|
|
|
this.drawImage = function(image, x, y, width, height, sx, sy, swidth, sheight) { |
|
|
|
if (image instanceof ImageCanvasProxy) { |
|
|
|
if (image instanceof ImageCanvasProxy) { |
|
|
|
stack.push(["$drawCanvas", [image.imgData, x, y, image.width, image.height]]); |
|
|
|
stack.push(["$drawCanvas", [image.imgData, x, y, image.width, image.height]]); |
|
|
@ -168,9 +182,26 @@ function CanvasProxy(width, height) { |
|
|
|
for (var name in ctxProp) { |
|
|
|
for (var name in ctxProp) { |
|
|
|
this["$" + name] = ctxProp[name]; |
|
|
|
this["$" + name] = ctxProp[name]; |
|
|
|
this.__defineGetter__(name, buildGetter(name)); |
|
|
|
this.__defineGetter__(name, buildGetter(name)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Special treatment for `fillStyle` and `strokeStyle`: The passed style
|
|
|
|
|
|
|
|
// might be a gradient. Need to check for that.
|
|
|
|
|
|
|
|
if (name == "fillStyle" || name == "strokeStyle") { |
|
|
|
|
|
|
|
function buildSetterStyle(name) { |
|
|
|
|
|
|
|
return function(value) { |
|
|
|
|
|
|
|
if (value instanceof GradientProxy) { |
|
|
|
|
|
|
|
stack.push(["$" + name + "Gradient"]); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
stack.push(["$", name, value]); |
|
|
|
|
|
|
|
return this["$" + name] = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.__defineSetter__(name, buildSetterStyle(name)); |
|
|
|
|
|
|
|
} else { |
|
|
|
this.__defineSetter__(name, buildSetter(name)); |
|
|
|
this.__defineSetter__(name, buildSetter(name)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CanvasProxy.prototype.flush = function() { |
|
|
|
CanvasProxy.prototype.flush = function() { |
|
|
|
postMessage("canvas_proxy_stack"); |
|
|
|
postMessage("canvas_proxy_stack"); |
|
|
|