2956N/A/*
3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2956N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2956N/A *
2956N/A * This code is free software; you can redistribute it and/or modify it
2956N/A * under the terms of the GNU General Public License version 2 only, as
2956N/A * published by the Free Software Foundation. Oracle designates this
2956N/A * particular file as subject to the "Classpath" exception as provided
2956N/A * by Oracle in the LICENSE file that accompanied this code.
2956N/A *
2956N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2956N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2956N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2956N/A * version 2 for more details (a copy is included in the LICENSE file that
2956N/A * accompanied this code).
2956N/A *
2956N/A * You should have received a copy of the GNU General Public License version
2956N/A * 2 along with this work; if not, write to the Free Software Foundation,
2956N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2956N/A *
2956N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2956N/A * or visit www.oracle.com if you need additional information or have any
2956N/A * questions.
2956N/A */
2956N/A
2956N/Apackage sun.java2d.pisces;
2956N/A
2956N/Aimport sun.awt.geom.PathConsumer2D;
2956N/Aimport java.awt.geom.AffineTransform;
2956N/A
3444N/Afinal class TransformingPathConsumer2D {
2956N/A public static PathConsumer2D
2956N/A transformConsumer(PathConsumer2D out,
2956N/A AffineTransform at)
2956N/A {
2956N/A if (at == null) {
2956N/A return out;
2956N/A }
2956N/A float Mxx = (float) at.getScaleX();
2956N/A float Mxy = (float) at.getShearX();
2956N/A float Mxt = (float) at.getTranslateX();
2956N/A float Myx = (float) at.getShearY();
2956N/A float Myy = (float) at.getScaleY();
2956N/A float Myt = (float) at.getTranslateY();
2956N/A if (Mxy == 0f && Myx == 0f) {
2956N/A if (Mxx == 1f && Myy == 1f) {
2956N/A if (Mxt == 0f && Myt == 0f) {
2956N/A return out;
2956N/A } else {
2956N/A return new TranslateFilter(out, Mxt, Myt);
2956N/A }
2956N/A } else {
3444N/A if (Mxt == 0f && Myt == 0f) {
3444N/A return new DeltaScaleFilter(out, Mxx, Myy);
3444N/A } else {
3444N/A return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);
3444N/A }
2956N/A }
3444N/A } else if (Mxt == 0f && Myt == 0f) {
3444N/A return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
2956N/A } else {
2956N/A return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt);
2956N/A }
2956N/A }
2956N/A
3444N/A public static PathConsumer2D
3444N/A deltaTransformConsumer(PathConsumer2D out,
3444N/A AffineTransform at)
3444N/A {
3444N/A if (at == null) {
3444N/A return out;
3444N/A }
3444N/A float Mxx = (float) at.getScaleX();
3444N/A float Mxy = (float) at.getShearX();
3444N/A float Myx = (float) at.getShearY();
3444N/A float Myy = (float) at.getScaleY();
3444N/A if (Mxy == 0f && Myx == 0f) {
3444N/A if (Mxx == 1f && Myy == 1f) {
3444N/A return out;
3444N/A } else {
3444N/A return new DeltaScaleFilter(out, Mxx, Myy);
3444N/A }
3444N/A } else {
3444N/A return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
3444N/A }
3444N/A }
3444N/A
3444N/A public static PathConsumer2D
3444N/A inverseDeltaTransformConsumer(PathConsumer2D out,
3444N/A AffineTransform at)
3444N/A {
3444N/A if (at == null) {
3444N/A return out;
3444N/A }
3444N/A float Mxx = (float) at.getScaleX();
3444N/A float Mxy = (float) at.getShearX();
3444N/A float Myx = (float) at.getShearY();
3444N/A float Myy = (float) at.getScaleY();
3444N/A if (Mxy == 0f && Myx == 0f) {
3444N/A if (Mxx == 1f && Myy == 1f) {
3444N/A return out;
3444N/A } else {
3444N/A return new DeltaScaleFilter(out, 1.0f/Mxx, 1.0f/Myy);
3444N/A }
3444N/A } else {
3444N/A float det = Mxx * Myy - Mxy * Myx;
3444N/A return new DeltaTransformFilter(out,
3444N/A Myy / det,
3444N/A -Mxy / det,
3444N/A -Myx / det,
3444N/A Mxx / det);
3444N/A }
3444N/A }
3444N/A
3444N/A static final class TranslateFilter implements PathConsumer2D {
3444N/A private final PathConsumer2D out;
3444N/A private final float tx;
3444N/A private final float ty;
2956N/A
2956N/A TranslateFilter(PathConsumer2D out,
2956N/A float tx, float ty)
2956N/A {
2956N/A this.out = out;
2956N/A this.tx = tx;
2956N/A this.ty = ty;
2956N/A }
2956N/A
2956N/A public void moveTo(float x0, float y0) {
2956N/A out.moveTo(x0 + tx, y0 + ty);
2956N/A }
2956N/A
2956N/A public void lineTo(float x1, float y1) {
2956N/A out.lineTo(x1 + tx, y1 + ty);
2956N/A }
2956N/A
2956N/A public void quadTo(float x1, float y1,
2956N/A float x2, float y2)
2956N/A {
2956N/A out.quadTo(x1 + tx, y1 + ty,
2956N/A x2 + tx, y2 + ty);
2956N/A }
2956N/A
2956N/A public void curveTo(float x1, float y1,
2956N/A float x2, float y2,
2956N/A float x3, float y3)
2956N/A {
2956N/A out.curveTo(x1 + tx, y1 + ty,
2956N/A x2 + tx, y2 + ty,
2956N/A x3 + tx, y3 + ty);
2956N/A }
2956N/A
2956N/A public void closePath() {
2956N/A out.closePath();
2956N/A }
2956N/A
2956N/A public void pathDone() {
2956N/A out.pathDone();
2956N/A }
2956N/A
2956N/A public long getNativeConsumer() {
2956N/A return 0;
2956N/A }
2956N/A }
2956N/A
3444N/A static final class ScaleFilter implements PathConsumer2D {
3444N/A private final PathConsumer2D out;
3444N/A private final float sx;
3444N/A private final float sy;
3444N/A private final float tx;
3444N/A private final float ty;
2956N/A
2956N/A ScaleFilter(PathConsumer2D out,
2956N/A float sx, float sy, float tx, float ty)
2956N/A {
2956N/A this.out = out;
2956N/A this.sx = sx;
2956N/A this.sy = sy;
2956N/A this.tx = tx;
2956N/A this.ty = ty;
2956N/A }
2956N/A
2956N/A public void moveTo(float x0, float y0) {
2956N/A out.moveTo(x0 * sx + tx, y0 * sy + ty);
2956N/A }
2956N/A
2956N/A public void lineTo(float x1, float y1) {
2956N/A out.lineTo(x1 * sx + tx, y1 * sy + ty);
2956N/A }
2956N/A
2956N/A public void quadTo(float x1, float y1,
2956N/A float x2, float y2)
2956N/A {
2956N/A out.quadTo(x1 * sx + tx, y1 * sy + ty,
2956N/A x2 * sx + tx, y2 * sy + ty);
2956N/A }
2956N/A
2956N/A public void curveTo(float x1, float y1,
2956N/A float x2, float y2,
2956N/A float x3, float y3)
2956N/A {
2956N/A out.curveTo(x1 * sx + tx, y1 * sy + ty,
2956N/A x2 * sx + tx, y2 * sy + ty,
2956N/A x3 * sx + tx, y3 * sy + ty);
2956N/A }
2956N/A
2956N/A public void closePath() {
2956N/A out.closePath();
2956N/A }
2956N/A
2956N/A public void pathDone() {
2956N/A out.pathDone();
2956N/A }
2956N/A
2956N/A public long getNativeConsumer() {
2956N/A return 0;
2956N/A }
2956N/A }
2956N/A
3444N/A static final class TransformFilter implements PathConsumer2D {
3444N/A private final PathConsumer2D out;
3444N/A private final float Mxx;
3444N/A private final float Mxy;
3444N/A private final float Mxt;
3444N/A private final float Myx;
3444N/A private final float Myy;
3444N/A private final float Myt;
2956N/A
2956N/A TransformFilter(PathConsumer2D out,
2956N/A float Mxx, float Mxy, float Mxt,
2956N/A float Myx, float Myy, float Myt)
2956N/A {
2956N/A this.out = out;
2956N/A this.Mxx = Mxx;
2956N/A this.Mxy = Mxy;
2956N/A this.Mxt = Mxt;
2956N/A this.Myx = Myx;
2956N/A this.Myy = Myy;
2956N/A this.Myt = Myt;
2956N/A }
2956N/A
2956N/A public void moveTo(float x0, float y0) {
2956N/A out.moveTo(x0 * Mxx + y0 * Mxy + Mxt,
2956N/A x0 * Myx + y0 * Myy + Myt);
2956N/A }
2956N/A
2956N/A public void lineTo(float x1, float y1) {
2956N/A out.lineTo(x1 * Mxx + y1 * Mxy + Mxt,
2956N/A x1 * Myx + y1 * Myy + Myt);
2956N/A }
2956N/A
2956N/A public void quadTo(float x1, float y1,
2956N/A float x2, float y2)
2956N/A {
2956N/A out.quadTo(x1 * Mxx + y1 * Mxy + Mxt,
2956N/A x1 * Myx + y1 * Myy + Myt,
2956N/A x2 * Mxx + y2 * Mxy + Mxt,
2956N/A x2 * Myx + y2 * Myy + Myt);
2956N/A }
2956N/A
2956N/A public void curveTo(float x1, float y1,
2956N/A float x2, float y2,
2956N/A float x3, float y3)
2956N/A {
2956N/A out.curveTo(x1 * Mxx + y1 * Mxy + Mxt,
2956N/A x1 * Myx + y1 * Myy + Myt,
2956N/A x2 * Mxx + y2 * Mxy + Mxt,
2956N/A x2 * Myx + y2 * Myy + Myt,
2956N/A x3 * Mxx + y3 * Mxy + Mxt,
2956N/A x3 * Myx + y3 * Myy + Myt);
2956N/A }
2956N/A
2956N/A public void closePath() {
2956N/A out.closePath();
2956N/A }
2956N/A
2956N/A public void pathDone() {
2956N/A out.pathDone();
2956N/A }
2956N/A
2956N/A public long getNativeConsumer() {
2956N/A return 0;
2956N/A }
2956N/A }
3444N/A
3444N/A static final class DeltaScaleFilter implements PathConsumer2D {
3444N/A private final float sx, sy;
3444N/A private final PathConsumer2D out;
3444N/A
3444N/A public DeltaScaleFilter(PathConsumer2D out, float Mxx, float Myy) {
3444N/A sx = Mxx;
3444N/A sy = Myy;
3444N/A this.out = out;
3444N/A }
3444N/A
3444N/A public void moveTo(float x0, float y0) {
3444N/A out.moveTo(x0 * sx, y0 * sy);
3444N/A }
3444N/A
3444N/A public void lineTo(float x1, float y1) {
3444N/A out.lineTo(x1 * sx, y1 * sy);
3444N/A }
3444N/A
3444N/A public void quadTo(float x1, float y1,
3444N/A float x2, float y2)
3444N/A {
3444N/A out.quadTo(x1 * sx, y1 * sy,
3444N/A x2 * sx, y2 * sy);
3444N/A }
3444N/A
3444N/A public void curveTo(float x1, float y1,
3444N/A float x2, float y2,
3444N/A float x3, float y3)
3444N/A {
3444N/A out.curveTo(x1 * sx, y1 * sy,
3444N/A x2 * sx, y2 * sy,
3444N/A x3 * sx, y3 * sy);
3444N/A }
3444N/A
3444N/A public void closePath() {
3444N/A out.closePath();
3444N/A }
3444N/A
3444N/A public void pathDone() {
3444N/A out.pathDone();
3444N/A }
3444N/A
3444N/A public long getNativeConsumer() {
3444N/A return 0;
3444N/A }
3444N/A }
3444N/A
3444N/A static final class DeltaTransformFilter implements PathConsumer2D {
3444N/A private PathConsumer2D out;
3444N/A private final float Mxx;
3444N/A private final float Mxy;
3444N/A private final float Myx;
3444N/A private final float Myy;
3444N/A
3444N/A DeltaTransformFilter(PathConsumer2D out,
3444N/A float Mxx, float Mxy,
3444N/A float Myx, float Myy)
3444N/A {
3444N/A this.out = out;
3444N/A this.Mxx = Mxx;
3444N/A this.Mxy = Mxy;
3444N/A this.Myx = Myx;
3444N/A this.Myy = Myy;
3444N/A }
3444N/A
3444N/A public void moveTo(float x0, float y0) {
3444N/A out.moveTo(x0 * Mxx + y0 * Mxy,
3444N/A x0 * Myx + y0 * Myy);
3444N/A }
3444N/A
3444N/A public void lineTo(float x1, float y1) {
3444N/A out.lineTo(x1 * Mxx + y1 * Mxy,
3444N/A x1 * Myx + y1 * Myy);
3444N/A }
3444N/A
3444N/A public void quadTo(float x1, float y1,
3444N/A float x2, float y2)
3444N/A {
3444N/A out.quadTo(x1 * Mxx + y1 * Mxy,
3444N/A x1 * Myx + y1 * Myy,
3444N/A x2 * Mxx + y2 * Mxy,
3444N/A x2 * Myx + y2 * Myy);
3444N/A }
3444N/A
3444N/A public void curveTo(float x1, float y1,
3444N/A float x2, float y2,
3444N/A float x3, float y3)
3444N/A {
3444N/A out.curveTo(x1 * Mxx + y1 * Mxy,
3444N/A x1 * Myx + y1 * Myy,
3444N/A x2 * Mxx + y2 * Mxy,
3444N/A x2 * Myx + y2 * Myy,
3444N/A x3 * Mxx + y3 * Mxy,
3444N/A x3 * Myx + y3 * Myy);
3444N/A }
3444N/A
3444N/A public void closePath() {
3444N/A out.closePath();
3444N/A }
3444N/A
3444N/A public void pathDone() {
3444N/A out.pathDone();
3444N/A }
3444N/A
3444N/A public long getNativeConsumer() {
3444N/A return 0;
3444N/A }
3444N/A }
2956N/A}