SVG Importer: implement initial support for importing of images.

This commit is contained in:
Jonathan Puckey 2012-12-02 19:41:29 +01:00
parent 86d3a3521b
commit 9727874aa2

View file

@ -269,6 +269,24 @@ new function() {
// http://www.w3.org/TR/SVG/pservers.html#RadialGradients
radialgradient: importGradient,
// http://www.w3.org/TR/SVG/struct.html#ImageElement
image: function (svg) {
var raster = new Raster(getValue(svg, 'href'));
// TODO: for some reason Raster#onLoad is being fired twice,
// as a workaround work with alreadyLoaded variable
var alreadyLoaded = false;
raster.onLoad = function() {
if (alreadyLoaded) return;
var size = getSize(svg, 'width', 'height');
this.setSize(size);
// Since x and y start from the top left of an image, add
// half of its size:
this.translate(getPoint(svg, 'x', 'y').add(size.divide(2)));
alreadyLoaded = true;
};
return raster;
},
// http://www.w3.org/TR/SVG/struct.html#SymbolElement
symbol: function(svg, type) {
return new Symbol(applyAttributes(importGroup(svg, type), svg));