Michael A. Peters wrote:
*snip*
Is there an easy way around this? IE a php class/function that
understands SVG w/ xlink and can replace the use tags with the polygons
they refer to? If not, I'll have to try to write one, but I'd rather not
...
I just did, haven't tested yet, but this may work -
function use2polygon($use,$polygon) {
// get the xy coords
$x = 0; $y = 0;
if ($use->hasAttribute('x') {
$x = 0 + $use->getAttribute('x');
}
if ($use->hasAttribute('y') {
$y = 0 + $use->getAttribute('y');
}
// clone the polygon
if ($polygon->hasAttribute('points') {
$points = preg_replace('/\s+/',' ',$polygon->getAttribute('points'));
$pointArray = explode(' ',$points);
$sizeof = sizeof($pointArray);
for ($i=0;$i<$sizeof;$i++) {
$foo = explode(',',$pointArray[$i]);
$foo[0] = $x + $foo[0];
$foo[1] = $y + $foo[1];
$pointArray[$i] = $foo[0] . ',' . $foo[1];
}
$points = implode(' ',$points);
$newPolygon = $polygon->cloneNode(true);
$newPolygon->setAttribute('points',$points);
$use->parentNode->replaceChild($newPolygon,$use);
}
}
of course that requires domdocument and probably requires looping
through the dom node list backwards, but hopefully that will do it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php