~ubuntu-branches/debian/squeeze/latexdraw/squeeze

« back to all changes in this revision

Viewing changes to latexDraw/generators/svg/LDrawingSVGGenerator.java

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2009-05-03 23:49:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090503234935-cls7n48x018g0vk2
Tags: upstream-2.0.2+1
ImportĀ upstreamĀ versionĀ 2.0.2+1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package latexDraw.generators.svg;
 
2
 
 
3
import java.util.Vector;
 
4
 
 
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;
 
13
 
 
14
import org.w3c.dom.NodeList;
 
15
 
 
16
/**
 
17
 * Defines a SVG generator for a drawing.<br>
 
18
 *<br>
 
19
 * This file is part of LaTeXDraw.<br>
 
20
 * Copyright (c) 2005-2008 Arnaud BLOUIN<br>
 
21
 *<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>
 
26
 *<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>
 
30
 *<br>
 
31
 * 11/11/07<br>
 
32
 * @author Arnaud BLOUIN<br>
 
33
 * @version 0.1<br>
 
34
 */
 
35
public class LDrawingSVGGenerator extends LShapeSVGGenerator
 
36
{
 
37
 
 
38
        public LDrawingSVGGenerator(Draw f)
 
39
        {
 
40
                super(f);
 
41
        }
 
42
 
 
43
 
 
44
        
 
45
        public LDrawingSVGGenerator(SVGGElement elt)
 
46
        {
 
47
                this(elt, true);
 
48
        }
 
49
        
 
50
        
 
51
        
 
52
        /**
 
53
         * Creates a drawing from a G element.
 
54
         * @param elt The source element.
 
55
         * @since 2.0.0
 
56
         */
 
57
        public LDrawingSVGGenerator(SVGGElement elt, boolean withTransformation)
 
58
        {
 
59
                this(new Draw(true, true));
 
60
                
 
61
                if(elt==null)
 
62
                        throw new IllegalArgumentException();
 
63
                
 
64
                NodeList nl = elt.getChildNodes();
 
65
                Figure f;
 
66
                Draw d = (Draw)getShape();
 
67
                
 
68
                if(nl.getLength()<2)
 
69
                        throw new IllegalArgumentException();
 
70
                
 
71
                for(int i=0, size=nl.getLength(); i<size; i++)
 
72
                {
 
73
                        f = LaTeXDrawFiguresFactory.createFigure((SVGElement)nl.item(i), withTransformation);
 
74
                        
 
75
                        if(f!=null)
 
76
                                d.addFigure(f);
 
77
                }
 
78
                
 
79
                setNumber(elt);
 
80
        }
 
81
 
 
82
 
 
83
        
 
84
        @Override
 
85
        public SVGElement toSVG(SVGDocument doc)
 
86
        {
 
87
                if(doc==null)
 
88
                        return null;
 
89
                
 
90
                Draw d = (Draw)shape;
 
91
                
 
92
                if(d.isDrawFigures() && !d.isEmpty())
 
93
                {
 
94
                         SVGElement root = new SVGGElement(doc);
 
95
                         Vector<Figure> figures = d.getFigures();
 
96
                         
 
97
                         root.setAttribute(LaTeXDrawNamespace.LATEXDRAW_NAMESPACE+':'+LaTeXDrawNamespace.XML_TYPE, LaTeXDrawNamespace.XML_TYPE_DRAWING);
 
98
                         root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
 
99
                         
 
100
                         for(Figure f : figures)
 
101
                                 root.appendChild(SVGShapesFactory.createSVGElement(f, doc));
 
102
                         
 
103
                         return root;
 
104
                }                
 
105
                 
 
106
                return null;
 
107
        }
 
108
}