diff --git a/editor/canvg/canvg.js b/editor/canvg/canvg.js index 17d0ef4b..c67269ec 100644 --- a/editor/canvg/canvg.js +++ b/editor/canvg/canvg.js @@ -11,11 +11,27 @@ if(!window.console) { window.console.log = function(str) {}; window.console.dir = function(str) {}; } + +// <3 IE +if(!Array.indexOf){ + Array.prototype.indexOf = function(obj){ + for(var i=0; i ignore mouse events + // ignoreAnimation: true => ignore animations + this.canvg = function (target, s, opts) { if (typeof target == 'string') { target = document.getElementById(target); } @@ -30,6 +46,7 @@ if(!window.console) { svg = target.svg; svg.stop(); } + svg.opts = opts; var ctx = target.getContext('2d'); if (s.substr(0,1) == '<') { @@ -43,7 +60,7 @@ if(!window.console) { } function build() { - var svg = {}; + var svg = { }; svg.FRAMERATE = 30; @@ -290,6 +307,13 @@ if(!window.console) { this.angleTo = function(p) { return Math.atan2(p.y - this.y, p.x - this.x); } + + this.applyTransform = function(v) { + var xp = this.x * v[0] + this.y * v[2] + v[4]; + var yp = this.x * v[1] + this.y * v[3] + v[5]; + this.x = xp; + this.y = yp; + } } svg.CreatePoint = function(s) { var a = svg.ToNumberArray(s); @@ -389,6 +413,10 @@ if(!window.console) { } } + this.isPointInBox = function(x, y) { + return (this.x1 <= x && x <= this.x2 && this.y1 <= y && y <= this.y2); + } + this.addPoint(x1, y1); this.addPoint(x2, y2); } @@ -404,6 +432,9 @@ if(!window.console) { this.apply = function(ctx) { ctx.translate(this.p.x || 0.0, this.p.y || 0.0); } + this.applyToPoint = function(p) { + p.applyTransform([1, 0, 0, 1, this.p.x || 0.0, this.p.y || 0.0]); + } } // rotate @@ -417,6 +448,12 @@ if(!window.console) { ctx.rotate(this.angle.Angle.toRadians()); ctx.translate(-this.cx, -this.cy); } + this.applyToPoint = function(p) { + var a = this.angle.Angle.toRadians(); + p.applyTransform([1, 0, 0, 1, this.p.x || 0.0, this.p.y || 0.0]); + p.applyTransform([Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0]); + p.applyTransform([1, 0, 0, 1, -this.p.x || 0.0, -this.p.y || 0.0]); + } } this.Type.scale = function(s) { @@ -424,6 +461,9 @@ if(!window.console) { this.apply = function(ctx) { ctx.scale(this.p.x || 1.0, this.p.y || this.p.x || 1.0); } + this.applyToPoint = function(p) { + p.applyTransform([this.p.x || 0.0, 0, 0, this.p.y || 0.0, 0, 0]); + } } this.Type.matrix = function(s) { @@ -431,6 +471,9 @@ if(!window.console) { this.apply = function(ctx) { ctx.transform(this.m[0], this.m[1], this.m[2], this.m[3], this.m[4], this.m[5]); } + this.applyToPoint = function(p) { + p.applyTransform(this.m); + } } this.Type.SkewBase = function(s) { @@ -455,12 +498,19 @@ if(!window.console) { this.Type.skewY.prototype = new this.Type.SkewBase; this.transforms = []; + this.apply = function(ctx) { for (var i=0; i