Commit 6b3fa145 by Dmitry Baranovskiy

Added alias to customAttribute. Fixed transform() method

parent a3d3b76d
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -101,6 +101,12 @@ ...@@ -101,6 +101,12 @@
}, },
Paper = function () { Paper = function () {
/*\ /*\
* Paper.ca
[ property (object) ]
**
* Shortcut for @Paper.customAttributes
\*/
/*\
* Paper.customAttributes * Paper.customAttributes
[ property (object) ] [ property (object) ]
** **
...@@ -109,7 +115,7 @@ ...@@ -109,7 +115,7 @@
> Usage > Usage
| paper.customAttributes.hue = function (num) { | paper.customAttributes.hue = function (num) {
| num = num % 1; | num = num % 1;
| return {fill: "hsb(" + num + ", .75, 1)"}; | return {fill: "hsb(" + num + ", 0.75, 1)"};
| }; | };
| // Custom attribute “hue” will change fill | // Custom attribute “hue” will change fill
| // to be given hue with fixed saturation and brightness. | // to be given hue with fixed saturation and brightness.
...@@ -123,10 +129,10 @@ ...@@ -123,10 +129,10 @@
| paper.customAttributes.hsb = function (h, s, b) { | paper.customAttributes.hsb = function (h, s, b) {
| return {fill: "hsb(" + [h, s, b].join(",") + ")"}; | return {fill: "hsb(" + [h, s, b].join(",") + ")"};
| }; | };
| c.attr({hsb: ".5 .8 1"}); | c.attr({hsb: "0.5 .8 1"});
| c.animate({hsb: "1 0 .5"}, 1e3); | c.animate({hsb: [1, 0, 0.5]}, 1e3);
\*/ \*/
this.customAttributes = {}; this.ca = this.customAttributes = {};
}, },
paperproto, paperproto,
appendChild = "appendChild", appendChild = "appendChild",
...@@ -137,7 +143,7 @@ ...@@ -137,7 +143,7 @@
S = " ", S = " ",
Str = String, Str = String,
split = "split", split = "split",
events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel".split(S), events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
touchMap = { touchMap = {
mousedown: "touchstart", mousedown: "touchstart",
mousemove: "touchmove", mousemove: "touchmove",
...@@ -881,7 +887,7 @@ ...@@ -881,7 +887,7 @@
red = toInt((t = rgb[3].charAt(1)) + t, 16); red = toInt((t = rgb[3].charAt(1)) + t, 16);
} }
if (rgb[4]) { if (rgb[4]) {
values = rgb[4].split(commaSpaces); values = rgb[4][split](commaSpaces);
red = toFloat(values[0]); red = toFloat(values[0]);
values[0].slice(-1) == "%" && (red *= 2.55); values[0].slice(-1) == "%" && (red *= 2.55);
green = toFloat(values[1]); green = toFloat(values[1]);
...@@ -892,7 +898,7 @@ ...@@ -892,7 +898,7 @@
values[3] && values[3].slice(-1) == "%" && (opacity /= 100); values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
} }
if (rgb[5]) { if (rgb[5]) {
values = rgb[5].split(commaSpaces); values = rgb[5][split](commaSpaces);
red = toFloat(values[0]); red = toFloat(values[0]);
values[0].slice(-1) == "%" && (red *= 2.55); values[0].slice(-1) == "%" && (red *= 2.55);
green = toFloat(values[1]); green = toFloat(values[1]);
...@@ -905,7 +911,7 @@ ...@@ -905,7 +911,7 @@
return R.hsb2rgb(red, green, blue, opacity); return R.hsb2rgb(red, green, blue, opacity);
} }
if (rgb[6]) { if (rgb[6]) {
values = rgb[6].split(commaSpaces); values = rgb[6][split](commaSpaces);
red = toFloat(values[0]); red = toFloat(values[0]);
values[0].slice(-1) == "%" && (red *= 2.55); values[0].slice(-1) == "%" && (red *= 2.55);
green = toFloat(values[1]); green = toFloat(values[1]);
...@@ -1484,7 +1490,7 @@ ...@@ -1484,7 +1490,7 @@
if (recursive) { if (recursive) {
return [m2, m3, m4][concat](res); return [m2, m3, m4][concat](res);
} else { } else {
res = [m2, m3, m4][concat](res).join().split(","); res = [m2, m3, m4][concat](res).join()[split](",");
var newres = []; var newres = [];
for (var i = 0, ii = res.length; i < ii; i++) { for (var i = 0, ii = res.length; i < ii; i++) {
newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
...@@ -1736,24 +1742,25 @@ ...@@ -1736,24 +1742,25 @@
for (var i = 0, ii = tdata.length; i < ii; i++) { for (var i = 0, ii = tdata.length; i < ii; i++) {
var t = tdata[i], var t = tdata[i],
tlen = t.length, tlen = t.length,
absolute = t[0] != (t[0] = Str(t[0]).toLowerCase()), command = Str(t[0]).toLowerCase(),
absolute = t[0] != command,
inver = absolute ? m.invert() : 0, inver = absolute ? m.invert() : 0,
x1, x1,
y1, y1,
x2, x2,
y2, y2,
bb; bb;
if (t[0] == "t" && tlen == 3) { if (command == "t" && tlen == 3) {
if (absolute) { if (absolute) {
x1 = inver.x(0, 0), x1 = inver.x(0, 0);
y1 = inver.y(0, 0), y1 = inver.y(0, 0);
x2 = inver.x(t[1], t[2]); x2 = inver.x(t[1], t[2]);
y2 = inver.y(t[1], t[2]); y2 = inver.y(t[1], t[2]);
m.translate(x2 - x1, y2 - y1); m.translate(x2 - x1, y2 - y1);
} else { } else {
m.translate(t[1], t[2]); m.translate(t[1], t[2]);
} }
} else if (t[0] == "r") { } else if (command == "r") {
if (tlen == 2) { if (tlen == 2) {
bb = bb || el.getBBox(1); bb = bb || el.getBBox(1);
m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2); m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
...@@ -1768,7 +1775,7 @@ ...@@ -1768,7 +1775,7 @@
} }
deg += t[1]; deg += t[1];
} }
} else if (t[0] == "s") { } else if (command == "s") {
if (tlen == 2 || tlen == 3) { if (tlen == 2 || tlen == 3) {
bb = bb || el.getBBox(1); bb = bb || el.getBBox(1);
m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2); m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
...@@ -1785,7 +1792,7 @@ ...@@ -1785,7 +1792,7 @@
sx *= t[1]; sx *= t[1];
sy *= t[2]; sy *= t[2];
} }
} else if (t[0] == "m" && tlen == 7) { } else if (command == "m" && tlen == 7) {
m.add(t[1], t[2], t[3], t[4], t[5], t[6]); m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
} }
_.dirtyT = 1; _.dirtyT = 1;
...@@ -2166,7 +2173,7 @@ ...@@ -2166,7 +2173,7 @@
= (string) transform string = (string) transform string
\*/ \*/
matrixproto.toTransformString = function (shorter) { matrixproto.toTransformString = function (shorter) {
var s = shorter || this.split(); var s = shorter || this[split]();
if (s.isSimple) { if (s.isSimple) {
return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0]; return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0];
} else { } else {
...@@ -3540,7 +3547,7 @@ ...@@ -3540,7 +3547,7 @@
} }
break; break;
default: default:
var from2 = [].concat(from[attr]); var from2 = [][concat](from[attr]);
now = []; now = [];
i = that.paper.customAttributes[attr].length; i = that.paper.customAttributes[attr].length;
while (i--) { while (i--) {
...@@ -3846,8 +3853,8 @@ ...@@ -3846,8 +3853,8 @@
} }
break; break;
case "csv": case "csv":
var values = Str(params[attr]).split(separator), var values = Str(params[attr])[split](separator),
from2 = Str(from[attr]).split(separator); from2 = Str(from[attr])[split](separator);
if (attr == "clip-rect") { if (attr == "clip-rect") {
from[attr] = from2; from[attr] = from2;
diff[attr] = []; diff[attr] = [];
...@@ -3859,8 +3866,8 @@ ...@@ -3859,8 +3866,8 @@
to[attr] = values; to[attr] = values;
break; break;
default: default:
values = [].concat(params[attr]); values = [][concat](params[attr]);
from2 = [].concat(from[attr]); from2 = [][concat](from[attr]);
diff[attr] = []; diff[attr] = [];
i = element.paper.customAttributes[attr].length; i = element.paper.customAttributes[attr].length;
while (i--) { while (i--) {
...@@ -4469,14 +4476,14 @@ ...@@ -4469,14 +4476,14 @@
origin = origin || "middle"; // baseline|middle origin = origin || "middle"; // baseline|middle
letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1); letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
var out = this.set(), var out = this.set(),
letters = Str(string).split(E), letters = Str(string)[split](E),
shift = 0, shift = 0,
path = E, path = E,
scale; scale;
R.is(font, string) && (font = this.getFont(font)); R.is(font, string) && (font = this.getFont(font));
if (font) { if (font) {
scale = (size || 16) / font.face["units-per-em"]; scale = (size || 16) / font.face["units-per-em"];
var bb = font.face.bbox.split(separator), var bb = font.face.bbox[split](separator),
top = +bb[0], top = +bb[0],
height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2); height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
for (var i = 0, ii = letters.length; i < ii; i++) { for (var i = 0, ii = letters.length; i < ii; i++) {
......
...@@ -265,7 +265,8 @@ ...@@ -265,7 +265,8 @@
}, },
Paper = function () { Paper = function () {
this.customAttributes = {};
this.ca = this.customAttributes = {};
}, },
paperproto, paperproto,
appendChild = "appendChild", appendChild = "appendChild",
...@@ -276,7 +277,7 @@ ...@@ -276,7 +277,7 @@
S = " ", S = " ",
Str = String, Str = String,
split = "split", split = "split",
events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel".split(S), events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
touchMap = { touchMap = {
mousedown: "touchstart", mousedown: "touchstart",
mousemove: "touchmove", mousemove: "touchmove",
...@@ -814,7 +815,7 @@ ...@@ -814,7 +815,7 @@
red = toInt((t = rgb[3].charAt(1)) + t, 16); red = toInt((t = rgb[3].charAt(1)) + t, 16);
} }
if (rgb[4]) { if (rgb[4]) {
values = rgb[4].split(commaSpaces); values = rgb[4][split](commaSpaces);
red = toFloat(values[0]); red = toFloat(values[0]);
values[0].slice(-1) == "%" && (red *= 2.55); values[0].slice(-1) == "%" && (red *= 2.55);
green = toFloat(values[1]); green = toFloat(values[1]);
...@@ -825,7 +826,7 @@ ...@@ -825,7 +826,7 @@
values[3] && values[3].slice(-1) == "%" && (opacity /= 100); values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
} }
if (rgb[5]) { if (rgb[5]) {
values = rgb[5].split(commaSpaces); values = rgb[5][split](commaSpaces);
red = toFloat(values[0]); red = toFloat(values[0]);
values[0].slice(-1) == "%" && (red *= 2.55); values[0].slice(-1) == "%" && (red *= 2.55);
green = toFloat(values[1]); green = toFloat(values[1]);
...@@ -838,7 +839,7 @@ ...@@ -838,7 +839,7 @@
return R.hsb2rgb(red, green, blue, opacity); return R.hsb2rgb(red, green, blue, opacity);
} }
if (rgb[6]) { if (rgb[6]) {
values = rgb[6].split(commaSpaces); values = rgb[6][split](commaSpaces);
red = toFloat(values[0]); red = toFloat(values[0]);
values[0].slice(-1) == "%" && (red *= 2.55); values[0].slice(-1) == "%" && (red *= 2.55);
green = toFloat(values[1]); green = toFloat(values[1]);
...@@ -1315,7 +1316,7 @@ ...@@ -1315,7 +1316,7 @@
if (recursive) { if (recursive) {
return [m2, m3, m4][concat](res); return [m2, m3, m4][concat](res);
} else { } else {
res = [m2, m3, m4][concat](res).join().split(","); res = [m2, m3, m4][concat](res).join()[split](",");
var newres = []; var newres = [];
for (var i = 0, ii = res.length; i < ii; i++) { for (var i = 0, ii = res.length; i < ii; i++) {
newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
...@@ -1567,24 +1568,25 @@ ...@@ -1567,24 +1568,25 @@
for (var i = 0, ii = tdata.length; i < ii; i++) { for (var i = 0, ii = tdata.length; i < ii; i++) {
var t = tdata[i], var t = tdata[i],
tlen = t.length, tlen = t.length,
absolute = t[0] != (t[0] = Str(t[0]).toLowerCase()), command = Str(t[0]).toLowerCase(),
absolute = t[0] != command,
inver = absolute ? m.invert() : 0, inver = absolute ? m.invert() : 0,
x1, x1,
y1, y1,
x2, x2,
y2, y2,
bb; bb;
if (t[0] == "t" && tlen == 3) { if (command == "t" && tlen == 3) {
if (absolute) { if (absolute) {
x1 = inver.x(0, 0), x1 = inver.x(0, 0);
y1 = inver.y(0, 0), y1 = inver.y(0, 0);
x2 = inver.x(t[1], t[2]); x2 = inver.x(t[1], t[2]);
y2 = inver.y(t[1], t[2]); y2 = inver.y(t[1], t[2]);
m.translate(x2 - x1, y2 - y1); m.translate(x2 - x1, y2 - y1);
} else { } else {
m.translate(t[1], t[2]); m.translate(t[1], t[2]);
} }
} else if (t[0] == "r") { } else if (command == "r") {
if (tlen == 2) { if (tlen == 2) {
bb = bb || el.getBBox(1); bb = bb || el.getBBox(1);
m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2); m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
...@@ -1599,7 +1601,7 @@ ...@@ -1599,7 +1601,7 @@
} }
deg += t[1]; deg += t[1];
} }
} else if (t[0] == "s") { } else if (command == "s") {
if (tlen == 2 || tlen == 3) { if (tlen == 2 || tlen == 3) {
bb = bb || el.getBBox(1); bb = bb || el.getBBox(1);
m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2); m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
...@@ -1616,7 +1618,7 @@ ...@@ -1616,7 +1618,7 @@
sx *= t[1]; sx *= t[1];
sy *= t[2]; sy *= t[2];
} }
} else if (t[0] == "m" && tlen == 7) { } else if (command == "m" && tlen == 7) {
m.add(t[1], t[2], t[3], t[4], t[5], t[6]); m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
} }
_.dirtyT = 1; _.dirtyT = 1;
...@@ -1872,7 +1874,7 @@ ...@@ -1872,7 +1874,7 @@
}; };
matrixproto.toTransformString = function (shorter) { matrixproto.toTransformString = function (shorter) {
var s = shorter || this.split(); var s = shorter || this[split]();
if (s.isSimple) { if (s.isSimple) {
return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0]; return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0];
} else { } else {
...@@ -2595,7 +2597,7 @@ ...@@ -2595,7 +2597,7 @@
} }
break; break;
default: default:
var from2 = [].concat(from[attr]); var from2 = [][concat](from[attr]);
now = []; now = [];
i = that.paper.customAttributes[attr].length; i = that.paper.customAttributes[attr].length;
while (i--) { while (i--) {
...@@ -2856,8 +2858,8 @@ ...@@ -2856,8 +2858,8 @@
} }
break; break;
case "csv": case "csv":
var values = Str(params[attr]).split(separator), var values = Str(params[attr])[split](separator),
from2 = Str(from[attr]).split(separator); from2 = Str(from[attr])[split](separator);
if (attr == "clip-rect") { if (attr == "clip-rect") {
from[attr] = from2; from[attr] = from2;
diff[attr] = []; diff[attr] = [];
...@@ -2869,8 +2871,8 @@ ...@@ -2869,8 +2871,8 @@
to[attr] = values; to[attr] = values;
break; break;
default: default:
values = [].concat(params[attr]); values = [][concat](params[attr]);
from2 = [].concat(from[attr]); from2 = [][concat](from[attr]);
diff[attr] = []; diff[attr] = [];
i = element.paper.customAttributes[attr].length; i = element.paper.customAttributes[attr].length;
while (i--) { while (i--) {
...@@ -3278,14 +3280,14 @@ ...@@ -3278,14 +3280,14 @@
origin = origin || "middle"; // baseline|middle origin = origin || "middle"; // baseline|middle
letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1); letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
var out = this.set(), var out = this.set(),
letters = Str(string).split(E), letters = Str(string)[split](E),
shift = 0, shift = 0,
path = E, path = E,
scale; scale;
R.is(font, string) && (font = this.getFont(font)); R.is(font, string) && (font = this.getFont(font));
if (font) { if (font) {
scale = (size || 16) / font.face["units-per-em"]; scale = (size || 16) / font.face["units-per-em"];
var bb = font.face.bbox.split(separator), var bb = font.face.bbox[split](separator),
top = +bb[0], top = +bb[0],
height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2); height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
for (var i = 0, ii = letters.length; i < ii; i++) { for (var i = 0, ii = letters.length; i < ii; i++) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment