diff --git a/lib/excanvas-diff.patch b/lib/excanvas-diff.patch
new file mode 100644
index 00000000..2b7d64cc
--- /dev/null
+++ b/lib/excanvas-diff.patch
@@ -0,0 +1,196 @@
+Index: excanvas.js
+===================================================================
+--- excanvas.js (revision 63)
++++ excanvas.js (working copy)
+@@ -255,6 +255,7 @@
+ o2.arcScaleX_ = o1.arcScaleX_;
+ o2.arcScaleY_ = o1.arcScaleY_;
+ o2.lineScale_ = o1.lineScale_;
++ o2.rotation_ = o1.rotation_; // used for images
+ }
+
+ var colorData = {
+@@ -599,6 +600,7 @@
+ this.arcScaleX_ = 1;
+ this.arcScaleY_ = 1;
+ this.lineScale_ = 1;
++ this.rotation_ = 0;
+ }
+
+ var contextPrototype = CanvasRenderingContext2D_.prototype;
+@@ -763,23 +765,31 @@
+ return gradient;
+ };
+
+- contextPrototype.drawImage = function(image, var_args) {
++ contextPrototype.drawImage = function(image) {
+ var dx, dy, dw, dh, sx, sy, sw, sh;
+-
++
++ // to fix new Image() we check the existance of runtimeStyle
++ var rts = image.runtimeStyle.width;
++
+ // to find the original width we overide the width and height
+- var oldRuntimeWidth = image.runtimeStyle.width;
+- var oldRuntimeHeight = image.runtimeStyle.height;
+- image.runtimeStyle.width = 'auto';
+- image.runtimeStyle.height = 'auto';
++ if(rts) {
++ var oldRuntimeWidth = image.runtimeStyle.width;
++ var oldRuntimeHeight = image.runtimeStyle.height;
++
++ image.runtimeStyle.width = 'auto';
++ image.runtimeStyle.height = 'auto';
++ }
+
+ // get the original size
+ var w = image.width;
+ var h = image.height;
+-
++
+ // and remove overides
+- image.runtimeStyle.width = oldRuntimeWidth;
+- image.runtimeStyle.height = oldRuntimeHeight;
+-
++ if(rts) {
++ image.runtimeStyle.width = oldRuntimeWidth;
++ image.runtimeStyle.height = oldRuntimeHeight;
++ }
++
+ if (arguments.length == 3) {
+ dx = arguments[1];
+ dy = arguments[2];
+@@ -816,29 +826,44 @@
+
+ var W = 10;
+ var H = 10;
++
++ var scaleX = scaleY = 1;
++
++ // FIX: divs give better quality then vml image and also fixes transparent PNG's
++ vmlStr.push('
' ,
+- '
',
+- '');
++ vmlStr.push(' ">');
+
+- this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));
++ // Draw a special cropping div if needed
++ if (sx || sy) {
++ // Apply scales to width and height
++ vmlStr.push('
');
++ }
++
++
++ // Apply scales to width and height
++ vmlStr.push('
');
++
++ // Close the crop div if necessary
++ if (sx || sy) vmlStr.push('
');
++
++ vmlStr.push('
');
++
++ this.element_.insertAdjacentHTML('beforeEnd', vmlStr.join(''));
+ };
+
+ contextPrototype.stroke = function(aFill) {
+@@ -1155,6 +1197,8 @@
+ var c = mc(aRot);
+ var s = ms(aRot);
+
++ this.rotation_ += aRot;
++
+ var m1 = [
+ [c, s, 0],
+ [-s, c, 0],
+@@ -1308,7 +1352,11 @@
+ }
+ var doc = this.element_.ownerDocument;
+ this.textMeasureEl_.innerHTML = '';
+- this.textMeasureEl_.style.font = this.font;
++ // FIX: Apply current font style to textMeasureEl to get correct size
++ var fontStyle = getComputedStyle(processFontStyle(this.font), this.element_),
++ fontStyleString = buildStyle(fontStyle);
++ this.textMeasureEl_.style.font = fontStyleString;
++
+ // Don't use innerHTML or innerText because they allow markup/whitespace.
+ this.textMeasureEl_.appendChild(doc.createTextNode(text));
+ return {width: this.textMeasureEl_.offsetWidth};
diff --git a/lib/excanvas.js b/lib/excanvas.js
index 0def37f9..a6dceecb 100644
--- a/lib/excanvas.js
+++ b/lib/excanvas.js
@@ -253,6 +253,7 @@ if (!document.createElement('canvas').getContext) {
o2.arcScaleX_ = o1.arcScaleX_;
o2.arcScaleY_ = o1.arcScaleY_;
o2.lineScale_ = o1.lineScale_;
+ o2.rotation_ = o1.rotation_; // used for images
}
var colorData = {
@@ -603,6 +604,7 @@ if (!document.createElement('canvas').getContext) {
this.arcScaleX_ = 1;
this.arcScaleY_ = 1;
this.lineScale_ = 1;
+ this.rotation_ = 0;
}
var contextPrototype = CanvasRenderingContext2D_.prototype;
@@ -767,23 +769,31 @@ if (!document.createElement('canvas').getContext) {
return gradient;
};
- contextPrototype.drawImage = function(image, var_args) {
+ contextPrototype.drawImage = function(image) {
var dx, dy, dw, dh, sx, sy, sw, sh;
-
+
+ // to fix new Image() we check the existance of runtimeStyle
+ var rts = image.runtimeStyle.width;
+
// to find the original width we overide the width and height
- var oldRuntimeWidth = image.runtimeStyle.width;
- var oldRuntimeHeight = image.runtimeStyle.height;
- image.runtimeStyle.width = 'auto';
- image.runtimeStyle.height = 'auto';
+ if(rts) {
+ var oldRuntimeWidth = image.runtimeStyle.width;
+ var oldRuntimeHeight = image.runtimeStyle.height;
+
+ image.runtimeStyle.width = 'auto';
+ image.runtimeStyle.height = 'auto';
+ }
// get the original size
var w = image.width;
var h = image.height;
-
+
// and remove overides
- image.runtimeStyle.width = oldRuntimeWidth;
- image.runtimeStyle.height = oldRuntimeHeight;
-
+ if(rts) {
+ image.runtimeStyle.width = oldRuntimeWidth;
+ image.runtimeStyle.height = oldRuntimeHeight;
+ }
+
if (arguments.length == 3) {
dx = arguments[1];
dy = arguments[2];
@@ -820,29 +830,44 @@ if (!document.createElement('canvas').getContext) {
var W = 10;
var H = 10;
-
- // For some reason that I've now forgotten, using divs didn't work
- vmlStr.push(' ' ,
- '',
- '');
+ vmlStr.push(' ">');
- this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));
+ // Draw a special cropping div if needed
+ if (sx || sy) {
+ // Apply scales to width and height
+ vmlStr.push('');
+ }
+
+
+ // Apply scales to width and height
+ vmlStr.push('
');
+
+ // Close the crop div if necessary
+ if (sx || sy) vmlStr.push('
');
+
+ vmlStr.push('
');
+
+ this.element_.insertAdjacentHTML('beforeEnd', vmlStr.join(''));
};
contextPrototype.stroke = function(aFill) {
@@ -1156,6 +1198,8 @@ if (!document.createElement('canvas').getContext) {
var c = mc(aRot);
var s = ms(aRot);
+ this.rotation_ += aRot;
+
var m1 = [
[c, s, 0],
[-s, c, 0],
@@ -1309,7 +1353,11 @@ if (!document.createElement('canvas').getContext) {
}
var doc = this.element_.ownerDocument;
this.textMeasureEl_.innerHTML = '';
- this.textMeasureEl_.style.font = this.font;
+ // FIX: Apply current font style to textMeasureEl to get correct size
+ var fontStyle = getComputedStyle(processFontStyle(this.font), this.element_),
+ fontStyleString = buildStyle(fontStyle);
+ this.textMeasureEl_.style.font = fontStyleString;
+
// Don't use innerHTML or innerText because they allow markup/whitespace.
this.textMeasureEl_.appendChild(doc.createTextNode(text));
return {width: this.textMeasureEl_.offsetWidth};
diff --git a/lib/excanvas.js.orig b/lib/excanvas.js.orig
new file mode 100644
index 00000000..0def37f9
--- /dev/null
+++ b/lib/excanvas.js.orig
@@ -0,0 +1,1416 @@
+// Copyright 2006 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+// Known Issues:
+//
+// * Patterns only support repeat.
+// * Radial gradient are not implemented. The VML version of these look very
+// different from the canvas one.
+// * Clipping paths are not implemented.
+// * Coordsize. The width and height attribute have higher priority than the
+// width and height style values which isn't correct.
+// * Painting mode isn't implemented.
+// * Canvas width/height should is using content-box by default. IE in
+// Quirks mode will draw the canvas using border-box. Either change your
+// doctype to HTML5
+// (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype)
+// or use Box Sizing Behavior from WebFX
+// (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html)
+// * Non uniform scaling does not correctly scale strokes.
+// * Optimize. There is always room for speed improvements.
+
+// Only add this code if we do not already have a canvas implementation
+if (!document.createElement('canvas').getContext) {
+
+(function() {
+
+ // alias some functions to make (compiled) code shorter
+ var m = Math;
+ var mr = m.round;
+ var ms = m.sin;
+ var mc = m.cos;
+ var abs = m.abs;
+ var sqrt = m.sqrt;
+
+ // this is used for sub pixel precision
+ var Z = 10;
+ var Z2 = Z / 2;
+
+ var IE_VERSION = +navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];
+
+ /**
+ * This funtion is assigned to the