--- a/jdk/src/share/classes/sun/java2d/pisces/TransformingPathConsumer2D.java Thu Feb 03 19:15:30 2011 -0800
+++ b/jdk/src/share/classes/sun/java2d/pisces/TransformingPathConsumer2D.java Tue Feb 08 09:22:49 2011 -0500
@@ -28,7 +28,7 @@
import sun.awt.geom.PathConsumer2D;
import java.awt.geom.AffineTransform;
-public class TransformingPathConsumer2D {
+final class TransformingPathConsumer2D {
public static PathConsumer2D
transformConsumer(PathConsumer2D out,
AffineTransform at)
@@ -50,17 +50,72 @@
return new TranslateFilter(out, Mxt, Myt);
}
} else {
- return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);
+ if (Mxt == 0f && Myt == 0f) {
+ return new DeltaScaleFilter(out, Mxx, Myy);
+ } else {
+ return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);
+ }
}
+ } else if (Mxt == 0f && Myt == 0f) {
+ return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
} else {
return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt);
}
}
- static class TranslateFilter implements PathConsumer2D {
- PathConsumer2D out;
- float tx;
- float ty;
+ public static PathConsumer2D
+ deltaTransformConsumer(PathConsumer2D out,
+ AffineTransform at)
+ {
+ if (at == null) {
+ return out;
+ }
+ float Mxx = (float) at.getScaleX();
+ float Mxy = (float) at.getShearX();
+ float Myx = (float) at.getShearY();
+ float Myy = (float) at.getScaleY();
+ if (Mxy == 0f && Myx == 0f) {
+ if (Mxx == 1f && Myy == 1f) {
+ return out;
+ } else {
+ return new DeltaScaleFilter(out, Mxx, Myy);
+ }
+ } else {
+ return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
+ }
+ }
+
+ public static PathConsumer2D
+ inverseDeltaTransformConsumer(PathConsumer2D out,
+ AffineTransform at)
+ {
+ if (at == null) {
+ return out;
+ }
+ float Mxx = (float) at.getScaleX();
+ float Mxy = (float) at.getShearX();
+ float Myx = (float) at.getShearY();
+ float Myy = (float) at.getScaleY();
+ if (Mxy == 0f && Myx == 0f) {
+ if (Mxx == 1f && Myy == 1f) {
+ return out;
+ } else {
+ return new DeltaScaleFilter(out, 1.0f/Mxx, 1.0f/Myy);
+ }
+ } else {
+ float det = Mxx * Myy - Mxy * Myx;
+ return new DeltaTransformFilter(out,
+ Myy / det,
+ -Mxy / det,
+ -Myx / det,
+ Mxx / det);
+ }
+ }
+
+ static final class TranslateFilter implements PathConsumer2D {
+ private final PathConsumer2D out;
+ private final float tx;
+ private final float ty;
TranslateFilter(PathConsumer2D out,
float tx, float ty)
@@ -107,12 +162,12 @@
}
}
- static class ScaleFilter implements PathConsumer2D {
- PathConsumer2D out;
- float sx;
- float sy;
- float tx;
- float ty;
+ static final class ScaleFilter implements PathConsumer2D {
+ private final PathConsumer2D out;
+ private final float sx;
+ private final float sy;
+ private final float tx;
+ private final float ty;
ScaleFilter(PathConsumer2D out,
float sx, float sy, float tx, float ty)
@@ -161,14 +216,14 @@
}
}
- static class TransformFilter implements PathConsumer2D {
- PathConsumer2D out;
- float Mxx;
- float Mxy;
- float Mxt;
- float Myx;
- float Myy;
- float Myt;
+ static final class TransformFilter implements PathConsumer2D {
+ private final PathConsumer2D out;
+ private final float Mxx;
+ private final float Mxy;
+ private final float Mxt;
+ private final float Myx;
+ private final float Myy;
+ private final float Myt;
TransformFilter(PathConsumer2D out,
float Mxx, float Mxy, float Mxt,
@@ -226,4 +281,113 @@
return 0;
}
}
+
+ static final class DeltaScaleFilter implements PathConsumer2D {
+ private final float sx, sy;
+ private final PathConsumer2D out;
+
+ public DeltaScaleFilter(PathConsumer2D out, float Mxx, float Myy) {
+ sx = Mxx;
+ sy = Myy;
+ this.out = out;
+ }
+
+ public void moveTo(float x0, float y0) {
+ out.moveTo(x0 * sx, y0 * sy);
+ }
+
+ public void lineTo(float x1, float y1) {
+ out.lineTo(x1 * sx, y1 * sy);
+ }
+
+ public void quadTo(float x1, float y1,
+ float x2, float y2)
+ {
+ out.quadTo(x1 * sx, y1 * sy,
+ x2 * sx, y2 * sy);
+ }
+
+ public void curveTo(float x1, float y1,
+ float x2, float y2,
+ float x3, float y3)
+ {
+ out.curveTo(x1 * sx, y1 * sy,
+ x2 * sx, y2 * sy,
+ x3 * sx, y3 * sy);
+ }
+
+ public void closePath() {
+ out.closePath();
+ }
+
+ public void pathDone() {
+ out.pathDone();
+ }
+
+ public long getNativeConsumer() {
+ return 0;
+ }
+ }
+
+ static final class DeltaTransformFilter implements PathConsumer2D {
+ private PathConsumer2D out;
+ private final float Mxx;
+ private final float Mxy;
+ private final float Myx;
+ private final float Myy;
+
+ DeltaTransformFilter(PathConsumer2D out,
+ float Mxx, float Mxy,
+ float Myx, float Myy)
+ {
+ this.out = out;
+ this.Mxx = Mxx;
+ this.Mxy = Mxy;
+ this.Myx = Myx;
+ this.Myy = Myy;
+ }
+
+ public void moveTo(float x0, float y0) {
+ out.moveTo(x0 * Mxx + y0 * Mxy,
+ x0 * Myx + y0 * Myy);
+ }
+
+ public void lineTo(float x1, float y1) {
+ out.lineTo(x1 * Mxx + y1 * Mxy,
+ x1 * Myx + y1 * Myy);
+ }
+
+ public void quadTo(float x1, float y1,
+ float x2, float y2)
+ {
+ out.quadTo(x1 * Mxx + y1 * Mxy,
+ x1 * Myx + y1 * Myy,
+ x2 * Mxx + y2 * Mxy,
+ x2 * Myx + y2 * Myy);
+ }
+
+ public void curveTo(float x1, float y1,
+ float x2, float y2,
+ float x3, float y3)
+ {
+ out.curveTo(x1 * Mxx + y1 * Mxy,
+ x1 * Myx + y1 * Myy,
+ x2 * Mxx + y2 * Mxy,
+ x2 * Myx + y2 * Myy,
+ x3 * Mxx + y3 * Mxy,
+ x3 * Myx + y3 * Myy);
+ }
+
+ public void closePath() {
+ out.closePath();
+ }
+
+ public void pathDone() {
+ out.pathDone();
+ }
+
+ public long getNativeConsumer() {
+ return 0;
+ }
+ }
}