Remove need for svg.getAttribute('fx') check.

This commit is contained in:
Jürg Lehni 2012-11-08 15:01:32 -08:00
parent 61c8f76309
commit 203c9b16ca

View file

@ -25,19 +25,24 @@ new function() {
// objects, dealing with baseVal, and item lists. // objects, dealing with baseVal, and item lists.
// index is option, and if passed, causes a lookup in a list. // index is option, and if passed, causes a lookup in a list.
function getValue(svg, key, index) { function getValue(svg, key, allowNull, index) {
var base = svg[key].baseVal; var base = svg[key].baseVal,
return index !== undefined value = index !== undefined
? index < base.numberOfItems ? base.getItem(index).value || 0 : 0 ? index < base.numberOfItems ? base.getItem(index).value : null
: base.value || 0; : base.value;
return !allowNull && value == null ? 0 : value;
} }
function getPoint(svg, x, y, index) { function getPoint(svg, x, y, allowNull, index) {
return Point.create(getValue(svg, x, index), getValue(svg, y, index)); x = getValue(svg, x, allowNull, index);
y = getValue(svg, y, allowNull, index);
return x == null && y == null ? null : Point.create(x || 0, y || 0);
} }
function getSize(svg, w, h, index) { function getSize(svg, w, h, allowNull, index) {
return Size.create(getValue(svg, w, index), getValue(svg, h, index)); w = getValue(svg, w, allowNull, index);
h = getValue(svg, h, allowNull, index);
return w == null && h == null ? null : Size.create(w || 0, h || 0);
} }
// Converts a string attribute value to the specified type // Converts a string attribute value to the specified type
@ -215,10 +220,7 @@ new function() {
gradient.type = 'radial'; gradient.type = 'radial';
origin = getPoint(svg, 'cx', 'cy'); origin = getPoint(svg, 'cx', 'cy');
destination = origin.add(getValue(svg, 'r'), 0); destination = origin.add(getValue(svg, 'r'), 0);
var fx = svg.getAttribute('fx'); highlight = getPoint(svg, 'fx', 'fy', true);
if (fx) {
highlight = getPoint(svg, 'fx', 'fy');
}
} else { } else {
origin = getPoint(svg, 'x1', 'y1'); origin = getPoint(svg, 'x1', 'y1');
destination = getPoint(svg, 'x2', 'y2'); destination = getPoint(svg, 'x2', 'y2');
@ -305,8 +307,8 @@ new function() {
// TODO: Support for these is missing in Paper.js right now // TODO: Support for these is missing in Paper.js right now
// rotate: character rotation // rotate: character rotation
// lengthAdjust: // lengthAdjust:
var text = new PointText(getPoint(svg, 'x', 'y', 0) var text = new PointText(getPoint(svg, 'x', 'y', false, 0)
.add(getPoint(svg, 'dx', 'dy', 0))); .add(getPoint(svg, 'dx', 'dy', false, 0)));
text.content = svg.textContent || ''; text.content = svg.textContent || '';
return text; return text;
} }