1
package latexDraw.parsers.svg.elements;
3
import latexDraw.parsers.svg.MalformedSVGDocument;
4
import latexDraw.parsers.svg.SVGAttributes;
5
import latexDraw.parsers.svg.SVGDocument;
6
import latexDraw.parsers.svg.SVGElements;
7
import latexDraw.parsers.svg.elements.path.*;
9
import org.w3c.dom.Node;
12
* Defines the SVG tag <code>path</code>.<br>
14
* This file is part of LaTeXDraw.<br>
15
* Copyright (c) 2005-2008 Arnaud BLOUIN<br>
17
* LaTeXDraw is free software; you can redistribute it and/or modify
18
* it under the terms of the GNU General Public License as published by
19
* the Free Software Foundation; either version 2 of the License, or
20
* (at your option) any later version.<br>
22
* LaTeXDraw is distributed without any warranty; without even the
23
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
24
* PURPOSE. See the GNU General Public License for more details.<br>
27
* @author Arnaud BLOUIN<br>
31
public class SVGPathElement extends SVGElement
34
* See {@link SVGElement#SVGElement(Node, SVGElement)}.
35
* @throws MalformedSVGDocument If the element is not well formed.
37
public SVGPathElement(Node n, SVGElement p) throws MalformedSVGDocument
45
* Creates an empty SVG path element.
46
* @param owner The owner document.
49
public SVGPathElement(SVGDocument owner)
53
setAttribute(SVGAttributes.SVG_D, "");//$NON-NLS-1$
54
setNodeName(SVGElements.SVG_PATH);
60
* @return True if the path is a unique line.
63
public boolean isLine()
65
SVGPathSegList segList = getSegList();
67
return segList.size()==2 && segList.firstElement() instanceof SVGPathSegMoveto &&
68
segList.elementAt(1) instanceof SVGPathSegLineto ;
75
* @return True if the path is composed of lines and has a 'close path' segment at the end.
78
public boolean isLines()
80
SVGPathSegList segList = getSegList();
82
if(segList.size()<3 || !(segList.firstElement() instanceof SVGPathSegMoveto))
88
for(i=1, size=segList.size()-1; i<size && ok; i++)
89
if(!(segList.elementAt(i) instanceof SVGPathSegLineto))
98
* @return True if the path is composed of lines and has a 'close path' segment at the end.
101
public boolean isPolygon()
103
SVGPathSegList segList = getSegList();
105
if(segList.isEmpty() || !(segList.firstElement() instanceof SVGPathSegMoveto))
111
for(i=1, size=segList.size()-1; i<size && ok; i++)
112
if(!(segList.elementAt(i) instanceof SVGPathSegLineto))
115
if(!(segList.lastElement() instanceof SVGPathSegClosePath))
124
* The definition of the outline of a shape.
125
* @return The path data (in postscript) from the segList attribute.
128
public String getPathData()
130
return getAttribute(getUsablePrefix()+SVGAttributes.SVG_D);
135
public boolean checkAttributes()
137
return getPathData()!=null;
143
public boolean enableRendering()
145
return getPathData().length()>0;
150
* @return the segList.
153
public SVGPathSegList getSegList()
155
return new SVGPathSegList(getPathData());
161
* Sets the path data.
162
* @param path The path to set.
165
public void setPathData(SVGPathSegList path)
168
setAttribute(SVGAttributes.SVG_D, path.toString());