use of com.xenoage.zong.symbols.path.ClosePath in project Zong by Xenoage.
the class SvgPathReader method read.
/**
* Creates a path from the given d attribute value of a SVG path element.
* The type of the path is implementation dependent.
* The path and its bounding rect is returned.
*/
public Path read() {
// parse commands
char tokenChar = '?';
String token = getNextToken();
Point2f p, cp1, cp2;
float x, y;
while (token != null) {
char nextTokenChar = token.charAt(0);
if (Character.isDigit(nextTokenChar) || nextTokenChar == '-' || nextTokenChar == '+') {
// number. reuse last command (if not 'M' or 'm' - then it is 'L' or 'l'. see SVG spec)
pos -= token.length();
if (tokenChar == 'M')
tokenChar = 'L';
else if (tokenChar == 'm')
tokenChar = 'l';
} else {
// next command
tokenChar = nextTokenChar;
}
switch(tokenChar) {
// MoveTo (absolute)
case 'M':
p = readPointAbs();
moveTo(p);
break;
// MoveTo (relative)
case 'm':
p = readPointRel();
moveTo(pCurrent.add(p));
break;
// ClosePath
case 'Z':
case 'z':
closePath();
break;
// LineTo (absolute)
case 'L':
p = readPointAbs();
lineTo(p);
break;
// LineTo (relative)
case 'l':
p = readPointRel();
lineTo(pCurrent.add(p));
break;
// Horizontal LineTo (absolute)
case 'H':
x = readCoordAbs();
lineTo(p(x, pCurrent.y));
break;
// Horizontal LineTo (relative)
case 'h':
x = readCoordRel();
lineTo(p(pCurrent.x + x, pCurrent.y));
break;
// Vertical LineTo (absolute)
case 'V':
y = readCoordAbs();
lineTo(p(pCurrent.x, y));
break;
// Vertical LineTo (relative)
case 'v':
y = readCoordRel();
lineTo(p(pCurrent.x, pCurrent.y + y));
break;
// Cubic CurveTo (absolute)
case 'C':
cp1 = readPointAbs();
cp2 = readPointAbs();
p = readPointAbs();
cubicCurveTo(cp1, cp2, p);
break;
// Cubic CurveTo (relative)
case 'c':
cp1 = readPointRel();
cp2 = readPointRel();
p = readPointRel();
cubicCurveTo(pCurrent.add(cp1), pCurrent.add(cp2), pCurrent.add(p));
break;
// Quadratic CurveTo (absolute)
case 'Q':
cp1 = readPointAbs();
p = readPointAbs();
quadraticCurveTo(cp1, p);
break;
// Quadratic CurveTo (relative)
case 'q':
cp1 = readPointRel();
p = readPointRel();
quadraticCurveTo(pCurrent.add(cp1), pCurrent.add(p));
break;
// not implemented commands
case 'T':
case 't':
case 'S':
case 's':
case 'A':
case 'a':
throw new IllegalStateException("SVG command \"" + token + "\" not implemented yet.");
// unknown command
default:
throw new IllegalStateException("Unknown SVG command: \"" + token + "\"");
}
token = getNextToken();
}
return new Path(elements);
}