TransformListParserpublic class TransformListParser extends NumberParser The TransformListParser class converts attributes
conforming to the SVG
transform
syntax into AffineTransform objects. |
Fields Summary |
---|
private com.sun.perseus.j2d.Transform | transformCaptures the transform built by this parser |
Methods Summary |
---|
protected final void | parseMatrix()Parses a matrix transform. 'm' is assumed to be the current character.
current = read();
// Parse 'atrix wsp? ( wsp?'
if (current != 'a") {
throw new IllegalArgumentException();
}
current = read();
if (current != 't") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'r") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'i") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'x") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
if (current != '(") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
float a = parseNumber();
skipCommaSpaces();
float b = parseNumber();
skipCommaSpaces();
float c = parseNumber();
skipCommaSpaces();
float d = parseNumber();
skipCommaSpaces();
float e = parseNumber();
skipCommaSpaces();
float f = parseNumber();
skipSpaces();
if (current != ')") {
throw new IllegalArgumentException("Expected ')' and got >"
+ (char) current + "<");
}
transform.mMultiply(new Transform(a, b, c, d, e, f));
| protected final void | parseRotate()Parses a rotate transform. 'r' is assumed to be the current character.
current = read();
// Parse 'otate wsp? ( wsp?'
if (current != 'o") {
throw new IllegalArgumentException();
}
current = read();
if (current != 't") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'a") {
throw new IllegalArgumentException();
}
current = read();
if (current != 't") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'e") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
if (current != '(") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
float theta = parseNumber();
skipSpaces();
switch (current) {
case ')":
transform.mRotate(theta);
return;
case ',":
current = read();
skipSpaces();
default:
// nothing.
}
float cx = parseNumber();
skipCommaSpaces();
float cy = parseNumber();
skipSpaces();
if (current != ')") {
throw new IllegalArgumentException();
}
transform.mTranslate(cx, cy);
transform.mRotate(theta);
transform.mTranslate(-cx, -cy);
| protected final void | parseScale()Parses a scale transform. 'c' is assumed to be the current character.
current = read();
// Parse 'ale wsp? ( wsp?'
if (current != 'a") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'l") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'e") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
if (current != '(") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
float sx = parseNumber();
skipSpaces();
switch (current) {
case ')":
transform.mScale(sx);
return;
case ',":
current = read();
skipSpaces();
default:
// nothing
}
float sy = parseNumber();
skipSpaces();
if (current != ')") {
throw new IllegalArgumentException();
}
transform.mScale(sx, sy);
| protected final void | parseSkew()Parses a skew transform. 'e' is assumed to be the current character.
current = read();
// Parse 'ew[XY] wsp? ( wsp?'
if (current != 'e") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'w") {
throw new IllegalArgumentException();
}
current = read();
boolean skewX = false;
switch (current) {
case 'X":
skewX = true;
case 'Y":
break;
default:
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
if (current != '(") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
float sk = parseNumber();
skipSpaces();
if (current != ')") {
throw new IllegalArgumentException();
}
float tan = MathSupport.tan(MathSupport.toRadians(sk));
if (skewX) {
Transform shear = new Transform(1, 0, tan, 1, 0, 0);
transform.mMultiply(shear);
// transform.shear(tan, 0);
} else {
Transform shear = new Transform(1, tan, 0, 1, 0, 0);
transform.mMultiply(shear);
// transform.shear(0, tan);
}
| public com.sun.perseus.j2d.Transform | parseTransformList(java.lang.String txfStr)
setString(txfStr);
transform = new Transform(1, 0, 0, 1, 0, 0);
// Parse leading wsp*
current = read();
skipSpaces();
// Now, iterate on 'transforms?'
loop2: for (;;) {
switch (current) {
case 'm":
parseMatrix();
break;
case 'r":
parseRotate();
break;
case 't":
parseTranslate();
break;
case 's":
current = read();
switch (current) {
case 'c":
parseScale();
break;
case 'k":
parseSkew();
break;
default:
throw new IllegalArgumentException();
}
break;
case -1:
break loop2;
default:
throw new IllegalArgumentException();
}
current = read();
skipCommaSpaces();
}
return transform;
| protected final void | parseTranslate()Parses a translate transform. 't' is assumed to be
the current character.
current = read();
// Parse 'ranslate wsp? ( wsp?'
if (current != 'r") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'a") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'n") {
throw new IllegalArgumentException();
}
current = read();
if (current != 's") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'l") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'a") {
throw new IllegalArgumentException();
}
current = read();
if (current != 't") {
throw new IllegalArgumentException();
}
current = read();
if (current != 'e") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
if (current != '(") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
float tx = parseNumber();
skipSpaces();
switch (current) {
case ')":
transform.mTranslate(tx, 0);
return;
case ',":
current = read();
skipSpaces();
default:
// nothing
}
float ty = parseNumber();
skipSpaces();
if (current != ')") {
throw new IllegalArgumentException();
}
transform.mTranslate(tx, ty);
|
|