/*
 * Paper.js
 *
 * This file is part of Paper.js, a JavaScript Vector Graphics Library,
 * based on Scriptographer.org and designed to be largely API compatible.
 * http://paperjs.org/
 * http://scriptographer.org/
 *
 * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
 * http://lehni.org/ & http://jonathanpuckey.com/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * All rights reserved.
 */

 /**
 * @name ProxyContext
 *
 * @class The ProxyContext is a helper class that helps Canvas debugging 
 * by logging all interactions with a 2D Canvas context.
 * 
 * @classexample
 * view._context = new ProxyContext(view._context);
 */
var ProxyContext = new function() {
	var descriptions = [
		'save()', 'restore()', 'scale(x,y)', 'rotate(angle)', 'translate(x,y)',
		'transform(a,b,c,d,e,f)', 'setTransform(a,b,c,d,e,f)', 'globalAlpha',
		'globalCompositeOperation', 'strokeStyle', 'fillStyle',
		'createLinearGradient(x0,y0,x1,y1)',
		'createRadialGradient(x0,y0,r0,x1,y1,r1)',
		'createPattern(image,repetition)', 'lineWidth', 'lineCap', 'lineJoin',
		'miterLimit', 'shadowOffsetX', 'shadowOffsetY', 'shadowBlur',
		'shadowColor', 'clearRect(x,y,w,h)', 'fillRect(x,y,w,h)',
		'strokeRect(x,y,w,h)', 'beginPath()', 'closePath()', 'moveTo(x,y)',
		'lineTo(x,y)', 'quadraticCurveTo(cpx,cpy,x,y)',
		'bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y)', 'arcTo(x1,y1,x2,y2,radius)',
		'rect(x,y,w,h)', 'arc(x,y,radius,startAngle,endAngle,anticlockwise)',
		'fill()', 'stroke()', 'drawSystemFocusRing()', 'drawCustomFocusRing()',
		'scrollPathIntoView()', 'clip()', 'isPointInPath(x,y)', 'font',
		'textAlign', 'textBaseline', 'fillText(text,x,y,maxWidth)',
		'strokeText(text,x,y,maxWidth)', 'measureText(text)',
		'drawImage(image,dx,dy)', 'drawImage(image,dx,dy,dw,dh)',
		'drawImage(image,sx,sy,sw,sh,dx,dy,dw,dh)', 'create(sw,sh)',
		'create(imagedata)', 'get(sx,sy,sw,sh)',
		'put(imagedata,dx,dy,dirtyX,dirtyY,dirtyWidth,dirtyHeight)'
	];
	var param = {
		initialize: function(context) {
			this._ctx = context;
			this._indents = 0;
		},
		getIndentation: function() {
			var str = '';
			for (var i = 0; i < this._indents; i++) {
				str += '	';
			}
			return str;
		}
	};
	Base.each(descriptions, function(description) {
		var matches = description.match(/^([^(]+)(\()*/),
			name = matches[1],
			isFunction = !!matches[2];
		if (isFunction) {
			param[name] = function() {
				if (name == 'restore') {
					this._indents--;
				}
				var args = Array.prototype.slice.call(arguments, 0).join(', '),
					string = 'ctx.' + name + '(' + args + ');';
				console.log(this.getIndentation() + string);
				this._ctx[name].apply(this._ctx, arguments);
				if (name == 'save') {
					this._indents++;
				}
			};
		} else {
			var capitalized = Base.capitalize(name);
			param['set' + capitalized] = function(value) {
				var logValue = value.substring ? '\'' + value + '\'' : value,
					string = 'ctx.' + name + ' = ' + logValue + ';';
				console.log(this.getIndentation() + string);
				return this._ctx[name] = value;
			};
			param['get' + capitalized] = function() {
				return this._ctx[name];
			};
		}
	});
	return Base.extend(param);
};

@@ -1836,16 +1836,25 @@
  'create
+ImageData
 (sw,sh)'
@@ -1864,16 +1864,25 @@
 %09'create
+ImageData
 (imageda
@@ -1891,16 +1891,25 @@
 )', 'get
+ImageData
 (sx,sy,s
@@ -1922,16 +1922,25 @@
 ,%0A%09%09'put
+ImageData
 (imageda
@@ -2662,57 +2662,8 @@
 %09%09%09%09
-this._ctx%5Bname%5D.apply(this._ctx, arguments);%0A%09%09%09%09
 if (
@@ -2703,24 +2703,80 @@
 nts++;%0A%09%09%09%09%7D
+%0A%09%09%09%09return this._ctx%5Bname%5D.apply(this._ctx, arguments);
 %0A%09%09%09%7D;%0A%09%09%7D e

Add missing ImageData relating functions to ProxyContext and fix problem where values weren't being returned.