1
package latexDraw.generators.svg;
3
import java.util.Vector;
5
import latexDraw.figures.Draw;
6
import latexDraw.figures.Figure;
7
import latexDraw.parsers.svg.LaTeXDrawFiguresFactory;
8
import latexDraw.parsers.svg.SVGAttributes;
9
import latexDraw.parsers.svg.SVGDocument;
10
import latexDraw.parsers.svg.elements.SVGElement;
11
import latexDraw.parsers.svg.elements.SVGGElement;
12
import latexDraw.util.LaTeXDrawNamespace;
14
import org.w3c.dom.NodeList;
17
* Defines a SVG generator for a drawing.<br>
19
* This file is part of LaTeXDraw.<br>
20
* Copyright (c) 2005-2008 Arnaud BLOUIN<br>
22
* LaTeXDraw is free software; you can redistribute it and/or modify
23
* it under the terms of the GNU General Public License as published by
24
* the Free Software Foundation; either version 2 of the License, or
25
* (at your option) any later version.<br>
27
* LaTeXDraw is distributed without any warranty; without even the
28
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
29
* PURPOSE. See the GNU General Public License for more details.<br>
32
* @author Arnaud BLOUIN<br>
35
public class LDrawingSVGGenerator extends LShapeSVGGenerator
38
public LDrawingSVGGenerator(Draw f)
45
public LDrawingSVGGenerator(SVGGElement elt)
53
* Creates a drawing from a G element.
54
* @param elt The source element.
57
public LDrawingSVGGenerator(SVGGElement elt, boolean withTransformation)
59
this(new Draw(true, true));
62
throw new IllegalArgumentException();
64
NodeList nl = elt.getChildNodes();
66
Draw d = (Draw)getShape();
69
throw new IllegalArgumentException();
71
for(int i=0, size=nl.getLength(); i<size; i++)
73
f = LaTeXDrawFiguresFactory.createFigure((SVGElement)nl.item(i), withTransformation);
85
public SVGElement toSVG(SVGDocument doc)
92
if(d.isDrawFigures() && !d.isEmpty())
94
SVGElement root = new SVGGElement(doc);
95
Vector<Figure> figures = d.getFigures();
97
root.setAttribute(LaTeXDrawNamespace.LATEXDRAW_NAMESPACE+':'+LaTeXDrawNamespace.XML_TYPE, LaTeXDrawNamespace.XML_TYPE_DRAWING);
98
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
100
for(Figure f : figures)
101
root.appendChild(SVGShapesFactory.createSVGElement(f, doc));