/tags/v5.0-ouadji/api/js/dojo/src/gfx/svg.js |
---|
New file |
0,0 → 1,473 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.svg"); |
dojo.require("dojo.lang.declare"); |
dojo.require("dojo.svg"); |
dojo.require("dojo.gfx.color"); |
dojo.require("dojo.gfx.common"); |
dojo.require("dojo.gfx.shape"); |
dojo.require("dojo.gfx.path"); |
dojo.require("dojo.experimental"); |
dojo.experimental("dojo.gfx.svg"); |
dojo.gfx.svg.getRef = function (fill) { |
if (!fill || fill == "none") { |
return null; |
} |
if (fill.match(/^url\(#.+\)$/)) { |
return dojo.byId(fill.slice(5, -1)); |
} |
if (dojo.render.html.opera && fill.match(/^#dj_unique_.+$/)) { |
return dojo.byId(fill.slice(1)); |
} |
return null; |
}; |
dojo.lang.extend(dojo.gfx.Shape, {setFill:function (fill) { |
if (!fill) { |
this.fillStyle = null; |
this.rawNode.setAttribute("fill", "none"); |
this.rawNode.setAttribute("fill-opacity", 0); |
return this; |
} |
if (typeof (fill) == "object" && "type" in fill) { |
switch (fill.type) { |
case "linear": |
var f = dojo.gfx.makeParameters(dojo.gfx.defaultLinearGradient, fill); |
var gradient = this._setFillObject(f, "linearGradient"); |
dojo.lang.forEach(["x1", "y1", "x2", "y2"], function (x) { |
gradient.setAttribute(x, f[x].toFixed(8)); |
}); |
break; |
case "radial": |
var f = dojo.gfx.makeParameters(dojo.gfx.defaultRadialGradient, fill); |
var gradient = this._setFillObject(f, "radialGradient"); |
dojo.lang.forEach(["cx", "cy", "r"], function (x) { |
gradient.setAttribute(x, f[x].toFixed(8)); |
}); |
break; |
case "pattern": |
var f = dojo.gfx.makeParameters(dojo.gfx.defaultPattern, fill); |
var pattern = this._setFillObject(f, "pattern"); |
dojo.lang.forEach(["x", "y", "width", "height"], function (x) { |
pattern.setAttribute(x, f[x].toFixed(8)); |
}); |
break; |
} |
return this; |
} |
var f = dojo.gfx.normalizeColor(fill); |
this.fillStyle = f; |
this.rawNode.setAttribute("fill", f.toCss()); |
this.rawNode.setAttribute("fill-opacity", f.a); |
return this; |
}, setStroke:function (stroke) { |
if (!stroke) { |
this.strokeStyle = null; |
this.rawNode.setAttribute("stroke", "none"); |
this.rawNode.setAttribute("stroke-opacity", 0); |
return this; |
} |
this.strokeStyle = dojo.gfx.makeParameters(dojo.gfx.defaultStroke, stroke); |
this.strokeStyle.color = dojo.gfx.normalizeColor(this.strokeStyle.color); |
var s = this.strokeStyle; |
var rn = this.rawNode; |
if (s) { |
rn.setAttribute("stroke", s.color.toCss()); |
rn.setAttribute("stroke-opacity", s.color.a); |
rn.setAttribute("stroke-width", s.width); |
rn.setAttribute("stroke-linecap", s.cap); |
if (typeof (s.join) == "number") { |
rn.setAttribute("stroke-linejoin", "miter"); |
rn.setAttribute("stroke-miterlimit", s.join); |
} else { |
rn.setAttribute("stroke-linejoin", s.join); |
} |
} |
return this; |
}, _setFillObject:function (f, nodeType) { |
var def_elems = this.rawNode.parentNode.getElementsByTagName("defs"); |
if (def_elems.length == 0) { |
return this; |
} |
this.fillStyle = f; |
var defs = def_elems[0]; |
var fill = this.rawNode.getAttribute("fill"); |
var ref = dojo.gfx.svg.getRef(fill); |
if (ref) { |
fill = ref; |
if (fill.tagName.toLowerCase() != nodeType.toLowerCase()) { |
var id = fill.id; |
fill.parentNode.removeChild(fill); |
fill = document.createElementNS(dojo.svg.xmlns.svg, nodeType); |
fill.setAttribute("id", id); |
defs.appendChild(fill); |
} else { |
while (fill.childNodes.length) { |
fill.removeChild(fill.lastChild); |
} |
} |
} else { |
fill = document.createElementNS(dojo.svg.xmlns.svg, nodeType); |
fill.setAttribute("id", dojo.dom.getUniqueId()); |
defs.appendChild(fill); |
} |
if (nodeType == "pattern") { |
fill.setAttribute("patternUnits", "userSpaceOnUse"); |
var img = document.createElementNS(dojo.svg.xmlns.svg, "image"); |
img.setAttribute("x", 0); |
img.setAttribute("y", 0); |
img.setAttribute("width", f.width.toFixed(8)); |
img.setAttribute("height", f.height.toFixed(8)); |
img.setAttributeNS(dojo.svg.xmlns.xlink, "href", f.src); |
fill.appendChild(img); |
} else { |
fill.setAttribute("gradientUnits", "userSpaceOnUse"); |
for (var i = 0; i < f.colors.length; ++i) { |
f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color); |
var t = document.createElementNS(dojo.svg.xmlns.svg, "stop"); |
t.setAttribute("offset", f.colors[i].offset.toFixed(8)); |
t.setAttribute("stop-color", f.colors[i].color.toCss()); |
fill.appendChild(t); |
} |
} |
this.rawNode.setAttribute("fill", "url(#" + fill.getAttribute("id") + ")"); |
this.rawNode.removeAttribute("fill-opacity"); |
return fill; |
}, _applyTransform:function () { |
var matrix = this._getRealMatrix(); |
if (matrix) { |
var tm = this.matrix; |
this.rawNode.setAttribute("transform", "matrix(" + tm.xx.toFixed(8) + "," + tm.yx.toFixed(8) + "," + tm.xy.toFixed(8) + "," + tm.yy.toFixed(8) + "," + tm.dx.toFixed(8) + "," + tm.dy.toFixed(8) + ")"); |
} else { |
this.rawNode.removeAttribute("transform"); |
} |
return this; |
}, setRawNode:function (rawNode) { |
with (rawNode) { |
setAttribute("fill", "none"); |
setAttribute("fill-opacity", 0); |
setAttribute("stroke", "none"); |
setAttribute("stroke-opacity", 0); |
setAttribute("stroke-width", 1); |
setAttribute("stroke-linecap", "butt"); |
setAttribute("stroke-linejoin", "miter"); |
setAttribute("stroke-miterlimit", 4); |
} |
this.rawNode = rawNode; |
}, moveToFront:function () { |
this.rawNode.parentNode.appendChild(this.rawNode); |
return this; |
}, moveToBack:function () { |
this.rawNode.parentNode.insertBefore(this.rawNode, this.rawNode.parentNode.firstChild); |
return this; |
}, setShape:function (newShape) { |
this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
for (var i in this.shape) { |
if (i != "type") { |
this.rawNode.setAttribute(i, this.shape[i]); |
} |
} |
return this; |
}, attachFill:function (rawNode) { |
var fillStyle = null; |
if (rawNode) { |
var fill = rawNode.getAttribute("fill"); |
if (fill == "none") { |
return; |
} |
var ref = dojo.gfx.svg.getRef(fill); |
if (ref) { |
var gradient = ref; |
switch (gradient.tagName.toLowerCase()) { |
case "lineargradient": |
fillStyle = this._getGradient(dojo.gfx.defaultLinearGradient, gradient); |
dojo.lang.forEach(["x1", "y1", "x2", "y2"], function (x) { |
fillStyle[x] = gradient.getAttribute(x); |
}); |
break; |
case "radialgradient": |
fillStyle = this._getGradient(dojo.gfx.defaultRadialGradient, gradient); |
dojo.lang.forEach(["cx", "cy", "r"], function (x) { |
fillStyle[x] = gradient.getAttribute(x); |
}); |
fillStyle.cx = gradient.getAttribute("cx"); |
fillStyle.cy = gradient.getAttribute("cy"); |
fillStyle.r = gradient.getAttribute("r"); |
break; |
case "pattern": |
fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultPattern, true); |
dojo.lang.forEach(["x", "y", "width", "height"], function (x) { |
fillStyle[x] = gradient.getAttribute(x); |
}); |
fillStyle.src = gradient.firstChild.getAttributeNS(dojo.svg.xmlns.xlink, "href"); |
break; |
} |
} else { |
fillStyle = new dojo.gfx.color.Color(fill); |
var opacity = rawNode.getAttribute("fill-opacity"); |
if (opacity != null) { |
fillStyle.a = opacity; |
} |
} |
} |
return fillStyle; |
}, _getGradient:function (defaultGradient, gradient) { |
var fillStyle = dojo.lang.shallowCopy(defaultGradient, true); |
fillStyle.colors = []; |
for (var i = 0; i < gradient.childNodes.length; ++i) { |
fillStyle.colors.push({offset:gradient.childNodes[i].getAttribute("offset"), color:new dojo.gfx.color.Color(gradient.childNodes[i].getAttribute("stop-color"))}); |
} |
return fillStyle; |
}, attachStroke:function (rawNode) { |
if (!rawNode) { |
return; |
} |
var stroke = rawNode.getAttribute("stroke"); |
if (stroke == null || stroke == "none") { |
return null; |
} |
var strokeStyle = dojo.lang.shallowCopy(dojo.gfx.defaultStroke, true); |
var color = new dojo.gfx.color.Color(stroke); |
if (color) { |
strokeStyle.color = color; |
strokeStyle.color.a = rawNode.getAttribute("stroke-opacity"); |
strokeStyle.width = rawNode.getAttribute("stroke-width"); |
strokeStyle.cap = rawNode.getAttribute("stroke-linecap"); |
strokeStyle.join = rawNode.getAttribute("stroke-linejoin"); |
if (strokeStyle.join == "miter") { |
strokeStyle.join = rawNode.getAttribute("stroke-miterlimit"); |
} |
} |
return strokeStyle; |
}, attachTransform:function (rawNode) { |
var matrix = null; |
if (rawNode) { |
matrix = rawNode.getAttribute("transform"); |
if (matrix.match(/^matrix\(.+\)$/)) { |
var t = matrix.slice(7, -1).split(","); |
matrix = dojo.gfx.matrix.normalize({xx:parseFloat(t[0]), xy:parseFloat(t[2]), yx:parseFloat(t[1]), yy:parseFloat(t[3]), dx:parseFloat(t[4]), dy:parseFloat(t[5])}); |
} |
} |
return matrix; |
}, attachShape:function (rawNode) { |
var shape = null; |
if (rawNode) { |
shape = dojo.lang.shallowCopy(this.shape, true); |
for (var i in shape) { |
shape[i] = rawNode.getAttribute(i); |
} |
} |
return shape; |
}, attach:function (rawNode) { |
if (rawNode) { |
this.rawNode = rawNode; |
this.fillStyle = this.attachFill(rawNode); |
this.strokeStyle = this.attachStroke(rawNode); |
this.matrix = this.attachTransform(rawNode); |
this.shape = this.attachShape(rawNode); |
} |
}}); |
dojo.declare("dojo.gfx.Group", dojo.gfx.Shape, {setRawNode:function (rawNode) { |
this.rawNode = rawNode; |
}}); |
dojo.gfx.Group.nodeType = "g"; |
dojo.declare("dojo.gfx.Rect", dojo.gfx.shape.Rect, {attachShape:function (rawNode) { |
var shape = null; |
if (rawNode) { |
shape = dojo.gfx.Rect.superclass.attachShape.apply(this, arguments); |
shape.r = Math.min(rawNode.getAttribute("rx"), rawNode.getAttribute("ry")); |
} |
return shape; |
}, setShape:function (newShape) { |
this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
for (var i in this.shape) { |
if (i != "type" && i != "r") { |
this.rawNode.setAttribute(i, this.shape[i]); |
} |
} |
this.rawNode.setAttribute("rx", this.shape.r); |
this.rawNode.setAttribute("ry", this.shape.r); |
return this; |
}}); |
dojo.gfx.Rect.nodeType = "rect"; |
dojo.gfx.Ellipse = dojo.gfx.shape.Ellipse; |
dojo.gfx.Ellipse.nodeType = "ellipse"; |
dojo.gfx.Circle = dojo.gfx.shape.Circle; |
dojo.gfx.Circle.nodeType = "circle"; |
dojo.gfx.Line = dojo.gfx.shape.Line; |
dojo.gfx.Line.nodeType = "line"; |
dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline, {setShape:function (points) { |
if (points && points instanceof Array) { |
this.shape = dojo.gfx.makeParameters(this.shape, {points:points}); |
if (closed && this.shape.points.length) { |
this.shape.points.push(this.shape.points[0]); |
} |
} else { |
this.shape = dojo.gfx.makeParameters(this.shape, points); |
} |
this.box = null; |
var attr = []; |
var p = this.shape.points; |
for (var i = 0; i < p.length; ++i) { |
attr.push(p[i].x.toFixed(8)); |
attr.push(p[i].y.toFixed(8)); |
} |
this.rawNode.setAttribute("points", attr.join(" ")); |
return this; |
}}); |
dojo.gfx.Polyline.nodeType = "polyline"; |
dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {setShape:function (newShape) { |
this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
var rawNode = this.rawNode; |
for (var i in this.shape) { |
if (i != "type" && i != "src") { |
rawNode.setAttribute(i, this.shape[i]); |
} |
} |
rawNode.setAttributeNS(dojo.svg.xmlns.xlink, "href", this.shape.src); |
return this; |
}, setStroke:function () { |
return this; |
}, setFill:function () { |
return this; |
}, attachStroke:function (rawNode) { |
return null; |
}, attachFill:function (rawNode) { |
return null; |
}}); |
dojo.gfx.Image.nodeType = "image"; |
dojo.declare("dojo.gfx.Path", dojo.gfx.path.Path, {_updateWithSegment:function (segment) { |
dojo.gfx.Path.superclass._updateWithSegment.apply(this, arguments); |
if (typeof (this.shape.path) == "string") { |
this.rawNode.setAttribute("d", this.shape.path); |
} |
}, setShape:function (newShape) { |
dojo.gfx.Path.superclass.setShape.apply(this, arguments); |
this.rawNode.setAttribute("d", this.shape.path); |
return this; |
}}); |
dojo.gfx.Path.nodeType = "path"; |
dojo.gfx._creators = {createPath:function (path) { |
return this.createObject(dojo.gfx.Path, path); |
}, createRect:function (rect) { |
return this.createObject(dojo.gfx.Rect, rect); |
}, createCircle:function (circle) { |
return this.createObject(dojo.gfx.Circle, circle); |
}, createEllipse:function (ellipse) { |
return this.createObject(dojo.gfx.Ellipse, ellipse); |
}, createLine:function (line) { |
return this.createObject(dojo.gfx.Line, line); |
}, createPolyline:function (points) { |
return this.createObject(dojo.gfx.Polyline, points); |
}, createImage:function (image) { |
return this.createObject(dojo.gfx.Image, image); |
}, createGroup:function () { |
return this.createObject(dojo.gfx.Group); |
}, createObject:function (shapeType, rawShape) { |
if (!this.rawNode) { |
return null; |
} |
var shape = new shapeType(); |
var node = document.createElementNS(dojo.svg.xmlns.svg, shapeType.nodeType); |
shape.setRawNode(node); |
this.rawNode.appendChild(node); |
shape.setShape(rawShape); |
this.add(shape); |
return shape; |
}, add:function (shape) { |
var oldParent = shape.getParent(); |
if (oldParent) { |
oldParent.remove(shape, true); |
} |
shape._setParent(this, null); |
this.rawNode.appendChild(shape.rawNode); |
return this; |
}, remove:function (shape, silently) { |
if (this.rawNode == shape.rawNode.parentNode) { |
this.rawNode.removeChild(shape.rawNode); |
} |
shape._setParent(null, null); |
return this; |
}}; |
dojo.gfx.attachNode = function (node) { |
if (!node) { |
return null; |
} |
var s = null; |
switch (node.tagName.toLowerCase()) { |
case dojo.gfx.Rect.nodeType: |
s = new dojo.gfx.Rect(); |
break; |
case dojo.gfx.Ellipse.nodeType: |
s = new dojo.gfx.Ellipse(); |
break; |
case dojo.gfx.Polyline.nodeType: |
s = new dojo.gfx.Polyline(); |
break; |
case dojo.gfx.Path.nodeType: |
s = new dojo.gfx.Path(); |
break; |
case dojo.gfx.Circle.nodeType: |
s = new dojo.gfx.Circle(); |
break; |
case dojo.gfx.Line.nodeType: |
s = new dojo.gfx.Line(); |
break; |
case dojo.gfx.Image.nodeType: |
s = new dojo.gfx.Image(); |
break; |
default: |
dojo.debug("FATAL ERROR! tagName = " + node.tagName); |
} |
s.attach(node); |
return s; |
}; |
dojo.lang.extend(dojo.gfx.Surface, {setDimensions:function (width, height) { |
if (!this.rawNode) { |
return this; |
} |
this.rawNode.setAttribute("width", width); |
this.rawNode.setAttribute("height", height); |
return this; |
}, getDimensions:function () { |
return this.rawNode ? {width:this.rawNode.getAttribute("width"), height:this.rawNode.getAttribute("height")} : null; |
}}); |
dojo.gfx.createSurface = function (parentNode, width, height) { |
var s = new dojo.gfx.Surface(); |
s.rawNode = document.createElementNS(dojo.svg.xmlns.svg, "svg"); |
s.rawNode.setAttribute("width", width); |
s.rawNode.setAttribute("height", height); |
var defs = new dojo.gfx.svg.Defines(); |
var node = document.createElementNS(dojo.svg.xmlns.svg, dojo.gfx.svg.Defines.nodeType); |
defs.setRawNode(node); |
s.rawNode.appendChild(node); |
dojo.byId(parentNode).appendChild(s.rawNode); |
return s; |
}; |
dojo.gfx.attachSurface = function (node) { |
var s = new dojo.gfx.Surface(); |
s.rawNode = node; |
return s; |
}; |
dojo.lang.extend(dojo.gfx.Group, dojo.gfx._creators); |
dojo.lang.extend(dojo.gfx.Surface, dojo.gfx._creators); |
delete dojo.gfx._creators; |
dojo.gfx.svg.Defines = function () { |
this.rawNode = null; |
}; |
dojo.lang.extend(dojo.gfx.svg.Defines, {setRawNode:function (rawNode) { |
this.rawNode = rawNode; |
}}); |
dojo.gfx.svg.Defines.nodeType = "defs"; |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/shape.js |
---|
New file |
0,0 → 1,176 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.shape"); |
dojo.require("dojo.lang.declare"); |
dojo.require("dojo.gfx.common"); |
dojo.declare("dojo.gfx.Shape", null, {initializer:function () { |
this.rawNode = null; |
this.shape = null; |
this.matrix = null; |
this.fillStyle = null; |
this.strokeStyle = null; |
this.bbox = null; |
this.parent = null; |
this.parentMatrix = null; |
}, getNode:function () { |
return this.rawNode; |
}, getShape:function () { |
return this.shape; |
}, getTransform:function () { |
return this.matrix; |
}, getFill:function () { |
return this.fillStyle; |
}, getStroke:function () { |
return this.strokeStyle; |
}, getParent:function () { |
return this.parent; |
}, getBoundingBox:function () { |
return this.bbox; |
}, getEventSource:function () { |
return this.rawNode; |
}, setShape:function (shape) { |
return this; |
}, setFill:function (fill) { |
return this; |
}, setStroke:function (stroke) { |
return this; |
}, moveToFront:function () { |
return this; |
}, moveToBack:function () { |
return this; |
}, setTransform:function (matrix) { |
this.matrix = dojo.gfx.matrix.clone(matrix ? dojo.gfx.matrix.normalize(matrix) : dojo.gfx.identity, true); |
return this._applyTransform(); |
}, applyRightTransform:function (matrix) { |
return matrix ? this.setTransform([this.matrix, matrix]) : this; |
}, applyLeftTransform:function (matrix) { |
return matrix ? this.setTransform([matrix, this.matrix]) : this; |
}, applyTransform:function (matrix) { |
return matrix ? this.setTransform([this.matrix, matrix]) : this; |
}, remove:function (silently) { |
if (this.parent) { |
this.parent.remove(this, silently); |
} |
return this; |
}, _setParent:function (parent, matrix) { |
this.parent = parent; |
return this._updateParentMatrix(matrix); |
}, _updateParentMatrix:function (matrix) { |
this.parentMatrix = matrix ? dojo.gfx.matrix.clone(matrix) : null; |
return this._applyTransform(); |
}, _getRealMatrix:function () { |
return this.parentMatrix ? new dojo.gfx.matrix.Matrix2D([this.parentMatrix, this.matrix]) : this.matrix; |
}}); |
dojo.declare("dojo.gfx.shape.VirtualGroup", dojo.gfx.Shape, {initializer:function () { |
this.children = []; |
}, add:function (shape) { |
var oldParent = shape.getParent(); |
if (oldParent) { |
oldParent.remove(shape, true); |
} |
this.children.push(shape); |
return shape._setParent(this, this._getRealMatrix()); |
}, remove:function (shape, silently) { |
for (var i = 0; i < this.children.length; ++i) { |
if (this.children[i] == shape) { |
if (silently) { |
} else { |
shape._setParent(null, null); |
} |
this.children.splice(i, 1); |
break; |
} |
} |
return this; |
}, _applyTransform:function () { |
var matrix = this._getRealMatrix(); |
for (var i = 0; i < this.children.length; ++i) { |
this.children[i]._updateParentMatrix(matrix); |
} |
return this; |
}}); |
dojo.declare("dojo.gfx.shape.Rect", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultRect, true); |
this.attach(rawNode); |
}, getBoundingBox:function () { |
return this.shape; |
}}); |
dojo.declare("dojo.gfx.shape.Ellipse", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultEllipse, true); |
this.attach(rawNode); |
}, getBoundingBox:function () { |
if (!this.bbox) { |
var shape = this.shape; |
this.bbox = {x:shape.cx - shape.rx, y:shape.cy - shape.ry, width:2 * shape.rx, height:2 * shape.ry}; |
} |
return this.bbox; |
}}); |
dojo.declare("dojo.gfx.shape.Circle", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultCircle, true); |
this.attach(rawNode); |
}, getBoundingBox:function () { |
if (!this.bbox) { |
var shape = this.shape; |
this.bbox = {x:shape.cx - shape.r, y:shape.cy - shape.r, width:2 * shape.r, height:2 * shape.r}; |
} |
return this.bbox; |
}}); |
dojo.declare("dojo.gfx.shape.Line", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultLine, true); |
this.attach(rawNode); |
}, getBoundingBox:function () { |
if (!this.bbox) { |
var shape = this.shape; |
this.bbox = {x:Math.min(shape.x1, shape.x2), y:Math.min(shape.y1, shape.y2), width:Math.abs(shape.x2 - shape.x1), height:Math.abs(shape.y2 - shape.y1)}; |
} |
return this.bbox; |
}}); |
dojo.declare("dojo.gfx.shape.Polyline", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true); |
this.attach(rawNode); |
}, getBoundingBox:function () { |
if (!this.bbox && this.shape.points.length) { |
var p = this.shape.points; |
var l = p.length; |
var t = p[0]; |
var bbox = {l:t.x, t:t.y, r:t.x, b:t.y}; |
for (var i = 1; i < l; ++i) { |
t = p[i]; |
if (bbox.l > t.x) { |
bbox.l = t.x; |
} |
if (bbox.r < t.x) { |
bbox.r = t.x; |
} |
if (bbox.t > t.y) { |
bbox.t = t.y; |
} |
if (bbox.b < t.y) { |
bbox.b = t.y; |
} |
} |
this.bbox = {x:bbox.l, y:bbox.t, width:bbox.r - bbox.l, height:bbox.b - bbox.t}; |
} |
return this.bbox; |
}}); |
dojo.declare("dojo.gfx.shape.Image", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true); |
this.attach(rawNode); |
}, getBoundingBox:function () { |
if (!this.bbox) { |
var shape = this.shape; |
this.bbox = {x:0, y:0, width:shape.width, height:shape.height}; |
} |
return this.bbox; |
}}); |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/color/hsl.js |
---|
New file |
0,0 → 1,118 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.color.hsl"); |
dojo.require("dojo.lang.array"); |
dojo.lang.extend(dojo.gfx.color.Color, {toHsl:function () { |
return dojo.gfx.color.rgb2hsl(this.toRgb()); |
}}); |
dojo.gfx.color.rgb2hsl = function (r, g, b) { |
if (dojo.lang.isArray(r)) { |
b = r[2] || 0; |
g = r[1] || 0; |
r = r[0] || 0; |
} |
r /= 255; |
g /= 255; |
b /= 255; |
var h = null; |
var s = null; |
var l = null; |
var min = Math.min(r, g, b); |
var max = Math.max(r, g, b); |
var delta = max - min; |
l = (min + max) / 2; |
s = 0; |
if ((l > 0) && (l < 1)) { |
s = delta / ((l < 0.5) ? (2 * l) : (2 - 2 * l)); |
} |
h = 0; |
if (delta > 0) { |
if ((max == r) && (max != g)) { |
h += (g - b) / delta; |
} |
if ((max == g) && (max != b)) { |
h += (2 + (b - r) / delta); |
} |
if ((max == b) && (max != r)) { |
h += (4 + (r - g) / delta); |
} |
h *= 60; |
} |
h = (h == 0) ? 360 : Math.ceil((h / 360) * 255); |
s = Math.ceil(s * 255); |
l = Math.ceil(l * 255); |
return [h, s, l]; |
}; |
dojo.gfx.color.hsl2rgb = function (h, s, l) { |
if (dojo.lang.isArray(h)) { |
l = h[2] || 0; |
s = h[1] || 0; |
h = h[0] || 0; |
} |
h = (h / 255) * 360; |
if (h == 360) { |
h = 0; |
} |
s = s / 255; |
l = l / 255; |
while (h < 0) { |
h += 360; |
} |
while (h > 360) { |
h -= 360; |
} |
var r, g, b; |
if (h < 120) { |
r = (120 - h) / 60; |
g = h / 60; |
b = 0; |
} else { |
if (h < 240) { |
r = 0; |
g = (240 - h) / 60; |
b = (h - 120) / 60; |
} else { |
r = (h - 240) / 60; |
g = 0; |
b = (360 - h) / 60; |
} |
} |
r = Math.min(r, 1); |
g = Math.min(g, 1); |
b = Math.min(b, 1); |
r = 2 * s * r + (1 - s); |
g = 2 * s * g + (1 - s); |
b = 2 * s * b + (1 - s); |
if (l < 0.5) { |
r = l * r; |
g = l * g; |
b = l * b; |
} else { |
r = (1 - l) * r + 2 * l - 1; |
g = (1 - l) * g + 2 * l - 1; |
b = (1 - l) * b + 2 * l - 1; |
} |
r = Math.ceil(r * 255); |
g = Math.ceil(g * 255); |
b = Math.ceil(b * 255); |
return [r, g, b]; |
}; |
dojo.gfx.color.hsl2hex = function (h, s, l) { |
var rgb = dojo.gfx.color.hsl2rgb(h, s, l); |
return dojo.gfx.color.rgb2hex(rgb[0], rgb[1], rgb[2]); |
}; |
dojo.gfx.color.hex2hsl = function (hex) { |
var rgb = dojo.gfx.color.hex2rgb(hex); |
return dojo.gfx.color.rgb2hsl(rgb[0], rgb[1], rgb[2]); |
}; |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/color/hsv.js |
---|
New file |
0,0 → 1,210 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.color.hsv"); |
dojo.require("dojo.lang.array"); |
dojo.require("dojo.math"); |
dojo.lang.extend(dojo.gfx.color.Color, {toHsv:function () { |
return dojo.gfx.color.rgb2hsv(this.toRgb()); |
}}); |
dojo.gfx.color.rgb2hsv = function (r, g, b, options) { |
if (dojo.lang.isArray(r)) { |
if (g) { |
options = g; |
} |
b = r[2] || 0; |
g = r[1] || 0; |
r = r[0] || 0; |
} |
var opt = {inputRange:(options && options.inputRange) ? options.inputRange : 255, outputRange:(options && options.outputRange) ? options.outputRange : [255, 255, 255]}; |
var h = null; |
var s = null; |
var v = null; |
switch (opt.inputRange) { |
case 1: |
r = (r * 255); |
g = (g * 255); |
b = (b * 255); |
break; |
case 100: |
r = (r / 100) * 255; |
g = (g / 100) * 255; |
b = (b / 100) * 255; |
break; |
default: |
break; |
} |
var min = Math.min(r, g, b); |
v = Math.max(r, g, b); |
var delta = v - min; |
s = (v == 0) ? 0 : delta / v; |
if (s == 0) { |
h = 0; |
} else { |
if (r == v) { |
h = 60 * (g - b) / delta; |
} else { |
if (g == v) { |
h = 120 + 60 * (b - r) / delta; |
} else { |
if (b == v) { |
h = 240 + 60 * (r - g) / delta; |
} |
} |
} |
if (h <= 0) { |
h += 360; |
} |
} |
switch (opt.outputRange[0]) { |
case 360: |
break; |
case 100: |
h = (h / 360) * 100; |
break; |
case 1: |
h = (h / 360); |
break; |
default: |
h = (h / 360) * 255; |
break; |
} |
switch (opt.outputRange[1]) { |
case 100: |
s = s * 100; |
case 1: |
break; |
default: |
s = s * 255; |
break; |
} |
switch (opt.outputRange[2]) { |
case 100: |
v = (v / 255) * 100; |
break; |
case 1: |
v = (v / 255); |
break; |
default: |
break; |
} |
h = dojo.math.round(h); |
s = dojo.math.round(s); |
v = dojo.math.round(v); |
return [h, s, v]; |
}; |
dojo.gfx.color.hsv2rgb = function (h, s, v, options) { |
if (dojo.lang.isArray(h)) { |
if (s) { |
options = s; |
} |
v = h[2] || 0; |
s = h[1] || 0; |
h = h[0] || 0; |
} |
var opt = {inputRange:(options && options.inputRange) ? options.inputRange : [255, 255, 255], outputRange:(options && options.outputRange) ? options.outputRange : 255}; |
switch (opt.inputRange[0]) { |
case 1: |
h = h * 360; |
break; |
case 100: |
h = (h / 100) * 360; |
break; |
case 360: |
h = h; |
break; |
default: |
h = (h / 255) * 360; |
} |
if (h == 360) { |
h = 0; |
} |
switch (opt.inputRange[1]) { |
case 100: |
s /= 100; |
break; |
case 255: |
s /= 255; |
} |
switch (opt.inputRange[2]) { |
case 100: |
v /= 100; |
break; |
case 255: |
v /= 255; |
} |
var r = null; |
var g = null; |
var b = null; |
if (s == 0) { |
r = v; |
g = v; |
b = v; |
} else { |
var hTemp = h / 60; |
var i = Math.floor(hTemp); |
var f = hTemp - i; |
var p = v * (1 - s); |
var q = v * (1 - (s * f)); |
var t = v * (1 - (s * (1 - f))); |
switch (i) { |
case 0: |
r = v; |
g = t; |
b = p; |
break; |
case 1: |
r = q; |
g = v; |
b = p; |
break; |
case 2: |
r = p; |
g = v; |
b = t; |
break; |
case 3: |
r = p; |
g = q; |
b = v; |
break; |
case 4: |
r = t; |
g = p; |
b = v; |
break; |
case 5: |
r = v; |
g = p; |
b = q; |
break; |
} |
} |
switch (opt.outputRange) { |
case 1: |
r = dojo.math.round(r, 2); |
g = dojo.math.round(g, 2); |
b = dojo.math.round(b, 2); |
break; |
case 100: |
r = Math.round(r * 100); |
g = Math.round(g * 100); |
b = Math.round(b * 100); |
break; |
default: |
r = Math.round(r * 255); |
g = Math.round(g * 255); |
b = Math.round(b * 255); |
} |
return [r, g, b]; |
}; |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/matrix.js |
---|
New file |
0,0 → 1,148 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.matrix"); |
dojo.require("dojo.lang.common"); |
dojo.require("dojo.math.*"); |
dojo.gfx.matrix.Matrix2D = function (arg) { |
if (arg) { |
if (arg instanceof Array) { |
if (arg.length > 0) { |
var m = dojo.gfx.matrix.normalize(arg[0]); |
for (var i = 1; i < arg.length; ++i) { |
var l = m; |
var r = dojo.gfx.matrix.normalize(arg[i]); |
m = new dojo.gfx.matrix.Matrix2D(); |
m.xx = l.xx * r.xx + l.xy * r.yx; |
m.xy = l.xx * r.xy + l.xy * r.yy; |
m.yx = l.yx * r.xx + l.yy * r.yx; |
m.yy = l.yx * r.xy + l.yy * r.yy; |
m.dx = l.xx * r.dx + l.xy * r.dy + l.dx; |
m.dy = l.yx * r.dx + l.yy * r.dy + l.dy; |
} |
dojo.mixin(this, m); |
} |
} else { |
dojo.mixin(this, arg); |
} |
} |
}; |
dojo.extend(dojo.gfx.matrix.Matrix2D, {xx:1, xy:0, yx:0, yy:1, dx:0, dy:0}); |
dojo.mixin(dojo.gfx.matrix, {identity:new dojo.gfx.matrix.Matrix2D(), flipX:new dojo.gfx.matrix.Matrix2D({xx:-1}), flipY:new dojo.gfx.matrix.Matrix2D({yy:-1}), flipXY:new dojo.gfx.matrix.Matrix2D({xx:-1, yy:-1}), translate:function (a, b) { |
if (arguments.length > 1) { |
return new dojo.gfx.matrix.Matrix2D({dx:a, dy:b}); |
} |
return new dojo.gfx.matrix.Matrix2D({dx:a.x, dy:a.y}); |
}, scale:function (a, b) { |
if (arguments.length > 1) { |
return new dojo.gfx.matrix.Matrix2D({xx:a, yy:b}); |
} |
if (typeof a == "number") { |
return new dojo.gfx.matrix.Matrix2D({xx:a, yy:a}); |
} |
return new dojo.gfx.matrix.Matrix2D({xx:a.x, yy:a.y}); |
}, rotate:function (angle) { |
var c = Math.cos(angle); |
var s = Math.sin(angle); |
return new dojo.gfx.matrix.Matrix2D({xx:c, xy:s, yx:-s, yy:c}); |
}, rotateg:function (degree) { |
return dojo.gfx.matrix.rotate(dojo.math.degToRad(degree)); |
}, skewX:function (angle) { |
return new dojo.gfx.matrix.Matrix2D({xy:Math.tan(angle)}); |
}, skewXg:function (degree) { |
return dojo.gfx.matrix.skewX(dojo.math.degToRad(degree)); |
}, skewY:function (angle) { |
return new dojo.gfx.matrix.Matrix2D({yx:-Math.tan(angle)}); |
}, skewYg:function (degree) { |
return dojo.gfx.matrix.skewY(dojo.math.degToRad(degree)); |
}, normalize:function (matrix) { |
return (matrix instanceof dojo.gfx.matrix.Matrix2D) ? matrix : new dojo.gfx.matrix.Matrix2D(matrix); |
}, clone:function (matrix) { |
var obj = new dojo.gfx.matrix.Matrix2D(); |
for (var i in matrix) { |
if (typeof (matrix[i]) == "number" && typeof (obj[i]) == "number" && obj[i] != matrix[i]) { |
obj[i] = matrix[i]; |
} |
} |
return obj; |
}, invert:function (matrix) { |
var m = dojo.gfx.matrix.normalize(matrix); |
var D = m.xx * m.yy - m.xy * m.yx; |
var M = new dojo.gfx.matrix.Matrix2D({xx:m.yy / D, xy:-m.xy / D, yx:-m.yx / D, yy:m.xx / D, dx:(m.yx * m.dy - m.yy * m.dx) / D, dy:(m.xy * m.dx - m.xx * m.dy) / D}); |
return M; |
}, _multiplyPoint:function (m, x, y) { |
return {x:m.xx * x + m.xy * y + m.dx, y:m.yx * x + m.yy * y + m.dy}; |
}, multiplyPoint:function (matrix, a, b) { |
var m = dojo.gfx.matrix.normalize(matrix); |
if (typeof a == "number" && typeof b == "number") { |
return dojo.gfx.matrix._multiplyPoint(m, a, b); |
} |
return dojo.gfx.matrix._multiplyPoint(m, a.x, a.y); |
}, multiply:function (matrix) { |
var m = dojo.gfx.matrix.normalize(matrix); |
for (var i = 1; i < arguments.length; ++i) { |
var l = m; |
var r = dojo.gfx.matrix.normalize(arguments[i]); |
m = new dojo.gfx.matrix.Matrix2D(); |
m.xx = l.xx * r.xx + l.xy * r.yx; |
m.xy = l.xx * r.xy + l.xy * r.yy; |
m.yx = l.yx * r.xx + l.yy * r.yx; |
m.yy = l.yx * r.xy + l.yy * r.yy; |
m.dx = l.xx * r.dx + l.xy * r.dy + l.dx; |
m.dy = l.yx * r.dx + l.yy * r.dy + l.dy; |
} |
return m; |
}, _sandwich:function (m, x, y) { |
return dojo.gfx.matrix.multiply(dojo.gfx.matrix.translate(x, y), m, dojo.gfx.matrix.translate(-x, -y)); |
}, scaleAt:function (a, b, c, d) { |
switch (arguments.length) { |
case 4: |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.scale(a, b), c, d); |
case 3: |
if (typeof c == "number") { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.scale(a), b, c); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.scale(a, b), c.x, c.y); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.scale(a), b.x, b.y); |
}, rotateAt:function (angle, a, b) { |
if (arguments.length > 2) { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.rotate(angle), a, b); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.rotate(angle), a.x, a.y); |
}, rotategAt:function (degree, a, b) { |
if (arguments.length > 2) { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.rotateg(degree), a, b); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.rotateg(degree), a.x, a.y); |
}, skewXAt:function (angle, a, b) { |
if (arguments.length > 2) { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewX(angle), a, b); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewX(angle), a.x, a.y); |
}, skewXgAt:function (degree, a, b) { |
if (arguments.length > 2) { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewXg(degree), a, b); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewXg(degree), a.x, a.y); |
}, skewYAt:function (angle, a, b) { |
if (arguments.length > 2) { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewY(angle), a, b); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewY(angle), a.x, a.y); |
}, skewYgAt:function (degree, a, b) { |
if (arguments.length > 2) { |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewYg(degree), a, b); |
} |
return dojo.gfx.matrix._sandwich(dojo.gfx.matrix.skewYg(degree), a.x, a.y); |
}}); |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/__package__.js |
---|
New file |
0,0 → 1,17 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.kwCompoundRequire({common:["dojo.gfx.color", "dojo.gfx.matrix", "dojo.gfx.common"]}); |
dojo.requireIf(dojo.render.svg.capable, "dojo.gfx.svg"); |
dojo.requireIf(dojo.render.vml.capable, "dojo.gfx.vml"); |
dojo.provide("dojo.gfx.*"); |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/common.js |
---|
New file |
0,0 → 1,63 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.common"); |
dojo.require("dojo.gfx.color"); |
dojo.require("dojo.lang.declare"); |
dojo.require("dojo.lang.extras"); |
dojo.require("dojo.dom"); |
dojo.lang.mixin(dojo.gfx, {defaultPath:{type:"path", path:""}, defaultPolyline:{type:"polyline", points:[]}, defaultRect:{type:"rect", x:0, y:0, width:100, height:100, r:0}, defaultEllipse:{type:"ellipse", cx:0, cy:0, rx:200, ry:100}, defaultCircle:{type:"circle", cx:0, cy:0, r:100}, defaultLine:{type:"line", x1:0, y1:0, x2:100, y2:100}, defaultImage:{type:"image", width:0, height:0, src:""}, defaultStroke:{color:"black", width:1, cap:"butt", join:4}, defaultLinearGradient:{type:"linear", x1:0, y1:0, x2:100, y2:100, colors:[{offset:0, color:"black"}, {offset:1, color:"white"}]}, defaultRadialGradient:{type:"radial", cx:0, cy:0, r:100, colors:[{offset:0, color:"black"}, {offset:1, color:"white"}]}, defaultPattern:{type:"pattern", x:0, y:0, width:0, height:0, src:""}, normalizeColor:function (color) { |
return (color instanceof dojo.gfx.color.Color) ? color : new dojo.gfx.color.Color(color); |
}, normalizeParameters:function (existed, update) { |
if (update) { |
var empty = {}; |
for (var x in existed) { |
if (x in update && !(x in empty)) { |
existed[x] = update[x]; |
} |
} |
} |
return existed; |
}, makeParameters:function (defaults, update) { |
if (!update) { |
return dojo.lang.shallowCopy(defaults, true); |
} |
var result = {}; |
for (var i in defaults) { |
if (!(i in result)) { |
result[i] = dojo.lang.shallowCopy((i in update) ? update[i] : defaults[i], true); |
} |
} |
return result; |
}, formatNumber:function (x, addSpace) { |
var val = x.toString(); |
if (val.indexOf("e") >= 0) { |
val = x.toFixed(4); |
} else { |
var point = val.indexOf("."); |
if (point >= 0 && val.length - point > 5) { |
val = x.toFixed(4); |
} |
} |
if (x < 0) { |
return val; |
} |
return addSpace ? " " + val : val; |
}, pathRegExp:/([A-Za-z]+)|(\d+(\.\d+)?)|(\.\d+)|(-\d+(\.\d+)?)|(-\.\d+)/g}); |
dojo.declare("dojo.gfx.Surface", null, {initializer:function () { |
this.rawNode = null; |
}, getEventSource:function () { |
return this.rawNode; |
}}); |
dojo.declare("dojo.gfx.Point", null, {}); |
dojo.declare("dojo.gfx.Rectangle", null, {}); |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/Colorspace.js |
---|
New file |
0,0 → 1,723 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.Colorspace"); |
dojo.require("dojo.lang.common"); |
dojo.require("dojo.math.matrix"); |
dojo.gfx.Colorspace = function () { |
this.whitePoint = "D65"; |
this.stdObserver = "10"; |
this.chromaticAdaptationAlg = "bradford"; |
this.RGBWorkingSpace = "s_rgb"; |
this.useApproxCIELabMapping = 1; |
this.chainMaps = {"RGB_to_xyY":["XYZ"], "xyY_to_RGB":["XYZ"], "RGB_to_Lab":["XYZ"], "Lab_to_RGB":["XYZ"], "RGB_to_LCHab":["XYZ", "Lab"], "LCHab_to_RGB":["Lab"], "xyY_to_Lab":["XYZ"], "Lab_to_xyY":["XYZ"], "XYZ_to_LCHab":["Lab"], "LCHab_to_XYZ":["Lab"], "xyY_to_LCHab":["XYZ", "Lab"], "LCHab_to_xyY":["Lab", "XYZ"], "RGB_to_Luv":["XYZ"], "Luv_to_RGB":["XYZ"], "xyY_to_Luv":["XYZ"], "Luv_to_xyY":["XYZ"], "Lab_to_Luv":["XYZ"], "Luv_to_Lab":["XYZ"], "LCHab_to_Luv":["Lab", "XYZ"], "Luv_to_LCHab":["XYZ", "Lab"], "RGB_to_LCHuv":["XYZ", "Luv"], "LCHuv_to_RGB":["Luv", "XYZ"], "XYZ_to_LCHuv":["Luv"], "LCHuv_to_XYZ":["Luv"], "xyY_to_LCHuv":["XYZ", "Luv"], "LCHuv_to_xyY":["Luv", "XYZ"], "Lab_to_LCHuv":["XYZ", "Luv"], "LCHuv_to_Lab":["Luv", "XYZ"], "LCHab_to_LCHuv":["Lab", "XYZ", "Luv"], "LCHuv_to_LCHab":["Luv", "XYZ", "Lab"], "XYZ_to_CMY":["RGB"], "CMY_to_XYZ":["RGB"], "xyY_to_CMY":["RGB"], "CMY_to_xyY":["RGB"], "Lab_to_CMY":["RGB"], "CMY_to_Lab":["RGB"], "LCHab_to_CMY":["RGB"], "CMY_to_LCHab":["RGB"], "Luv_to_CMY":["RGB"], "CMY_to_Luv":["RGB"], "LCHuv_to_CMY":["RGB"], "CMY_to_LCHuv":["RGB"], "XYZ_to_HSL":["RGB"], "HSL_to_XYZ":["RGB"], "xyY_to_HSL":["RGB"], "HSL_to_xyY":["RGB"], "Lab_to_HSL":["RGB"], "HSL_to_Lab":["RGB"], "LCHab_to_HSL":["RGB"], "HSL_to_LCHab":["RGB"], "Luv_to_HSL":["RGB"], "HSL_to_Luv":["RGB"], "LCHuv_to_HSL":["RGB"], "HSL_to_LCHuv":["RGB"], "CMY_to_HSL":["RGB"], "HSL_to_CMY":["RGB"], "CMYK_to_HSL":["RGB"], "HSL_to_CMYK":["RGB"], "XYZ_to_HSV":["RGB"], "HSV_to_XYZ":["RGB"], "xyY_to_HSV":["RGB"], "HSV_to_xyY":["RGB"], "Lab_to_HSV":["RGB"], "HSV_to_Lab":["RGB"], "LCHab_to_HSV":["RGB"], "HSV_to_LCHab":["RGB"], "Luv_to_HSV":["RGB"], "HSV_to_Luv":["RGB"], "LCHuv_to_HSV":["RGB"], "HSV_to_LCHuv":["RGB"], "CMY_to_HSV":["RGB"], "HSV_to_CMY":["RGB"], "CMYK_to_HSV":["RGB"], "HSV_to_CMYK":["RGB"], "HSL_to_HSV":["RGB"], "HSV_to_HSL":["RGB"], "XYZ_to_CMYK":["RGB"], "CMYK_to_XYZ":["RGB"], "xyY_to_CMYK":["RGB"], "CMYK_to_xyY":["RGB"], "Lab_to_CMYK":["RGB"], "CMYK_to_Lab":["RGB"], "LCHab_to_CMYK":["RGB"], "CMYK_to_LCHab":["RGB"], "Luv_to_CMYK":["RGB"], "CMYK_to_Luv":["RGB"], "LCHuv_to_CMYK":["RGB"], "CMYK_to_LCHuv":["RGB"]}; |
return this; |
}; |
dojo.gfx.Colorspace.prototype.convert = function (col, model_from, model_to) { |
var k = model_from + "_to_" + model_to; |
if (this[k]) { |
return this[k](col); |
} else { |
if (this.chainMaps[k]) { |
var cur = model_from; |
var models = this.chainMaps[k].concat(); |
models.push(model_to); |
for (var i = 0; i < models.length; i++) { |
col = this.convert(col, cur, models[i]); |
cur = models[i]; |
} |
return col; |
} else { |
dojo.debug("Can't convert from " + model_from + " to " + model_to); |
} |
} |
}; |
dojo.gfx.Colorspace.prototype.munge = function (keys, args) { |
if (dojo.lang.isArray(args[0])) { |
args = args[0]; |
} |
var out = new Array(); |
for (var i = 0; i < keys.length; i++) { |
out[keys.charAt(i)] = args[i]; |
} |
return out; |
}; |
dojo.gfx.Colorspace.prototype.getWhitePoint = function () { |
var x = 0; |
var y = 0; |
var t = 0; |
switch (this.stdObserver) { |
case "2": |
switch (this.whitePoint) { |
case "E": |
x = 1 / 3; |
y = 1 / 3; |
t = 5400; |
break; |
case "D50": |
x = 0.34567; |
y = 0.3585; |
t = 5000; |
break; |
case "D55": |
x = 0.33242; |
y = 0.34743; |
t = 5500; |
break; |
case "D65": |
x = 0.31271; |
y = 0.32902; |
t = 6500; |
break; |
case "D75": |
x = 0.29902; |
y = 0.31485; |
t = 7500; |
break; |
case "A": |
x = 0.44757; |
y = 0.40745; |
t = 2856; |
break; |
case "B": |
x = 0.34842; |
y = 0.35161; |
t = 4874; |
break; |
case "C": |
x = 0.31006; |
y = 0.31616; |
t = 6774; |
break; |
case "9300": |
x = 0.2848; |
y = 0.2932; |
t = 9300; |
break; |
case "F2": |
x = 0.37207; |
y = 0.37512; |
t = 4200; |
break; |
case "F7": |
x = 0.31285; |
y = 0.32918; |
t = 6500; |
break; |
case "F11": |
x = 0.38054; |
y = 0.37691; |
t = 4000; |
break; |
default: |
dojo.debug("White point " + this.whitePoint + " isn't defined for Std. Observer " + this.strObserver); |
} |
break; |
case "10": |
switch (this.whitePoint) { |
case "E": |
x = 1 / 3; |
y = 1 / 3; |
t = 5400; |
break; |
case "D50": |
x = 0.34773; |
y = 0.35952; |
t = 5000; |
break; |
case "D55": |
x = 0.33411; |
y = 0.34877; |
t = 5500; |
break; |
case "D65": |
x = 0.31382; |
y = 0.331; |
t = 6500; |
break; |
case "D75": |
x = 0.29968; |
y = 0.3174; |
t = 7500; |
break; |
case "A": |
x = 0.45117; |
y = 0.40594; |
t = 2856; |
break; |
case "B": |
x = 0.3498; |
y = 0.3527; |
t = 4874; |
break; |
case "C": |
x = 0.31039; |
y = 0.31905; |
t = 6774; |
break; |
case "F2": |
x = 0.37928; |
y = 0.36723; |
t = 4200; |
break; |
case "F7": |
x = 0.31565; |
y = 0.32951; |
t = 6500; |
break; |
case "F11": |
x = 0.38543; |
y = 0.3711; |
t = 4000; |
break; |
default: |
dojo.debug("White point " + this.whitePoint + " isn't defined for Std. Observer " + this.strObserver); |
} |
break; |
default: |
dojo.debug("Std. Observer " + this.strObserver + " isn't defined"); |
} |
var z = 1 - x - y; |
var wp = {"x":x, "y":y, "z":z, "t":t}; |
wp.Y = 1; |
var XYZ = this.xyY_to_XYZ([wp.x, wp.y, wp.Y]); |
wp.X = XYZ[0]; |
wp.Y = XYZ[1]; |
wp.Z = XYZ[2]; |
return wp; |
}; |
dojo.gfx.Colorspace.prototype.getPrimaries = function () { |
var m = []; |
switch (this.RGBWorkingSpace) { |
case "adobe_rgb_1998": |
m = [2.2, "D65", 0.64, 0.33, 0.297361, 0.21, 0.71, 0.627355, 0.15, 0.06, 0.075285]; |
break; |
case "apple_rgb": |
m = [1.8, "D65", 0.625, 0.34, 0.244634, 0.28, 0.595, 0.672034, 0.155, 0.07, 0.083332]; |
break; |
case "best_rgb": |
m = [2.2, "D50", 0.7347, 0.2653, 0.228457, 0.215, 0.775, 0.737352, 0.13, 0.035, 0.034191]; |
break; |
case "beta_rgb": |
m = [2.2, "D50", 0.6888, 0.3112, 0.303273, 0.1986, 0.7551, 0.663786, 0.1265, 0.0352, 0.032941]; |
break; |
case "bruce_rgb": |
m = [2.2, "D65", 0.64, 0.33, 0.240995, 0.28, 0.65, 0.683554, 0.15, 0.06, 0.075452]; |
break; |
case "cie_rgb": |
m = [2.2, "E", 0.735, 0.265, 0.176204, 0.274, 0.717, 0.812985, 0.167, 0.009, 0.010811]; |
break; |
case "color_match_rgb": |
m = [1.8, "D50", 0.63, 0.34, 0.274884, 0.295, 0.605, 0.658132, 0.15, 0.075, 0.066985]; |
break; |
case "don_rgb_4": |
m = [2.2, "D50", 0.696, 0.3, 0.27835, 0.215, 0.765, 0.68797, 0.13, 0.035, 0.03368]; |
break; |
case "eci_rgb": |
m = [1.8, "D50", 0.67, 0.33, 0.32025, 0.21, 0.71, 0.602071, 0.14, 0.08, 0.077679]; |
break; |
case "ekta_space_ps5": |
m = [2.2, "D50", 0.695, 0.305, 0.260629, 0.26, 0.7, 0.734946, 0.11, 0.005, 0.004425]; |
break; |
case "ntsc_rgb": |
m = [2.2, "C", 0.67, 0.33, 0.298839, 0.21, 0.71, 0.586811, 0.14, 0.08, 0.11435]; |
break; |
case "pal_secam_rgb": |
m = [2.2, "D65", 0.64, 0.33, 0.222021, 0.29, 0.6, 0.706645, 0.15, 0.06, 0.071334]; |
break; |
case "pro_photo_rgb": |
m = [1.8, "D50", 0.7347, 0.2653, 0.28804, 0.1596, 0.8404, 0.711874, 0.0366, 0.0001, 0.000086]; |
break; |
case "smpte-c_rgb": |
m = [2.2, "D65", 0.63, 0.34, 0.212395, 0.31, 0.595, 0.701049, 0.155, 0.07, 0.086556]; |
break; |
case "s_rgb": |
m = [2.2, "D65", 0.64, 0.33, 0.212656, 0.3, 0.6, 0.715158, 0.15, 0.06, 0.072186]; |
break; |
case "wide_gamut_rgb": |
m = [2.2, "D50", 0.735, 0.265, 0.258187, 0.115, 0.826, 0.724938, 0.157, 0.018, 0.016875]; |
break; |
default: |
dojo.debug("RGB working space " + this.RGBWorkingSpace + " isn't defined"); |
} |
var p = {name:this.RGBWorkingSpace, gamma:m[0], wp:m[1], xr:m[2], yr:m[3], Yr:m[4], xg:m[5], yg:m[6], Yg:m[7], xb:m[8], yb:m[9], Yb:m[10]}; |
if (p.wp != this.whitePoint) { |
var r = this.XYZ_to_xyY(this.chromaticAdaptation(this.xyY_to_XYZ([p.xr, p.yr, p.Yr]), p.wp, this.whitePoint)); |
var g = this.XYZ_to_xyY(this.chromaticAdaptation(this.xyY_to_XYZ([p.xg, p.yg, p.Yg]), p.wp, this.whitePoint)); |
var b = this.XYZ_to_xyY(this.chromaticAdaptation(this.xyY_to_XYZ([p.xb, p.yb, p.Yb]), p.wp, this.whitePoint)); |
p.xr = r[0]; |
p.yr = r[1]; |
p.Yr = r[2]; |
p.xg = g[0]; |
p.yg = g[1]; |
p.Yg = g[2]; |
p.xb = b[0]; |
p.yb = b[1]; |
p.Yb = b[2]; |
p.wp = this.whitePoint; |
} |
p.zr = 1 - p.xr - p.yr; |
p.zg = 1 - p.xg - p.yg; |
p.zb = 1 - p.xb - p.yb; |
return p; |
}; |
dojo.gfx.Colorspace.prototype.epsilon = function () { |
return this.useApproxCIELabMapping ? 0.008856 : 216 / 24289; |
}; |
dojo.gfx.Colorspace.prototype.kappa = function () { |
return this.useApproxCIELabMapping ? 903.3 : 24389 / 27; |
}; |
dojo.gfx.Colorspace.prototype.XYZ_to_xyY = function () { |
var src = this.munge("XYZ", arguments); |
var sum = src.X + src.Y + src.Z; |
if (sum == 0) { |
var wp = this.getWhitePoint(); |
var x = wp.x; |
var y = wp.y; |
} else { |
var x = src.X / sum; |
var y = src.Y / sum; |
} |
var Y = src.Y; |
return [x, y, Y]; |
}; |
dojo.gfx.Colorspace.prototype.xyY_to_XYZ = function () { |
var src = this.munge("xyY", arguments); |
if (src.y == 0) { |
var X = 0; |
var Y = 0; |
var Z = 0; |
} else { |
var X = (src.x * src.Y) / src.y; |
var Y = src.Y; |
var Z = ((1 - src.x - src.y) * src.Y) / src.y; |
} |
return [X, Y, Z]; |
}; |
dojo.gfx.Colorspace.prototype.RGB_to_XYZ = function () { |
var src = this.munge("RGB", arguments); |
var m = this.getRGB_XYZ_Matrix(); |
var pr = this.getPrimaries(); |
if (this.RGBWorkingSpace == "s_rgb") { |
var r = (src.R > 0.04045) ? Math.pow(((src.R + 0.055) / 1.055), 2.4) : src.R / 12.92; |
var g = (src.G > 0.04045) ? Math.pow(((src.G + 0.055) / 1.055), 2.4) : src.G / 12.92; |
var b = (src.B > 0.04045) ? Math.pow(((src.B + 0.055) / 1.055), 2.4) : src.B / 12.92; |
} else { |
var r = Math.pow(src.R, pr.gamma); |
var g = Math.pow(src.G, pr.gamma); |
var b = Math.pow(src.B, pr.gamma); |
} |
var XYZ = dojo.math.matrix.multiply([[r, g, b]], m); |
return [XYZ[0][0], XYZ[0][1], XYZ[0][2]]; |
}; |
dojo.gfx.Colorspace.prototype.XYZ_to_RGB = function () { |
var src = this.munge("XYZ", arguments); |
var mi = this.getXYZ_RGB_Matrix(); |
var pr = this.getPrimaries(); |
var rgb = dojo.math.matrix.multiply([[src.X, src.Y, src.Z]], mi); |
var r = rgb[0][0]; |
var g = rgb[0][1]; |
var b = rgb[0][2]; |
if (this.RGBWorkingSpace == "s_rgb") { |
var R = (r > 0.0031308) ? (1.055 * Math.pow(r, 1 / 2.4)) - 0.055 : 12.92 * r; |
var G = (g > 0.0031308) ? (1.055 * Math.pow(g, 1 / 2.4)) - 0.055 : 12.92 * g; |
var B = (b > 0.0031308) ? (1.055 * Math.pow(b, 1 / 2.4)) - 0.055 : 12.92 * b; |
} else { |
var R = Math.pow(r, 1 / pr.gamma); |
var G = Math.pow(g, 1 / pr.gamma); |
var B = Math.pow(b, 1 / pr.gamma); |
} |
return [R, G, B]; |
}; |
dojo.gfx.Colorspace.prototype.XYZ_to_Lab = function () { |
var src = this.munge("XYZ", arguments); |
var wp = this.getWhitePoint(); |
var xr = src.X / wp.X; |
var yr = src.Y / wp.Y; |
var zr = src.Z / wp.Z; |
var fx = (xr > this.epsilon()) ? Math.pow(xr, 1 / 3) : (this.kappa() * xr + 16) / 116; |
var fy = (yr > this.epsilon()) ? Math.pow(yr, 1 / 3) : (this.kappa() * yr + 16) / 116; |
var fz = (zr > this.epsilon()) ? Math.pow(zr, 1 / 3) : (this.kappa() * zr + 16) / 116; |
var L = 116 * fy - 16; |
var a = 500 * (fx - fy); |
var b = 200 * (fy - fz); |
return [L, a, b]; |
}; |
dojo.gfx.Colorspace.prototype.Lab_to_XYZ = function () { |
var src = this.munge("Lab", arguments); |
var wp = this.getWhitePoint(); |
var yr = (src.L > (this.kappa() * this.epsilon())) ? Math.pow((src.L + 16) / 116, 3) : src.L / this.kappa(); |
var fy = (yr > this.epsilon()) ? (src.L + 16) / 116 : (this.kappa() * yr + 16) / 116; |
var fx = (src.a / 500) + fy; |
var fz = fy - (src.b / 200); |
var fxcube = Math.pow(fx, 3); |
var fzcube = Math.pow(fz, 3); |
var xr = (fxcube > this.epsilon()) ? fxcube : (116 * fx - 16) / this.kappa(); |
var zr = (fzcube > this.epsilon()) ? fzcube : (116 * fz - 16) / this.kappa(); |
var X = xr * wp.X; |
var Y = yr * wp.Y; |
var Z = zr * wp.Z; |
return [X, Y, Z]; |
}; |
dojo.gfx.Colorspace.prototype.Lab_to_LCHab = function () { |
var src = this.munge("Lab", arguments); |
var L = src.L; |
var C = Math.pow(src.a * src.a + src.b * src.b, 0.5); |
var H = Math.atan2(src.b, src.a) * (180 / Math.PI); |
if (H < 0) { |
H += 360; |
} |
if (H > 360) { |
H -= 360; |
} |
return [L, C, H]; |
}; |
dojo.gfx.Colorspace.prototype.LCHab_to_Lab = function () { |
var src = this.munge("LCH", arguments); |
var H_rad = src.H * (Math.PI / 180); |
var L = src.L; |
var a = src.C / Math.pow(Math.pow(Math.tan(H_rad), 2) + 1, 0.5); |
if ((90 < src.H) && (src.H < 270)) { |
a = -a; |
} |
var b = Math.pow(Math.pow(src.C, 2) - Math.pow(a, 2), 0.5); |
if (src.H > 180) { |
b = -b; |
} |
return [L, a, b]; |
}; |
dojo.gfx.Colorspace.prototype.chromaticAdaptation = function (col, src_w, dst_w) { |
col = this.munge("XYZ", [col]); |
var old_wp = this.whitePoint; |
this.whitePoint = src_w; |
var wp_src = this.getWhitePoint(); |
this.whitePoint = dst_w; |
var wp_dst = this.getWhitePoint(); |
this.whitePoint = old_wp; |
switch (this.chromaticAdaptationAlg) { |
case "xyz_scaling": |
var ma = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; |
var mai = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; |
break; |
case "bradford": |
var ma = [[0.8951, -0.7502, 0.0389], [0.2664, 1.7135, -0.0685], [-0.1614, 0.0367, 1.0296]]; |
var mai = [[0.986993, 0.432305, -0.008529], [-0.147054, 0.51836, 0.040043], [0.159963, 0.049291, 0.968487]]; |
break; |
case "von_kries": |
var ma = [[0.40024, -0.2263, 0], [0.7076, 1.16532, 0], [-0.08081, 0.0457, 0.91822]]; |
var mai = [[1.859936, 0.361191, 0], [-1.129382, 0.638812, 0], [0.219897, -0.000006, 1.089064]]; |
break; |
default: |
dojo.debug("The " + this.chromaticAdaptationAlg + " chromatic adaptation algorithm matricies are not defined"); |
} |
var domain_src = dojo.math.matrix.multiply([[wp_src.x, wp_src.y, wp_src.z]], ma); |
var domain_dst = dojo.math.matrix.multiply([[wp_dst.x, wp_dst.y, wp_dst.z]], ma); |
var centre = [[domain_dst[0][0] / domain_src[0][0], 0, 0], [0, domain_dst[0][1] / domain_src[0][1], 0], [0, 0, domain_dst[0][2] / domain_src[0][2]]]; |
var m = dojo.math.matrix.multiply(dojo.math.matrix.multiply(ma, centre), mai); |
var dst = dojo.math.matrix.multiply([[col.X, col.Y, col.Z]], m); |
return dst[0]; |
}; |
dojo.gfx.Colorspace.prototype.getRGB_XYZ_Matrix = function () { |
var wp = this.getWhitePoint(); |
var pr = this.getPrimaries(); |
var Xr = pr.xr / pr.yr; |
var Yr = 1; |
var Zr = (1 - pr.xr - pr.yr) / pr.yr; |
var Xg = pr.xg / pr.yg; |
var Yg = 1; |
var Zg = (1 - pr.xg - pr.yg) / pr.yg; |
var Xb = pr.xb / pr.yb; |
var Yb = 1; |
var Zb = (1 - pr.xb - pr.yb) / pr.yb; |
var m1 = [[Xr, Yr, Zr], [Xg, Yg, Zg], [Xb, Yb, Zb]]; |
var m2 = [[wp.X, wp.Y, wp.Z]]; |
var sm = dojo.math.matrix.multiply(m2, dojo.math.matrix.inverse(m1)); |
var Sr = sm[0][0]; |
var Sg = sm[0][1]; |
var Sb = sm[0][2]; |
var m4 = [[Sr * Xr, Sr * Yr, Sr * Zr], [Sg * Xg, Sg * Yg, Sg * Zg], [Sb * Xb, Sb * Yb, Sb * Zb]]; |
return m4; |
}; |
dojo.gfx.Colorspace.prototype.getXYZ_RGB_Matrix = function () { |
var m = this.getRGB_XYZ_Matrix(); |
return dojo.math.matrix.inverse(m); |
}; |
dojo.gfx.Colorspace.prototype.XYZ_to_Luv = function () { |
var src = this.munge("XYZ", arguments); |
var wp = this.getWhitePoint(); |
var ud = (4 * src.X) / (src.X + 15 * src.Y + 3 * src.Z); |
var vd = (9 * src.Y) / (src.X + 15 * src.Y + 3 * src.Z); |
var udr = (4 * wp.X) / (wp.X + 15 * wp.Y + 3 * wp.Z); |
var vdr = (9 * wp.Y) / (wp.X + 15 * wp.Y + 3 * wp.Z); |
var yr = src.Y / wp.Y; |
var L = (yr > this.epsilon()) ? 116 * Math.pow(yr, 1 / 3) - 16 : this.kappa() * yr; |
var u = 13 * L * (ud - udr); |
var v = 13 * L * (vd - vdr); |
return [L, u, v]; |
}; |
dojo.gfx.Colorspace.prototype.Luv_to_XYZ = function () { |
var src = this.munge("Luv", arguments); |
var wp = this.getWhitePoint(); |
var uz = (4 * wp.X) / (wp.X + 15 * wp.Y + 3 * wp.Z); |
var vz = (9 * wp.Y) / (wp.X + 15 * wp.Y + 3 * wp.Z); |
var Y = (src.L > this.kappa() * this.epsilon()) ? Math.pow((src.L + 16) / 116, 3) : src.L / this.kappa(); |
var a = (1 / 3) * (((52 * src.L) / (src.u + 13 * src.L * uz)) - 1); |
var b = -5 * Y; |
var c = -(1 / 3); |
var d = Y * (((39 * src.L) / (src.v + 13 * src.L * vz)) - 5); |
var X = (d - b) / (a - c); |
var Z = X * a + b; |
return [X, Y, Z]; |
}; |
dojo.gfx.Colorspace.prototype.Luv_to_LCHuv = function () { |
var src = this.munge("Luv", arguments); |
var L = src.L; |
var C = Math.pow(src.u * src.u + src.v * src.v, 0.5); |
var H = Math.atan2(src.v, src.u) * (180 / Math.PI); |
if (H < 0) { |
H += 360; |
} |
if (H > 360) { |
H -= 360; |
} |
return [L, C, H]; |
}; |
dojo.gfx.Colorspace.prototype.LCHuv_to_Luv = function () { |
var src = this.munge("LCH", arguments); |
var H_rad = src.H * (Math.PI / 180); |
var L = src.L; |
var u = src.C / Math.pow(Math.pow(Math.tan(H_rad), 2) + 1, 0.5); |
var v = Math.pow(src.C * src.C - u * u, 0.5); |
if ((90 < src.H) && (src.H < 270)) { |
u *= -1; |
} |
if (src.H > 180) { |
v *= -1; |
} |
return [L, u, v]; |
}; |
dojo.gfx.Colorspace.colorTemp_to_whitePoint = function (T) { |
if (T < 4000) { |
dojo.debug("Can't find a white point for temperatures under 4000K"); |
return [0, 0]; |
} |
if (T > 25000) { |
dojo.debug("Can't find a white point for temperatures over 25000K"); |
return [0, 0]; |
} |
var T1 = T; |
var T2 = T * T; |
var T3 = T2 * T; |
var ten9 = Math.pow(10, 9); |
var ten6 = Math.pow(10, 6); |
var ten3 = Math.pow(10, 3); |
if (T <= 7000) { |
var x = (-4.607 * ten9 / T3) + (2.9678 * ten6 / T2) + (0.09911 * ten3 / T) + 0.244063; |
} else { |
var x = (-2.0064 * ten9 / T3) + (1.9018 * ten6 / T2) + (0.24748 * ten3 / T) + 0.23704; |
} |
var y = -3 * x * x + 2.87 * x - 0.275; |
return [x, y]; |
}; |
dojo.gfx.Colorspace.prototype.RGB_to_CMY = function () { |
var src = this.munge("RGB", arguments); |
var C = 1 - src.R; |
var M = 1 - src.G; |
var Y = 1 - src.B; |
return [C, M, Y]; |
}; |
dojo.gfx.Colorspace.prototype.CMY_to_RGB = function () { |
var src = this.munge("CMY", arguments); |
var R = 1 - src.C; |
var G = 1 - src.M; |
var B = 1 - src.Y; |
return [R, G, B]; |
}; |
dojo.gfx.Colorspace.prototype.RGB_to_CMYK = function () { |
var src = this.munge("RGB", arguments); |
var K = Math.min(1 - src.R, 1 - src.G, 1 - src.B); |
var C = (1 - src.R - K) / (1 - K); |
var M = (1 - src.G - K) / (1 - K); |
var Y = (1 - src.B - K) / (1 - K); |
return [C, M, Y, K]; |
}; |
dojo.gfx.Colorspace.prototype.CMYK_to_RGB = function () { |
var src = this.munge("CMYK", arguments); |
var R = 1 - Math.min(1, src.C * (1 - src.K) + src.K); |
var G = 1 - Math.min(1, src.M * (1 - src.K) + src.K); |
var B = 1 - Math.min(1, src.Y * (1 - src.K) + src.K); |
return [R, G, B]; |
}; |
dojo.gfx.Colorspace.prototype.CMY_to_CMYK = function () { |
var src = this.munge("CMY", arguments); |
var K = Math.min(src.C, src.M, src.Y); |
var C = (src.C - K) / (1 - K); |
var M = (src.M - K) / (1 - K); |
var Y = (src.Y - K) / (1 - K); |
return [C, M, Y, K]; |
}; |
dojo.gfx.Colorspace.prototype.CMYK_to_CMY = function () { |
var src = this.munge("CMYK", arguments); |
var C = Math.min(1, src.C * (1 - src.K) + src.K); |
var M = Math.min(1, src.M * (1 - src.K) + src.K); |
var Y = Math.min(1, src.Y * (1 - src.K) + src.K); |
return [C, M, Y]; |
}; |
dojo.gfx.Colorspace.prototype.RGB_to_HSV = function () { |
var src = this.munge("RGB", arguments); |
var min = Math.min(src.R, src.G, src.B); |
var V = Math.max(src.R, src.G, src.B); |
var delta = V - min; |
var H = null; |
var S = (V == 0) ? 0 : delta / V; |
if (S == 0) { |
H = 0; |
} else { |
if (src.R == V) { |
H = 60 * (src.G - src.B) / delta; |
} else { |
if (src.G == V) { |
H = 120 + 60 * (src.B - src.R) / delta; |
} else { |
if (src.B == V) { |
H = 240 + 60 * (src.R - src.G) / delta; |
} |
} |
} |
if (H < 0) { |
H += 360; |
} |
} |
H = (H == 0) ? 360 : H; |
return [H, S, V]; |
}; |
dojo.gfx.Colorspace.prototype.HSV_to_RGB = function () { |
var src = this.munge("HSV", arguments); |
if (src.H == 360) { |
src.H = 0; |
} |
var r = null; |
var g = null; |
var b = null; |
if (src.S == 0) { |
var R = src.V; |
var G = src.V; |
var B = src.V; |
} else { |
var hTemp = src.H / 60; |
var i = Math.floor(hTemp); |
var f = hTemp - i; |
var p = src.V * (1 - src.S); |
var q = src.V * (1 - (src.S * f)); |
var t = src.V * (1 - (src.S * (1 - f))); |
switch (i) { |
case 0: |
R = src.V; |
G = t; |
B = p; |
break; |
case 1: |
R = q; |
G = src.V; |
B = p; |
break; |
case 2: |
R = p; |
G = src.V; |
B = t; |
break; |
case 3: |
R = p; |
G = q; |
B = src.V; |
break; |
case 4: |
R = t; |
G = p; |
B = src.V; |
break; |
case 5: |
R = src.V; |
G = p; |
B = q; |
break; |
} |
} |
return [R, G, B]; |
}; |
dojo.gfx.Colorspace.prototype.RGB_to_HSL = function () { |
var src = this.munge("RGB", arguments); |
var min = Math.min(src.R, src.G, src.B); |
var max = Math.max(src.R, src.G, src.B); |
var delta = max - min; |
var H = 0; |
var S = 0; |
var L = (min + max) / 2; |
if ((L > 0) && (L < 1)) { |
S = delta / ((L < 0.5) ? (2 * L) : (2 - 2 * L)); |
} |
if (delta > 0) { |
if ((max == src.R) && (max != src.G)) { |
H += (src.G - src.B) / delta; |
} |
if ((max == src.G) && (max != src.B)) { |
H += (2 + (src.B - src.R) / delta); |
} |
if ((max == src.B) && (max != src.R)) { |
H += (4 + (src.R - src.G) / delta); |
} |
H *= 60; |
} |
H = (H == 0) ? 360 : H; |
return [H, S, L]; |
}; |
dojo.gfx.Colorspace.prototype.HSL_to_RGB = function () { |
var src = this.munge("HSL", arguments); |
while (src.H < 0) { |
src.H += 360; |
} |
while (src.H >= 360) { |
src.H -= 360; |
} |
var R = 0; |
var G = 0; |
var B = 0; |
if (src.H < 120) { |
R = (120 - src.H) / 60; |
G = src.H / 60; |
B = 0; |
} else { |
if (src.H < 240) { |
R = 0; |
G = (240 - src.H) / 60; |
B = (src.H - 120) / 60; |
} else { |
R = (src.H - 240) / 60; |
G = 0; |
B = (360 - src.H) / 60; |
} |
} |
R = 2 * src.S * Math.min(R, 1) + (1 - src.S); |
G = 2 * src.S * Math.min(G, 1) + (1 - src.S); |
B = 2 * src.S * Math.min(B, 1) + (1 - src.S); |
if (src.L < 0.5) { |
R = src.L * R; |
G = src.L * G; |
B = src.L * B; |
} else { |
R = (1 - src.L) * R + 2 * src.L - 1; |
G = (1 - src.L) * G + 2 * src.L - 1; |
B = (1 - src.L) * B + 2 * src.L - 1; |
} |
return [R, G, B]; |
}; |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/path.js |
---|
New file |
0,0 → 1,268 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.path"); |
dojo.require("dojo.math"); |
dojo.require("dojo.gfx.shape"); |
dojo.declare("dojo.gfx.path.Path", dojo.gfx.Shape, {initializer:function (rawNode) { |
this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPath, true); |
this.segments = []; |
this.absolute = true; |
this.last = {}; |
this.attach(rawNode); |
}, setAbsoluteMode:function (mode) { |
this.absolute = typeof (mode) == "string" ? (mode == "absolute") : mode; |
return this; |
}, getAbsoluteMode:function () { |
return this.absolute; |
}, getBoundingBox:function () { |
return "l" in this.bbox ? {x:this.bbox.l, y:this.bbox.t, width:this.bbox.r - this.bbox.l, height:this.bbox.b - this.bbox.t} : null; |
}, getLastPosition:function () { |
return "x" in this.last ? this.last : null; |
}, _updateBBox:function (x, y) { |
if ("l" in this.bbox) { |
if (this.bbox.l > x) { |
this.bbox.l = x; |
} |
if (this.bbox.r < x) { |
this.bbox.r = x; |
} |
if (this.bbox.t > y) { |
this.bbox.t = y; |
} |
if (this.bbox.b < y) { |
this.bbox.b = y; |
} |
} else { |
this.bbox = {l:x, b:y, r:x, t:y}; |
} |
}, _updateWithSegment:function (segment) { |
var n = segment.args; |
var l = n.length; |
switch (segment.action) { |
case "M": |
case "L": |
case "C": |
case "S": |
case "Q": |
case "T": |
for (var i = 0; i < l; i += 2) { |
this._updateBBox(this.bbox, n[i], n[i + 1]); |
} |
this.last.x = n[l - 2]; |
this.last.y = n[l - 1]; |
this.absolute = true; |
break; |
case "H": |
for (var i = 0; i < l; ++i) { |
this._updateBBox(this.bbox, n[i], this.last.y); |
} |
this.last.x = n[l - 1]; |
this.absolute = true; |
break; |
case "V": |
for (var i = 0; i < l; ++i) { |
this._updateBBox(this.bbox, this.last.x, n[i]); |
} |
this.last.y = n[l - 1]; |
this.absolute = true; |
break; |
case "m": |
var start = 0; |
if (!("x" in this.last)) { |
this._updateBBox(this.bbox, this.last.x = n[0], this.last.y = n[1]); |
start = 2; |
} |
for (var i = start; i < l; i += 2) { |
this._updateBBox(this.bbox, this.last.x += n[i], this.last.y += n[i + 1]); |
} |
this.absolute = false; |
break; |
case "l": |
case "t": |
for (var i = 0; i < l; i += 2) { |
this._updateBBox(this.bbox, this.last.x += n[i], this.last.y += n[i + 1]); |
} |
this.absolute = false; |
break; |
case "h": |
for (var i = 0; i < l; ++i) { |
this._updateBBox(this.bbox, this.last.x += n[i], this.last.y); |
} |
this.absolute = false; |
break; |
case "v": |
for (var i = 0; i < l; ++i) { |
this._updateBBox(this.bbox, this.last.x, this.last.y += n[i]); |
} |
this.absolute = false; |
break; |
case "c": |
for (var i = 0; i < l; i += 6) { |
this._updateBBox(this.bbox, this.last.x + n[i], this.last.y + n[i + 1]); |
this._updateBBox(this.bbox, this.last.x + n[i + 2], this.last.y + n[i + 3]); |
this._updateBBox(this.bbox, this.last.x += n[i + 4], this.last.y += n[i + 5]); |
} |
this.absolute = false; |
break; |
case "s": |
case "q": |
for (var i = 0; i < l; i += 4) { |
this._updateBBox(this.bbox, this.last.x + n[i], this.last.y + n[i + 1]); |
this._updateBBox(this.bbox, this.last.x += n[i + 2], this.last.y += n[i + 3]); |
} |
this.absolute = false; |
break; |
case "A": |
for (var i = 0; i < l; i += 7) { |
this._updateBBox(this.bbox, n[i + 5], n[i + 6]); |
} |
this.last.x = n[l - 2]; |
this.last.y = n[l - 1]; |
this.absolute = true; |
break; |
case "a": |
for (var i = 0; i < l; i += 7) { |
this._updateBBox(this.bbox, this.last.x += n[i + 5], this.last.y += n[i + 6]); |
} |
this.absolute = false; |
break; |
} |
var path = [segment.action]; |
for (var i = 0; i < l; ++i) { |
path.push(dojo.gfx.formatNumber(n[i], true)); |
} |
if (typeof (this.shape.path) == "string") { |
this.shape.path += path.join(""); |
} else { |
this.shape.path = this.shape.path.concat(path); |
} |
}, _validSegments:{m:2, l:2, h:1, v:1, c:6, s:4, q:4, t:2, a:7, z:0}, _pushSegment:function (action, args) { |
var group = this._validSegments[action.toLowerCase()]; |
if (typeof (group) == "number") { |
if (group) { |
if (args.length >= group) { |
var segment = {action:action, args:args.slice(0, args.length - args.length % group)}; |
this.segments.push(segment); |
this._updateWithSegment(segment); |
} |
} else { |
var segment = {action:action, args:[]}; |
this.segments.push(segment); |
this._updateWithSegment(segment); |
} |
} |
}, _collectArgs:function (array, args) { |
for (var i = 0; i < args.length; ++i) { |
var t = args[i]; |
if (typeof (t) == "boolean") { |
array.push(t ? 1 : 0); |
} else { |
if (typeof (t) == "number") { |
array.push(t); |
} else { |
if (t instanceof Array) { |
this._collectArgs(array, t); |
} else { |
if ("x" in t && "y" in t) { |
array.push(t.x); |
array.push(t.y); |
} |
} |
} |
} |
} |
}, moveTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "M" : "m", args); |
return this; |
}, lineTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "L" : "l", args); |
return this; |
}, hLineTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "H" : "h", args); |
return this; |
}, vLineTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "V" : "v", args); |
return this; |
}, curveTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "C" : "c", args); |
return this; |
}, smoothCurveTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "S" : "s", args); |
return this; |
}, qCurveTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "Q" : "q", args); |
return this; |
}, qSmoothCurveTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
this._pushSegment(this.absolute ? "T" : "t", args); |
return this; |
}, arcTo:function () { |
var args = []; |
this._collectArgs(args, arguments); |
for (var i = 2; i < args.length; i += 7) { |
args[i] = -args[i]; |
} |
this._pushSegment(this.absolute ? "A" : "a", args); |
return this; |
}, closePath:function () { |
this._pushSegment("Z", []); |
return this; |
}, _setPath:function (path) { |
var p = path.match(dojo.gfx.pathRegExp); |
this.segments = []; |
this.absolute = true; |
this.bbox = {}; |
this.last = {}; |
if (!p) { |
return; |
} |
var action = ""; |
var args = []; |
for (var i = 0; i < p.length; ++i) { |
var t = p[i]; |
var x = parseFloat(t); |
if (isNaN(x)) { |
if (action) { |
this._pushSegment(action, args); |
} |
args = []; |
action = t; |
} else { |
args.push(x); |
} |
} |
this._pushSegment(action, args); |
}, setShape:function (newShape) { |
this.shape = dojo.gfx.makeParameters(this.shape, typeof (newShape) == "string" ? {path:newShape} : newShape); |
var path = this.shape.path; |
this.shape.path = []; |
this._setPath(path); |
this.shape.path = this.shape.path.join(""); |
return this; |
}, _2PI:Math.PI * 2}); |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/color.js |
---|
New file |
0,0 → 1,150 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.color"); |
dojo.require("dojo.lang.common"); |
dojo.require("dojo.lang.array"); |
dojo.gfx.color.Color = function (r, g, b, a) { |
if (dojo.lang.isArray(r)) { |
this.r = r[0]; |
this.g = r[1]; |
this.b = r[2]; |
this.a = r[3] || 1; |
} else { |
if (dojo.lang.isString(r)) { |
var rgb = dojo.gfx.color.extractRGB(r); |
this.r = rgb[0]; |
this.g = rgb[1]; |
this.b = rgb[2]; |
this.a = g || 1; |
} else { |
if (r instanceof dojo.gfx.color.Color) { |
this.r = r.r; |
this.b = r.b; |
this.g = r.g; |
this.a = r.a; |
} else { |
this.r = r; |
this.g = g; |
this.b = b; |
this.a = a; |
} |
} |
} |
}; |
dojo.gfx.color.Color.fromArray = function (arr) { |
return new dojo.gfx.color.Color(arr[0], arr[1], arr[2], arr[3]); |
}; |
dojo.extend(dojo.gfx.color.Color, {toRgb:function (includeAlpha) { |
if (includeAlpha) { |
return this.toRgba(); |
} else { |
return [this.r, this.g, this.b]; |
} |
}, toRgba:function () { |
return [this.r, this.g, this.b, this.a]; |
}, toHex:function () { |
return dojo.gfx.color.rgb2hex(this.toRgb()); |
}, toCss:function () { |
return "rgb(" + this.toRgb().join() + ")"; |
}, toString:function () { |
return this.toHex(); |
}, blend:function (color, weight) { |
var rgb = null; |
if (dojo.lang.isArray(color)) { |
rgb = color; |
} else { |
if (color instanceof dojo.gfx.color.Color) { |
rgb = color.toRgb(); |
} else { |
rgb = new dojo.gfx.color.Color(color).toRgb(); |
} |
} |
return dojo.gfx.color.blend(this.toRgb(), rgb, weight); |
}}); |
dojo.gfx.color.named = {white:[255, 255, 255], black:[0, 0, 0], red:[255, 0, 0], green:[0, 255, 0], lime:[0, 255, 0], blue:[0, 0, 255], navy:[0, 0, 128], gray:[128, 128, 128], silver:[192, 192, 192]}; |
dojo.gfx.color.blend = function (a, b, weight) { |
if (typeof a == "string") { |
return dojo.gfx.color.blendHex(a, b, weight); |
} |
if (!weight) { |
weight = 0; |
} |
weight = Math.min(Math.max(-1, weight), 1); |
weight = ((weight + 1) / 2); |
var c = []; |
for (var x = 0; x < 3; x++) { |
c[x] = parseInt(b[x] + ((a[x] - b[x]) * weight)); |
} |
return c; |
}; |
dojo.gfx.color.blendHex = function (a, b, weight) { |
return dojo.gfx.color.rgb2hex(dojo.gfx.color.blend(dojo.gfx.color.hex2rgb(a), dojo.gfx.color.hex2rgb(b), weight)); |
}; |
dojo.gfx.color.extractRGB = function (color) { |
var hex = "0123456789abcdef"; |
color = color.toLowerCase(); |
if (color.indexOf("rgb") == 0) { |
var matches = color.match(/rgba*\((\d+), *(\d+), *(\d+)/i); |
var ret = matches.splice(1, 3); |
return ret; |
} else { |
var colors = dojo.gfx.color.hex2rgb(color); |
if (colors) { |
return colors; |
} else { |
return dojo.gfx.color.named[color] || [255, 255, 255]; |
} |
} |
}; |
dojo.gfx.color.hex2rgb = function (hex) { |
var hexNum = "0123456789ABCDEF"; |
var rgb = new Array(3); |
if (hex.indexOf("#") == 0) { |
hex = hex.substring(1); |
} |
hex = hex.toUpperCase(); |
if (hex.replace(new RegExp("[" + hexNum + "]", "g"), "") != "") { |
return null; |
} |
if (hex.length == 3) { |
rgb[0] = hex.charAt(0) + hex.charAt(0); |
rgb[1] = hex.charAt(1) + hex.charAt(1); |
rgb[2] = hex.charAt(2) + hex.charAt(2); |
} else { |
rgb[0] = hex.substring(0, 2); |
rgb[1] = hex.substring(2, 4); |
rgb[2] = hex.substring(4); |
} |
for (var i = 0; i < rgb.length; i++) { |
rgb[i] = hexNum.indexOf(rgb[i].charAt(0)) * 16 + hexNum.indexOf(rgb[i].charAt(1)); |
} |
return rgb; |
}; |
dojo.gfx.color.rgb2hex = function (r, g, b) { |
if (dojo.lang.isArray(r)) { |
g = r[1] || 0; |
b = r[2] || 0; |
r = r[0] || 0; |
} |
var ret = dojo.lang.map([r, g, b], function (x) { |
x = new Number(x); |
var s = x.toString(16); |
while (s.length < 2) { |
s = "0" + s; |
} |
return s; |
}); |
ret.unshift("#"); |
return ret.join(""); |
}; |
/tags/v5.0-ouadji/api/js/dojo/src/gfx/vml.js |
---|
New file |
0,0 → 1,1010 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.gfx.vml"); |
dojo.require("dojo.dom"); |
dojo.require("dojo.math"); |
dojo.require("dojo.lang.declare"); |
dojo.require("dojo.lang.extras"); |
dojo.require("dojo.string.*"); |
dojo.require("dojo.html.metrics"); |
dojo.require("dojo.gfx.color"); |
dojo.require("dojo.gfx.common"); |
dojo.require("dojo.gfx.shape"); |
dojo.require("dojo.gfx.path"); |
dojo.require("dojo.experimental"); |
dojo.experimental("dojo.gfx.vml"); |
dojo.gfx.vml.xmlns = "urn:schemas-microsoft-com:vml"; |
dojo.gfx.vml._parseFloat = function (str) { |
return str.match(/^\d+f$/i) ? parseInt(str) / 65536 : parseFloat(str); |
}; |
dojo.gfx.vml.cm_in_pt = 72 / 2.54; |
dojo.gfx.vml.mm_in_pt = 7.2 / 2.54; |
dojo.gfx.vml.px_in_pt = function () { |
return dojo.html.getCachedFontMeasurements()["12pt"] / 12; |
}; |
dojo.gfx.vml.pt2px = function (len) { |
return len * this.px_in_pt(); |
}; |
dojo.gfx.vml.px2pt = function (len) { |
return len / this.px_in_pt(); |
}; |
dojo.gfx.vml.normalizedLength = function (len) { |
if (len.length == 0) { |
return 0; |
} |
if (len.length > 2) { |
var px_in_pt = this.px_in_pt(); |
var val = parseFloat(len); |
switch (len.slice(-2)) { |
case "px": |
return val; |
case "pt": |
return val * px_in_pt; |
case "in": |
return val * 72 * px_in_pt; |
case "pc": |
return val * 12 * px_in_pt; |
case "mm": |
return val / this.mm_in_pt * px_in_pt; |
case "cm": |
return val / this.cm_in_pt * px_in_pt; |
} |
} |
return parseFloat(len); |
}; |
dojo.lang.extend(dojo.gfx.Shape, {setFill:function (fill) { |
if (!fill) { |
this.fillStyle = null; |
this.rawNode.filled = false; |
return this; |
} |
if (typeof (fill) == "object" && "type" in fill) { |
switch (fill.type) { |
case "linear": |
var f = dojo.gfx.makeParameters(dojo.gfx.defaultLinearGradient, fill); |
this.fillStyle = f; |
var s = ""; |
for (var i = 0; i < f.colors.length; ++i) { |
f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color); |
s += f.colors[i].offset.toFixed(8) + " " + f.colors[i].color.toHex() + ";"; |
} |
var fo = this.rawNode.fill; |
fo.colors.value = s; |
fo.method = "sigma"; |
fo.type = "gradient"; |
fo.angle = (dojo.math.radToDeg(Math.atan2(f.x2 - f.x1, f.y2 - f.y1)) + 180) % 360; |
fo.on = true; |
break; |
case "radial": |
var f = dojo.gfx.makeParameters(dojo.gfx.defaultRadialGradient, fill); |
this.fillStyle = f; |
var w = parseFloat(this.rawNode.style.width); |
var h = parseFloat(this.rawNode.style.height); |
var c = isNaN(w) ? 1 : 2 * f.r / w; |
var i = f.colors.length - 1; |
f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color); |
var s = "0 " + f.colors[i].color.toHex(); |
for (; i >= 0; --i) { |
f.colors[i].color = dojo.gfx.normalizeColor(f.colors[i].color); |
s += (1 - c * f.colors[i].offset).toFixed(8) + " " + f.colors[i].color.toHex() + ";"; |
} |
var fo = this.rawNode.fill; |
fo.colors.value = s; |
fo.method = "sigma"; |
fo.type = "gradientradial"; |
if (isNaN(w) || isNaN(h)) { |
fo.focusposition = "0.5 0.5"; |
} else { |
fo.focusposition = (f.cx / w).toFixed(8) + " " + (f.cy / h).toFixed(8); |
} |
fo.focussize = "0 0"; |
fo.on = true; |
break; |
case "pattern": |
var f = dojo.gfx.makeParameters(dojo.gfx.defaultPattern, fill); |
this.fillStyle = f; |
var fo = this.rawNode.fill; |
fo.type = "tile"; |
fo.src = f.src; |
if (f.width && f.height) { |
fo.size.x = dojo.gfx.vml.px2pt(f.width); |
fo.size.y = dojo.gfx.vml.px2pt(f.height); |
} |
fo.alignShape = false; |
fo.position.x = 0; |
fo.position.y = 0; |
fo.origin.x = f.width ? f.x / f.width : 0; |
fo.origin.y = f.height ? f.y / f.height : 0; |
fo.on = true; |
break; |
} |
this.rawNode.fill.opacity = 1; |
return this; |
} |
this.fillStyle = dojo.gfx.normalizeColor(fill); |
this.rawNode.fillcolor = this.fillStyle.toHex(); |
this.rawNode.fill.opacity = this.fillStyle.a; |
this.rawNode.filled = true; |
return this; |
}, setStroke:function (stroke) { |
if (!stroke) { |
this.strokeStyle = null; |
this.rawNode.stroked = false; |
return this; |
} |
this.strokeStyle = dojo.gfx.makeParameters(dojo.gfx.defaultStroke, stroke); |
this.strokeStyle.color = dojo.gfx.normalizeColor(this.strokeStyle.color); |
var s = this.strokeStyle; |
this.rawNode.stroked = true; |
this.rawNode.strokecolor = s.color.toCss(); |
this.rawNode.strokeweight = s.width + "px"; |
if (this.rawNode.stroke) { |
this.rawNode.stroke.opacity = s.color.a; |
this.rawNode.stroke.endcap = this._translate(this._capMap, s.cap); |
if (typeof (s.join) == "number") { |
this.rawNode.stroke.joinstyle = "miter"; |
this.rawNode.stroke.miterlimit = s.join; |
} else { |
this.rawNode.stroke.joinstyle = s.join; |
} |
} |
return this; |
}, _capMap:{butt:"flat"}, _capMapReversed:{flat:"butt"}, _translate:function (dict, value) { |
return (value in dict) ? dict[value] : value; |
}, _applyTransform:function () { |
var matrix = this._getRealMatrix(); |
if (!matrix) { |
return this; |
} |
var skew = this.rawNode.skew; |
if (typeof (skew) == "undefined") { |
for (var i = 0; i < this.rawNode.childNodes.length; ++i) { |
if (this.rawNode.childNodes[i].tagName == "skew") { |
skew = this.rawNode.childNodes[i]; |
break; |
} |
} |
} |
if (skew) { |
skew.on = false; |
var mt = matrix.xx.toFixed(8) + " " + matrix.xy.toFixed(8) + " " + matrix.yx.toFixed(8) + " " + matrix.yy.toFixed(8) + " 0 0"; |
var offset = Math.floor(matrix.dx).toFixed() + "px " + Math.floor(matrix.dy).toFixed() + "px"; |
var l = parseFloat(this.rawNode.style.left); |
var t = parseFloat(this.rawNode.style.top); |
var w = parseFloat(this.rawNode.style.width); |
var h = parseFloat(this.rawNode.style.height); |
if (isNaN(l)) { |
l = 0; |
} |
if (isNaN(t)) { |
t = 0; |
} |
if (isNaN(w)) { |
w = 1; |
} |
if (isNaN(h)) { |
h = 1; |
} |
var origin = (-l / w - 0.5).toFixed(8) + " " + (-t / h - 0.5).toFixed(8); |
skew.matrix = mt; |
skew.origin = origin; |
skew.offset = offset; |
skew.on = true; |
} |
return this; |
}, setRawNode:function (rawNode) { |
rawNode.stroked = false; |
rawNode.filled = false; |
this.rawNode = rawNode; |
}, attachFill:function (rawNode) { |
var fillStyle = null; |
var fo = rawNode.fill; |
if (rawNode) { |
if (fo.on && fo.type == "gradient") { |
var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultLinearGradient, true); |
var rad = dojo.math.degToRad(fo.angle); |
fillStyle.x2 = Math.cos(rad); |
fillStyle.y2 = Math.sin(rad); |
fillStyle.colors = []; |
var stops = fo.colors.value.split(";"); |
for (var i = 0; i < stops.length; ++i) { |
var t = stops[i].match(/\S+/g); |
if (!t || t.length != 2) { |
continue; |
} |
fillStyle.colors.push({offset:dojo.gfx.vml._parseFloat(t[0]), color:new dojo.gfx.color.Color(t[1])}); |
} |
} else { |
if (fo.on && fo.type == "gradientradial") { |
var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultRadialGradient, true); |
var w = parseFloat(rawNode.style.width); |
var h = parseFloat(rawNode.style.height); |
fillStyle.cx = isNaN(w) ? 0 : fo.focusposition.x * w; |
fillStyle.cy = isNaN(h) ? 0 : fo.focusposition.y * h; |
fillStyle.r = isNaN(w) ? 1 : w / 2; |
fillStyle.colors = []; |
var stops = fo.colors.value.split(";"); |
for (var i = stops.length - 1; i >= 0; --i) { |
var t = stops[i].match(/\S+/g); |
if (!t || t.length != 2) { |
continue; |
} |
fillStyle.colors.push({offset:dojo.gfx.vml._parseFloat(t[0]), color:new dojo.gfx.color.Color(t[1])}); |
} |
} else { |
if (fo.on && fo.type == "tile") { |
var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultPattern, true); |
fillStyle.width = dojo.gfx.vml.pt2px(fo.size.x); |
fillStyle.height = dojo.gfx.vml.pt2px(fo.size.y); |
fillStyle.x = fo.origin.x * fillStyle.width; |
fillStyle.y = fo.origin.y * fillStyle.height; |
fillStyle.src = fo.src; |
} else { |
if (fo.on && rawNode.fillcolor) { |
fillStyle = new dojo.gfx.color.Color(rawNode.fillcolor + ""); |
fillStyle.a = fo.opacity; |
} |
} |
} |
} |
} |
return fillStyle; |
}, attachStroke:function (rawNode) { |
var strokeStyle = dojo.lang.shallowCopy(dojo.gfx.defaultStroke, true); |
if (rawNode && rawNode.stroked) { |
strokeStyle.color = new dojo.gfx.color.Color(rawNode.strokecolor.value); |
dojo.debug("We are expecting an .75pt here, instead of strokeweight = " + rawNode.strokeweight); |
strokeStyle.width = dojo.gfx.vml.normalizedLength(rawNode.strokeweight + ""); |
strokeStyle.color.a = rawNode.stroke.opacity; |
strokeStyle.cap = this._translate(this._capMapReversed, rawNode.stroke.endcap); |
strokeStyle.join = rawNode.stroke.joinstyle == "miter" ? rawNode.stroke.miterlimit : rawNode.stroke.joinstyle; |
} else { |
return null; |
} |
return strokeStyle; |
}, attachTransform:function (rawNode) { |
var matrix = {}; |
if (rawNode) { |
var s = rawNode.skew; |
matrix.xx = s.matrix.xtox; |
matrix.xy = s.matrix.ytox; |
matrix.yx = s.matrix.xtoy; |
matrix.yy = s.matrix.ytoy; |
matrix.dx = dojo.gfx.vml.pt2px(s.offset.x); |
matrix.dy = dojo.gfx.vml.pt2px(s.offset.y); |
} |
return dojo.gfx.matrix.normalize(matrix); |
}, attach:function (rawNode) { |
if (rawNode) { |
this.rawNode = rawNode; |
this.shape = this.attachShape(rawNode); |
this.fillStyle = this.attachFill(rawNode); |
this.strokeStyle = this.attachStroke(rawNode); |
this.matrix = this.attachTransform(rawNode); |
} |
}}); |
dojo.declare("dojo.gfx.Group", dojo.gfx.shape.VirtualGroup, {add:function (shape) { |
if (this != shape.getParent()) { |
this.rawNode.appendChild(shape.rawNode); |
dojo.gfx.Group.superclass.add.apply(this, arguments); |
} |
return this; |
}, remove:function (shape, silently) { |
if (this == shape.getParent()) { |
if (this.rawNode == shape.rawNode.parentNode) { |
this.rawNode.removeChild(shape.rawNode); |
} |
dojo.gfx.Group.superclass.remove.apply(this, arguments); |
} |
return this; |
}, attach:function (rawNode) { |
if (rawNode) { |
this.rawNode = rawNode; |
this.shape = null; |
this.fillStyle = null; |
this.strokeStyle = null; |
this.matrix = null; |
} |
}}); |
dojo.gfx.Group.nodeType = "group"; |
var zIndex = {moveToFront:function () { |
this.rawNode.parentNode.appendChild(this.rawNode); |
return this; |
}, moveToBack:function () { |
this.rawNode.parentNode.insertBefore(this.rawNode, this.rawNode.parentNode.firstChild); |
return this; |
}}; |
dojo.lang.extend(dojo.gfx.Shape, zIndex); |
dojo.lang.extend(dojo.gfx.Group, zIndex); |
delete zIndex; |
dojo.declare("dojo.gfx.Rect", dojo.gfx.shape.Rect, {attachShape:function (rawNode) { |
var arcsize = rawNode.outerHTML.match(/arcsize = \"(\d*\.?\d+[%f]?)\"/)[1]; |
arcsize = (arcsize.indexOf("%") >= 0) ? parseFloat(arcsize) / 100 : dojo.gfx.vml._parseFloat(arcsize); |
var style = rawNode.style; |
var width = parseFloat(style.width); |
var height = parseFloat(style.height); |
var o = dojo.gfx.makeParameters(dojo.gfx.defaultRect, {x:parseInt(style.left), y:parseInt(style.top), width:width, height:height, r:Math.min(width, height) * arcsize}); |
return o; |
}, setShape:function (newShape) { |
var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
var style = this.rawNode.style; |
style.left = shape.x.toFixed(); |
style.top = shape.y.toFixed(); |
style.width = (typeof (shape.width) == "string" && shape.width.indexOf("%") >= 0) ? shape.width : shape.width.toFixed(); |
style.height = (typeof (shape.width) == "string" && shape.height.indexOf("%") >= 0) ? shape.height : shape.height.toFixed(); |
var r = Math.min(1, (shape.r / Math.min(parseFloat(shape.width), parseFloat(shape.height)))).toFixed(8); |
var parent = this.rawNode.parentNode; |
var before = null; |
if (parent) { |
if (parent.lastChild != this.rawNode) { |
for (var i = 0; i < parent.childNodes.length; ++i) { |
if (parent.childNodes[i] == this.rawNode) { |
before = parent.childNodes[i + 1]; |
break; |
} |
} |
} |
parent.removeChild(this.rawNode); |
} |
this.rawNode.arcsize = r; |
if (parent) { |
if (before) { |
parent.insertBefore(this.rawNode, before); |
} else { |
parent.appendChild(this.rawNode); |
} |
} |
return this.setTransform(this.matrix); |
}}); |
dojo.gfx.Rect.nodeType = "roundrect"; |
dojo.declare("dojo.gfx.Ellipse", dojo.gfx.shape.Ellipse, {attachShape:function (rawNode) { |
var style = this.rawNode.style; |
var rx = parseInt(style.width) / 2; |
var ry = parseInt(style.height) / 2; |
var o = dojo.gfx.makeParameters(dojo.gfx.defaultEllipse, {cx:parseInt(style.left) + rx, cy:parseInt(style.top) + ry, rx:rx, ry:ry}); |
return o; |
}, setShape:function (newShape) { |
var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
var style = this.rawNode.style; |
style.left = (shape.cx - shape.rx).toFixed(); |
style.top = (shape.cy - shape.ry).toFixed(); |
style.width = (shape.rx * 2).toFixed(); |
style.height = (shape.ry * 2).toFixed(); |
return this.setTransform(this.matrix); |
}}); |
dojo.gfx.Ellipse.nodeType = "oval"; |
dojo.declare("dojo.gfx.Circle", dojo.gfx.shape.Circle, {attachShape:function (rawNode) { |
var style = this.rawNode.style; |
var r = parseInt(style.width) / 2; |
var o = dojo.gfx.makeParameters(dojo.gfx.defaultCircle, {cx:parseInt(style.left) + r, cy:parseInt(style.top) + r, r:r}); |
return o; |
}, setShape:function (newShape) { |
var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
var style = this.rawNode.style; |
style.left = (shape.cx - shape.r).toFixed(); |
style.top = (shape.cy - shape.r).toFixed(); |
style.width = (shape.r * 2).toFixed(); |
style.height = (shape.r * 2).toFixed(); |
return this; |
}}); |
dojo.gfx.Circle.nodeType = "oval"; |
dojo.declare("dojo.gfx.Line", dojo.gfx.shape.Line, function (rawNode) { |
if (rawNode) { |
rawNode.setAttribute("dojoGfxType", "line"); |
} |
}, {attachShape:function (rawNode) { |
var p = rawNode.path.v.match(dojo.gfx.pathRegExp); |
var shape = {}; |
do { |
if (p.length < 7 || p[0] != "m" || p[3] != "l" || p[6] != "e") { |
break; |
} |
shape.x1 = parseInt(p[1]); |
shape.y1 = parseInt(p[2]); |
shape.x2 = parseInt(p[4]); |
shape.y2 = parseInt(p[5]); |
} while (false); |
return dojo.gfx.makeParameters(dojo.gfx.defaultLine, shape); |
}, setShape:function (newShape) { |
var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
this.rawNode.path.v = "m" + shape.x1.toFixed() + " " + shape.y1.toFixed() + "l" + shape.x2.toFixed() + " " + shape.y2.toFixed() + "e"; |
return this.setTransform(this.matrix); |
}}); |
dojo.gfx.Line.nodeType = "shape"; |
dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline, function (rawNode) { |
if (rawNode) { |
rawNode.setAttribute("dojoGfxType", "polyline"); |
} |
}, {attachShape:function (rawNode) { |
var shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true); |
var p = rawNode.path.v.match(dojo.gfx.pathRegExp); |
do { |
if (p.length < 3 || p[0] != "m") { |
break; |
} |
var x = parseInt(p[0]); |
var y = parseInt(p[1]); |
if (isNaN(x) || isNaN(y)) { |
break; |
} |
shape.points.push({x:x, y:y}); |
if (p.length < 6 || p[3] != "l") { |
break; |
} |
for (var i = 4; i < p.length; i += 2) { |
x = parseInt(p[i]); |
y = parseInt(p[i + 1]); |
if (isNaN(x) || isNaN(y)) { |
break; |
} |
shape.points.push({x:x, y:y}); |
} |
} while (false); |
return shape; |
}, setShape:function (points, closed) { |
if (points && points instanceof Array) { |
this.shape = dojo.gfx.makeParameters(this.shape, {points:points}); |
if (closed && this.shape.points.length) { |
this.shape.points.push(this.shape.points[0]); |
} |
} else { |
this.shape = dojo.gfx.makeParameters(this.shape, points); |
} |
this.bbox = null; |
var attr = []; |
var p = this.shape.points; |
if (p.length > 0) { |
attr.push("m"); |
attr.push(p[0].x.toFixed()); |
attr.push(p[0].y.toFixed()); |
if (p.length > 1) { |
attr.push("l"); |
for (var i = 1; i < p.length; ++i) { |
attr.push(p[i].x.toFixed()); |
attr.push(p[i].y.toFixed()); |
} |
} |
} |
attr.push("e"); |
this.rawNode.path.v = attr.join(" "); |
return this.setTransform(this.matrix); |
}}); |
dojo.gfx.Polyline.nodeType = "shape"; |
dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {getEventSource:function () { |
return this.rawNode ? this.rawNode.firstChild : null; |
}, attachShape:function (rawNode) { |
var shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true); |
shape.src = rawNode.firstChild.src; |
return shape; |
}, setShape:function (newShape) { |
var shape = this.shape = dojo.gfx.makeParameters(this.shape, newShape); |
this.bbox = null; |
var firstChild = this.rawNode.firstChild; |
firstChild.src = shape.src; |
if (shape.width || shape.height) { |
firstChild.style.width = shape.width; |
firstChild.style.height = shape.height; |
} |
return this.setTransform(this.matrix); |
}, setStroke:function () { |
return this; |
}, setFill:function () { |
return this; |
}, attachStroke:function (rawNode) { |
return null; |
}, attachFill:function (rawNode) { |
return null; |
}, attachTransform:function (rawNode) { |
var matrix = {}; |
if (rawNode) { |
var m = rawNode.filters["DXImageTransform.Microsoft.Matrix"]; |
matrix.xx = m.M11; |
matrix.xy = m.M12; |
matrix.yx = m.M21; |
matrix.yy = m.M22; |
matrix.dx = m.Dx; |
matrix.dy = m.Dy; |
} |
return dojo.gfx.matrix.normalize(matrix); |
}, _applyTransform:function () { |
var matrix = this._getRealMatrix(); |
if (!matrix) { |
return this; |
} |
with (this.rawNode.filters["DXImageTransform.Microsoft.Matrix"]) { |
M11 = matrix.xx; |
M12 = matrix.xy; |
M21 = matrix.yx; |
M22 = matrix.yy; |
Dx = matrix.dx; |
Dy = matrix.dy; |
} |
return this; |
}}); |
dojo.gfx.Image.nodeType = "image"; |
dojo.gfx.path._calcArc = function (alpha) { |
var cosa = Math.cos(alpha); |
var sina = Math.sin(alpha); |
var p2 = {x:cosa + (4 / 3) * (1 - cosa), y:sina - (4 / 3) * cosa * (1 - cosa) / sina}; |
return {s:{x:cosa, y:sina}, c1:p2, c2:{x:p2.x, y:-p2.y}, e:{x:cosa, y:-sina}}; |
}; |
dojo.declare("dojo.gfx.Path", dojo.gfx.path.Path, function (rawNode) { |
if (rawNode) { |
rawNode.setAttribute("dojoGfxType", "path"); |
} |
this.vmlPath = ""; |
this.lastControl = {}; |
}, {_updateWithSegment:function (segment) { |
var last = dojo.lang.shallowCopy(this.last); |
dojo.gfx.Path.superclass._updateWithSegment.apply(this, arguments); |
var path = this[this.renderers[segment.action]](segment, last); |
if (typeof (this.vmlPath) == "string") { |
this.vmlPath += path.join(""); |
} else { |
this.vmlPath = this.vmlPath.concat(path); |
} |
if (typeof (this.vmlPath) == "string") { |
this.rawNode.path.v = this.vmlPath + " e"; |
} |
}, attachShape:function (rawNode) { |
var shape = dojo.lang.shallowCopy(dojo.gfx.defaultPath, true); |
var p = rawNode.path.v.match(dojo.gfx.pathRegExp); |
var t = [], skip = false; |
for (var i = 0; i < p.length; ++p) { |
var s = p[i]; |
if (s in this._pathVmlToSvgMap) { |
skip = false; |
t.push(this._pathVmlToSvgMap[s]); |
} else { |
if (!skip) { |
var n = parseInt(s); |
if (isNaN(n)) { |
skip = true; |
} else { |
t.push(n); |
} |
} |
} |
} |
if (t.length) { |
shape.path = t.join(" "); |
} |
return shape; |
}, setShape:function (newShape) { |
this.vmlPath = []; |
this.lastControl = {}; |
dojo.gfx.Path.superclass.setShape.apply(this, arguments); |
this.vmlPath = this.vmlPath.join(""); |
this.rawNode.path.v = this.vmlPath + " e"; |
return this; |
}, _pathVmlToSvgMap:{m:"M", l:"L", t:"m", r:"l", c:"C", v:"c", qb:"Q", x:"z", e:""}, renderers:{M:"_moveToA", m:"_moveToR", L:"_lineToA", l:"_lineToR", H:"_hLineToA", h:"_hLineToR", V:"_vLineToA", v:"_vLineToR", C:"_curveToA", c:"_curveToR", S:"_smoothCurveToA", s:"_smoothCurveToR", Q:"_qCurveToA", q:"_qCurveToR", T:"_qSmoothCurveToA", t:"_qSmoothCurveToR", A:"_arcTo", a:"_arcTo", Z:"_closePath", z:"_closePath"}, _addArgs:function (path, args, from, upto) { |
if (typeof (upto) == "undefined") { |
upto = args.length; |
} |
if (typeof (from) == "undefined") { |
from = 0; |
} |
for (var i = from; i < upto; ++i) { |
path.push(" "); |
path.push(args[i].toFixed()); |
} |
}, _addArgsAdjusted:function (path, last, args, from, upto) { |
if (typeof (upto) == "undefined") { |
upto = args.length; |
} |
if (typeof (from) == "undefined") { |
from = 0; |
} |
for (var i = from; i < upto; i += 2) { |
path.push(" "); |
path.push((last.x + args[i]).toFixed()); |
path.push(" "); |
path.push((last.y + args[i + 1]).toFixed()); |
} |
}, _moveToA:function (segment) { |
var p = [" m"]; |
var n = segment.args; |
var l = n.length; |
if (l == 2) { |
this._addArgs(p, n); |
} else { |
this._addArgs(p, n, 0, 2); |
p.push(" l"); |
this._addArgs(p, n, 2); |
} |
this.lastControl = {}; |
return p; |
}, _moveToR:function (segment, last) { |
var p = ["x" in last ? " t" : " m"]; |
var n = segment.args; |
var l = n.length; |
if (l == 2) { |
this._addArgs(p, n); |
} else { |
this._addArgs(p, n, 0, 2); |
p.push(" r"); |
this._addArgs(p, n, 2); |
} |
this.lastControl = {}; |
return p; |
}, _lineToA:function (segment) { |
var p = [" l"]; |
this._addArgs(p, segment.args); |
this.lastControl = {}; |
return p; |
}, _lineToR:function (segment) { |
var p = [" r"]; |
this._addArgs(p, segment.args); |
this.lastControl = {}; |
return p; |
}, _hLineToA:function (segment, last) { |
var p = [" l"]; |
var n = segment.args; |
var l = n.length; |
var y = " " + last.y.toFixed(); |
for (var i = 0; i < l; ++i) { |
p.push(" "); |
p.push(n[i].toFixed()); |
p.push(y); |
} |
this.lastControl = {}; |
return p; |
}, _hLineToR:function (segment) { |
var p = [" r"]; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; ++i) { |
p.push(" "); |
p.push(n[i].toFixed()); |
p.push(" 0"); |
} |
this.lastControl = {}; |
return p; |
}, _vLineToA:function (segment, last) { |
var p = [" l"]; |
var n = segment.args; |
var l = n.length; |
var x = " " + last.x.toFixed(); |
for (var i = 0; i < l; ++i) { |
p.push(x); |
p.push(" "); |
p.push(n[i].toFixed()); |
} |
this.lastControl = {}; |
return p; |
}, _vLineToR:function (segment) { |
var p = [" r"]; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; ++i) { |
p.push(" 0 "); |
p.push(n[i].toFixed()); |
} |
this.lastControl = {}; |
return p; |
}, _curveToA:function (segment) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 6) { |
p.push(" c"); |
this._addArgs(p, n, i, i + 6); |
} |
this.lastControl = {x:n[l - 4], y:n[l - 3], type:"C"}; |
return p; |
}, _curveToR:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 6) { |
p.push(" v"); |
this._addArgs(p, n, i, i + 6); |
this.lastControl = {x:last.x + n[i + 2], y:last.y + n[i + 3]}; |
last.x += n[i + 4]; |
last.y += n[i + 5]; |
} |
this.lastControl.type = "C"; |
return p; |
}, _smoothCurveToA:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 4) { |
p.push(" c"); |
if (this.lastControl.type == "C") { |
this._addArgs(p, [2 * last.x - this.lastControl.x, 2 * last.y - this.lastControl.y]); |
} else { |
this._addArgs(p, [last.x, last.y]); |
} |
this._addArgs(p, n, i, i + 4); |
} |
this.lastControl = {x:n[l - 4], y:n[l - 3], type:"C"}; |
return p; |
}, _smoothCurveToR:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 4) { |
p.push(" v"); |
if (this.lastControl.type == "C") { |
this._addArgs(p, [last.x - this.lastControl.x, last.y - this.lastControl.y]); |
} else { |
this._addArgs(p, [0, 0]); |
} |
this._addArgs(p, n, i, i + 4); |
this.lastControl = {x:last.x + n[i], y:last.y + n[i + 1]}; |
last.x += n[i + 2]; |
last.y += n[i + 3]; |
} |
this.lastControl.type = "C"; |
return p; |
}, _qCurveToA:function (segment) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 4) { |
p.push(" qb"); |
this._addArgs(p, n, i, i + 4); |
} |
this.lastControl = {x:n[l - 4], y:n[l - 3], type:"Q"}; |
return p; |
}, _qCurveToR:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 4) { |
p.push(" qb"); |
this._addArgsAdjusted(p, last, n, i, i + 4); |
this.lastControl = {x:last.x + n[i], y:last.y + n[i + 1]}; |
last.x += n[i + 2]; |
last.y += n[i + 3]; |
} |
this.lastControl.type = "Q"; |
return p; |
}, _qSmoothCurveToA:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 2) { |
p.push(" qb"); |
if (this.lastControl.type == "Q") { |
this._addArgs(p, [this.lastControl.x = 2 * last.x - this.lastControl.x, this.lastControl.y = 2 * last.y - this.lastControl.y]); |
} else { |
this._addArgs(p, [this.lastControl.x = last.x, this.lastControl.y = last.y]); |
} |
this._addArgs(p, n, i, i + 2); |
} |
this.lastControl.type = "Q"; |
return p; |
}, _qSmoothCurveToR:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
for (var i = 0; i < l; i += 2) { |
p.push(" qb"); |
if (this.lastControl.type == "Q") { |
this._addArgs(p, [this.lastControl.x = 2 * last.x - this.lastControl.x, this.lastControl.y = 2 * last.y - this.lastControl.y]); |
} else { |
this._addArgs(p, [this.lastControl.x = last.x, this.lastControl.y = last.y]); |
} |
this._addArgsAdjusted(p, last, n, i, i + 2); |
} |
this.lastControl.type = "Q"; |
return p; |
}, _PI4:Math.PI / 4, _curvePI4:dojo.gfx.path._calcArc(Math.PI / 8), _calcArcTo:function (path, last, rx, ry, xRotg, large, cw, x, y) { |
var m = dojo.gfx.matrix; |
var xRot = -dojo.math.degToRad(xRotg); |
var rx2 = rx * rx; |
var ry2 = ry * ry; |
var pa = m.multiplyPoint(m.rotate(-xRot), {x:(last.x - x) / 2, y:(last.y - y) / 2}); |
var pax2 = pa.x * pa.x; |
var pay2 = pa.y * pa.y; |
var c1 = Math.sqrt((rx2 * ry2 - rx2 * pay2 - ry2 * pax2) / (rx2 * pay2 + ry2 * pax2)); |
var ca = {x:c1 * rx * pa.y / ry, y:-c1 * ry * pa.x / rx}; |
if (large == cw) { |
ca = {x:-ca.x, y:-ca.y}; |
} |
var c = m.multiplyPoint([m.translate((last.x + x) / 2, (last.y + y) / 2), m.rotate(xRot)], ca); |
var startAngle = Math.atan2(c.y - last.y, last.x - c.x) - xRot; |
var endAngle = Math.atan2(c.y - y, x - c.x) - xRot; |
var theta = cw ? startAngle - endAngle : endAngle - startAngle; |
if (theta < 0) { |
theta += this._2PI; |
} else { |
if (theta > this._2PI) { |
theta = this._2PI; |
} |
} |
var elliptic_transform = m.normalize([m.translate(c.x, c.y), m.rotate(xRot), m.scale(rx, ry)]); |
var alpha = this._PI4 / 2; |
var curve = this._curvePI4; |
var step = cw ? -alpha : alpha; |
for (var angle = theta; angle > 0; angle -= this._PI4) { |
if (angle < this._PI4) { |
alpha = angle / 2; |
curve = dojo.gfx.path._calcArc(alpha); |
step = cw ? -alpha : alpha; |
} |
var c1, c2, e; |
var M = m.normalize([elliptic_transform, m.rotate(startAngle + step)]); |
if (cw) { |
c1 = m.multiplyPoint(M, curve.c2); |
c2 = m.multiplyPoint(M, curve.c1); |
e = m.multiplyPoint(M, curve.s); |
} else { |
c1 = m.multiplyPoint(M, curve.c1); |
c2 = m.multiplyPoint(M, curve.c2); |
e = m.multiplyPoint(M, curve.e); |
} |
path.push(" c"); |
this._addArgs(path, [c1.x, c1.y, c2.x, c2.y, e.x, e.y]); |
startAngle += 2 * step; |
} |
}, _arcTo:function (segment, last) { |
var p = []; |
var n = segment.args; |
var l = n.length; |
var relative = segment.action == "a"; |
for (var i = 0; i < l; i += 7) { |
var x1 = n[i + 5]; |
var y1 = n[i + 6]; |
if (relative) { |
x1 += last.x; |
y1 += last.y; |
} |
this._calcArcTo(p, last, n[i], n[i + 1], n[i + 2], n[i + 3] ? 1 : 0, n[i + 4] ? 1 : 0, x1, y1); |
last = {x:x1, y:y1}; |
} |
this.lastControl = {}; |
return p; |
}, _closePath:function () { |
this.lastControl = {}; |
return ["x"]; |
}}); |
dojo.gfx.Path.nodeType = "shape"; |
dojo.gfx._creators = {createPath:function (path) { |
return this.createObject(dojo.gfx.Path, path, true); |
}, createRect:function (rect) { |
return this.createObject(dojo.gfx.Rect, rect); |
}, createCircle:function (circle) { |
return this.createObject(dojo.gfx.Circle, circle); |
}, createEllipse:function (ellipse) { |
return this.createObject(dojo.gfx.Ellipse, ellipse); |
}, createLine:function (line) { |
return this.createObject(dojo.gfx.Line, line, true); |
}, createPolyline:function (points) { |
return this.createObject(dojo.gfx.Polyline, points, true); |
}, createImage:function (image) { |
if (!this.rawNode) { |
return null; |
} |
var shape = new dojo.gfx.Image(); |
var node = document.createElement("div"); |
node.style.position = "relative"; |
node.style.width = this.rawNode.style.width; |
node.style.height = this.rawNode.style.height; |
node.style.filter = "progid:DXImageTransform.Microsoft.Matrix(M11=1, M12=0, M21=0, M22=1, Dx=0, Dy=0)"; |
var img = document.createElement("img"); |
node.appendChild(img); |
shape.setRawNode(node); |
this.rawNode.appendChild(node); |
shape.setShape(image); |
this.add(shape); |
return shape; |
}, createGroup:function () { |
return this.createObject(dojo.gfx.Group, null, true); |
}, createObject:function (shapeType, rawShape, overrideSize) { |
if (!this.rawNode) { |
return null; |
} |
var shape = new shapeType(); |
var node = document.createElement("v:" + shapeType.nodeType); |
shape.setRawNode(node); |
this.rawNode.appendChild(node); |
if (overrideSize) { |
this._overrideSize(node); |
} |
shape.setShape(rawShape); |
this.add(shape); |
return shape; |
}, _overrideSize:function (node) { |
node.style.width = this.rawNode.style.width; |
node.style.height = this.rawNode.style.height; |
node.coordsize = parseFloat(node.style.width) + " " + parseFloat(node.style.height); |
}}; |
dojo.lang.extend(dojo.gfx.Group, dojo.gfx._creators); |
dojo.lang.extend(dojo.gfx.Surface, dojo.gfx._creators); |
delete dojo.gfx._creators; |
dojo.gfx.attachNode = function (node) { |
if (!node) { |
return null; |
} |
var s = null; |
switch (node.tagName.toLowerCase()) { |
case dojo.gfx.Rect.nodeType: |
s = new dojo.gfx.Rect(); |
break; |
case dojo.gfx.Ellipse.nodeType: |
s = (node.style.width == node.style.height) ? new dojo.gfx.Circle() : new dojo.gfx.Ellipse(); |
break; |
case dojo.gfx.Path.nodeType: |
switch (node.getAttribute("dojoGfxType")) { |
case "line": |
s = new dojo.gfx.Line(); |
break; |
case "polyline": |
s = new dojo.gfx.Polyline(); |
break; |
case "path": |
s = new dojo.gfx.Path(); |
break; |
} |
break; |
case dojo.gfx.Image.nodeType: |
s = new dojo.gfx.Image(); |
break; |
default: |
dojo.debug("FATAL ERROR! tagName = " + node.tagName); |
} |
s.attach(node); |
return s; |
}; |
dojo.lang.extend(dojo.gfx.Surface, {setDimensions:function (width, height) { |
if (!this.rawNode) { |
return this; |
} |
this.rawNode.style.width = width; |
this.rawNode.style.height = height; |
this.rawNode.coordsize = width + " " + height; |
return this; |
}, getDimensions:function () { |
return this.rawNode ? {width:this.rawNode.style.width, height:this.rawNode.style.height} : null; |
}, add:function (shape) { |
var oldParent = shape.getParent(); |
if (this != oldParent) { |
this.rawNode.appendChild(shape.rawNode); |
if (oldParent) { |
oldParent.remove(shape, true); |
} |
shape._setParent(this, null); |
} |
return this; |
}, remove:function (shape, silently) { |
if (this == shape.getParent()) { |
if (this.rawNode == shape.rawNode.parentNode) { |
this.rawNode.removeChild(shape.rawNode); |
} |
shape._setParent(null, null); |
} |
return this; |
}}); |
dojo.gfx.createSurface = function (parentNode, width, height) { |
var s = new dojo.gfx.Surface(); |
s.rawNode = document.createElement("v:group"); |
s.rawNode.style.width = width ? width : "100%"; |
s.rawNode.style.height = height ? height : "100%"; |
s.rawNode.coordsize = (width && height) ? (parseFloat(width) + " " + parseFloat(height)) : "100% 100%"; |
s.rawNode.coordorigin = "0 0"; |
dojo.byId(parentNode).appendChild(s.rawNode); |
return s; |
}; |
dojo.gfx.attachSurface = function (node) { |
var s = new dojo.gfx.Surface(); |
s.rawNode = node; |
return s; |
}; |