Status of SVG import or conversion

20 views
Skip to first unread message

Matthijs

unread,
Jan 15, 2010, 10:13:52 AM1/15/10
to Degrafa
I am investigating the use of degrafa as an SVG viewer. A google
search revealed that in february 2009 there was mention of a SVG to
degrafa converter, but I have not found any source code of this
converter.

I am wondering what options I have for displaying SVG data using
degrafa.
Is there a SVG -> degrafa converter?
Does degrafa have a SVG import/viewing function?
Does anyone have any suggestions on how to go about this?

Kind regards,
Matthijs

Elisheva

unread,
Jan 17, 2010, 3:54:04 PM1/17/10
to Degrafa
Hi,

To load svg into degrapha.

You load the svg file with URLRequest, and then you need to parse it.
Since it is xml-like , we want to look for the path-tag which has the
important info for us.

When we have it, we put it in to a path class, which loads into a
geometryCollection, which loads into a
Degrapha surface.

To load the file:

var request:URLRequest=new URLRequest("svg_file_name.svg");
var loaderSVG:URLLoader=new URLLoader(request);
loaderSVG.addEventListener(Event.COMPLETE, parseSVG);
loaderSVG.addEventListener(IOErrorEvent.IO_ERROR, errorLoadFile);

To parse recursively:

Private function parseSVG(e:Event):void {
var xmlData: XML = new XML(e.target.data);
for each ( var element:XML in xmlData.elements ( ) ) {
if ((element.localName() == 'path') || (element.localName() ==
'Path')){
var newPath:Path = new Path();
var newGc:GeometryGroup = new GeometryGroup();
// if you want to use the fill color in the file
var color:uint = getColor4Style(element.@style);
if (color != 0x000000) {
newPath.fill = new SolidFill(color);
}
newPath.data = element.@d;
newGc.geometryCollection.addItem(newPath);

// if you want to add interactivity
newGc.addEventListener(MouseEvent.ROLL_OVER,onRollOver);
newGc.addEventListener(MouseEvent.ROLL_OUT,onRollOut);
newGc.addEventListener(MouseEvent.CLICK,onClick);
newGc.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
GeometryGroup.geometryCollection.addItem(newGc);
newGc.target = GeometryGroup;
}
getDataFromXML( element);
}


private function getColor4Style(s:String):uint {
var start:int;
if((s=="none") || (s=="") || (s=='fill:none;')) {
return 0x000000;
} else
if (s.charAt(5)=="#") {
s = s.substring(6,12);

if(s.length<6) {
s = s.charAt(0)+s.charAt(0)+s.charAt(1)+s.charAt(1)+s.charAt
(2)+s.charAt(2);
}
} else
// if the # is somewhere else
if ((start=s.indexOf('#')) != -1) {
s = s.substring(start+1,start+6);
if(s.length<6) {
s = s.charAt(0)+s.charAt(0)+s.charAt(1)+s.charAt(1)+s.charAt
(2)+s.charAt(2);
}
}
return new Number("0x" + s);
}


This puts the svg file in your degrapha surface. Not sure why you want
to use degrapha as a viewer because there are other svg viewers (just
google them).

Hope this helps

Elisheva

Reply all
Reply to author
Forward
0 new messages