Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/pisces/TransformingPathConsumer2D.java
38918 views
/*1* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pisces;2627import sun.awt.geom.PathConsumer2D;28import java.awt.geom.AffineTransform;2930final class TransformingPathConsumer2D {31public static PathConsumer2D32transformConsumer(PathConsumer2D out,33AffineTransform at)34{35if (at == null) {36return out;37}38float Mxx = (float) at.getScaleX();39float Mxy = (float) at.getShearX();40float Mxt = (float) at.getTranslateX();41float Myx = (float) at.getShearY();42float Myy = (float) at.getScaleY();43float Myt = (float) at.getTranslateY();44if (Mxy == 0f && Myx == 0f) {45if (Mxx == 1f && Myy == 1f) {46if (Mxt == 0f && Myt == 0f) {47return out;48} else {49return new TranslateFilter(out, Mxt, Myt);50}51} else {52if (Mxt == 0f && Myt == 0f) {53return new DeltaScaleFilter(out, Mxx, Myy);54} else {55return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);56}57}58} else if (Mxt == 0f && Myt == 0f) {59return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);60} else {61return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt);62}63}6465public static PathConsumer2D66deltaTransformConsumer(PathConsumer2D out,67AffineTransform at)68{69if (at == null) {70return out;71}72float Mxx = (float) at.getScaleX();73float Mxy = (float) at.getShearX();74float Myx = (float) at.getShearY();75float Myy = (float) at.getScaleY();76if (Mxy == 0f && Myx == 0f) {77if (Mxx == 1f && Myy == 1f) {78return out;79} else {80return new DeltaScaleFilter(out, Mxx, Myy);81}82} else {83return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);84}85}8687public static PathConsumer2D88inverseDeltaTransformConsumer(PathConsumer2D out,89AffineTransform at)90{91if (at == null) {92return out;93}94float Mxx = (float) at.getScaleX();95float Mxy = (float) at.getShearX();96float Myx = (float) at.getShearY();97float Myy = (float) at.getScaleY();98if (Mxy == 0f && Myx == 0f) {99if (Mxx == 1f && Myy == 1f) {100return out;101} else {102return new DeltaScaleFilter(out, 1.0f/Mxx, 1.0f/Myy);103}104} else {105float det = Mxx * Myy - Mxy * Myx;106return new DeltaTransformFilter(out,107Myy / det,108-Mxy / det,109-Myx / det,110Mxx / det);111}112}113114static final class TranslateFilter implements PathConsumer2D {115private final PathConsumer2D out;116private final float tx;117private final float ty;118119TranslateFilter(PathConsumer2D out,120float tx, float ty)121{122this.out = out;123this.tx = tx;124this.ty = ty;125}126127public void moveTo(float x0, float y0) {128out.moveTo(x0 + tx, y0 + ty);129}130131public void lineTo(float x1, float y1) {132out.lineTo(x1 + tx, y1 + ty);133}134135public void quadTo(float x1, float y1,136float x2, float y2)137{138out.quadTo(x1 + tx, y1 + ty,139x2 + tx, y2 + ty);140}141142public void curveTo(float x1, float y1,143float x2, float y2,144float x3, float y3)145{146out.curveTo(x1 + tx, y1 + ty,147x2 + tx, y2 + ty,148x3 + tx, y3 + ty);149}150151public void closePath() {152out.closePath();153}154155public void pathDone() {156out.pathDone();157}158159public long getNativeConsumer() {160return 0;161}162}163164static final class ScaleFilter implements PathConsumer2D {165private final PathConsumer2D out;166private final float sx;167private final float sy;168private final float tx;169private final float ty;170171ScaleFilter(PathConsumer2D out,172float sx, float sy, float tx, float ty)173{174this.out = out;175this.sx = sx;176this.sy = sy;177this.tx = tx;178this.ty = ty;179}180181public void moveTo(float x0, float y0) {182out.moveTo(x0 * sx + tx, y0 * sy + ty);183}184185public void lineTo(float x1, float y1) {186out.lineTo(x1 * sx + tx, y1 * sy + ty);187}188189public void quadTo(float x1, float y1,190float x2, float y2)191{192out.quadTo(x1 * sx + tx, y1 * sy + ty,193x2 * sx + tx, y2 * sy + ty);194}195196public void curveTo(float x1, float y1,197float x2, float y2,198float x3, float y3)199{200out.curveTo(x1 * sx + tx, y1 * sy + ty,201x2 * sx + tx, y2 * sy + ty,202x3 * sx + tx, y3 * sy + ty);203}204205public void closePath() {206out.closePath();207}208209public void pathDone() {210out.pathDone();211}212213public long getNativeConsumer() {214return 0;215}216}217218static final class TransformFilter implements PathConsumer2D {219private final PathConsumer2D out;220private final float Mxx;221private final float Mxy;222private final float Mxt;223private final float Myx;224private final float Myy;225private final float Myt;226227TransformFilter(PathConsumer2D out,228float Mxx, float Mxy, float Mxt,229float Myx, float Myy, float Myt)230{231this.out = out;232this.Mxx = Mxx;233this.Mxy = Mxy;234this.Mxt = Mxt;235this.Myx = Myx;236this.Myy = Myy;237this.Myt = Myt;238}239240public void moveTo(float x0, float y0) {241out.moveTo(x0 * Mxx + y0 * Mxy + Mxt,242x0 * Myx + y0 * Myy + Myt);243}244245public void lineTo(float x1, float y1) {246out.lineTo(x1 * Mxx + y1 * Mxy + Mxt,247x1 * Myx + y1 * Myy + Myt);248}249250public void quadTo(float x1, float y1,251float x2, float y2)252{253out.quadTo(x1 * Mxx + y1 * Mxy + Mxt,254x1 * Myx + y1 * Myy + Myt,255x2 * Mxx + y2 * Mxy + Mxt,256x2 * Myx + y2 * Myy + Myt);257}258259public void curveTo(float x1, float y1,260float x2, float y2,261float x3, float y3)262{263out.curveTo(x1 * Mxx + y1 * Mxy + Mxt,264x1 * Myx + y1 * Myy + Myt,265x2 * Mxx + y2 * Mxy + Mxt,266x2 * Myx + y2 * Myy + Myt,267x3 * Mxx + y3 * Mxy + Mxt,268x3 * Myx + y3 * Myy + Myt);269}270271public void closePath() {272out.closePath();273}274275public void pathDone() {276out.pathDone();277}278279public long getNativeConsumer() {280return 0;281}282}283284static final class DeltaScaleFilter implements PathConsumer2D {285private final float sx, sy;286private final PathConsumer2D out;287288public DeltaScaleFilter(PathConsumer2D out, float Mxx, float Myy) {289sx = Mxx;290sy = Myy;291this.out = out;292}293294public void moveTo(float x0, float y0) {295out.moveTo(x0 * sx, y0 * sy);296}297298public void lineTo(float x1, float y1) {299out.lineTo(x1 * sx, y1 * sy);300}301302public void quadTo(float x1, float y1,303float x2, float y2)304{305out.quadTo(x1 * sx, y1 * sy,306x2 * sx, y2 * sy);307}308309public void curveTo(float x1, float y1,310float x2, float y2,311float x3, float y3)312{313out.curveTo(x1 * sx, y1 * sy,314x2 * sx, y2 * sy,315x3 * sx, y3 * sy);316}317318public void closePath() {319out.closePath();320}321322public void pathDone() {323out.pathDone();324}325326public long getNativeConsumer() {327return 0;328}329}330331static final class DeltaTransformFilter implements PathConsumer2D {332private PathConsumer2D out;333private final float Mxx;334private final float Mxy;335private final float Myx;336private final float Myy;337338DeltaTransformFilter(PathConsumer2D out,339float Mxx, float Mxy,340float Myx, float Myy)341{342this.out = out;343this.Mxx = Mxx;344this.Mxy = Mxy;345this.Myx = Myx;346this.Myy = Myy;347}348349public void moveTo(float x0, float y0) {350out.moveTo(x0 * Mxx + y0 * Mxy,351x0 * Myx + y0 * Myy);352}353354public void lineTo(float x1, float y1) {355out.lineTo(x1 * Mxx + y1 * Mxy,356x1 * Myx + y1 * Myy);357}358359public void quadTo(float x1, float y1,360float x2, float y2)361{362out.quadTo(x1 * Mxx + y1 * Mxy,363x1 * Myx + y1 * Myy,364x2 * Mxx + y2 * Mxy,365x2 * Myx + y2 * Myy);366}367368public void curveTo(float x1, float y1,369float x2, float y2,370float x3, float y3)371{372out.curveTo(x1 * Mxx + y1 * Mxy,373x1 * Myx + y1 * Myy,374x2 * Mxx + y2 * Mxy,375x2 * Myx + y2 * Myy,376x3 * Mxx + y3 * Mxy,377x3 * Myx + y3 * Myy);378}379380public void closePath() {381out.closePath();382}383384public void pathDone() {385out.pathDone();386}387388public long getNativeConsumer() {389return 0;390}391}392}393394395