jdk/src/share/classes/sun/java2d/pisces/TransformingPathConsumer2D.java
changeset 8131 e2932d8114cb
parent 7668 d4a77089c587
child 9035 1255eb81cc2f
equal deleted inserted replaced
8130:c582063ba5bb 8131:e2932d8114cb
    26 package sun.java2d.pisces;
    26 package sun.java2d.pisces;
    27 
    27 
    28 import sun.awt.geom.PathConsumer2D;
    28 import sun.awt.geom.PathConsumer2D;
    29 import java.awt.geom.AffineTransform;
    29 import java.awt.geom.AffineTransform;
    30 
    30 
    31 public class TransformingPathConsumer2D {
    31 final class TransformingPathConsumer2D {
    32     public static PathConsumer2D
    32     public static PathConsumer2D
    33         transformConsumer(PathConsumer2D out,
    33         transformConsumer(PathConsumer2D out,
    34                           AffineTransform at)
    34                           AffineTransform at)
    35     {
    35     {
    36         if (at == null) {
    36         if (at == null) {
    48                     return out;
    48                     return out;
    49                 } else {
    49                 } else {
    50                     return new TranslateFilter(out, Mxt, Myt);
    50                     return new TranslateFilter(out, Mxt, Myt);
    51                 }
    51                 }
    52             } else {
    52             } else {
    53                 return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);
    53                 if (Mxt == 0f && Myt == 0f) {
       
    54                     return new DeltaScaleFilter(out, Mxx, Myy);
       
    55                 } else {
       
    56                     return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);
       
    57                 }
       
    58             }
       
    59         } else if (Mxt == 0f && Myt == 0f) {
       
    60             return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
       
    61         } else {
       
    62             return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt);
       
    63         }
       
    64     }
       
    65 
       
    66     public static PathConsumer2D
       
    67         deltaTransformConsumer(PathConsumer2D out,
       
    68                                AffineTransform at)
       
    69     {
       
    70         if (at == null) {
       
    71             return out;
       
    72         }
       
    73         float Mxx = (float) at.getScaleX();
       
    74         float Mxy = (float) at.getShearX();
       
    75         float Myx = (float) at.getShearY();
       
    76         float Myy = (float) at.getScaleY();
       
    77         if (Mxy == 0f && Myx == 0f) {
       
    78             if (Mxx == 1f && Myy == 1f) {
       
    79                 return out;
       
    80             } else {
       
    81                 return new DeltaScaleFilter(out, Mxx, Myy);
    54             }
    82             }
    55         } else {
    83         } else {
    56             return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt);
    84             return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
    57         }
    85         }
    58     }
    86     }
    59 
    87 
    60     static class TranslateFilter implements PathConsumer2D {
    88     public static PathConsumer2D
    61         PathConsumer2D out;
    89         inverseDeltaTransformConsumer(PathConsumer2D out,
    62         float tx;
    90                                       AffineTransform at)
    63         float ty;
    91     {
       
    92         if (at == null) {
       
    93             return out;
       
    94         }
       
    95         float Mxx = (float) at.getScaleX();
       
    96         float Mxy = (float) at.getShearX();
       
    97         float Myx = (float) at.getShearY();
       
    98         float Myy = (float) at.getScaleY();
       
    99         if (Mxy == 0f && Myx == 0f) {
       
   100             if (Mxx == 1f && Myy == 1f) {
       
   101                 return out;
       
   102             } else {
       
   103                 return new DeltaScaleFilter(out, 1.0f/Mxx, 1.0f/Myy);
       
   104             }
       
   105         } else {
       
   106             float det = Mxx * Myy - Mxy * Myx;
       
   107             return new DeltaTransformFilter(out,
       
   108                                             Myy / det,
       
   109                                             -Mxy / det,
       
   110                                             -Myx / det,
       
   111                                             Mxx / det);
       
   112         }
       
   113     }
       
   114 
       
   115     static final class TranslateFilter implements PathConsumer2D {
       
   116         private final PathConsumer2D out;
       
   117         private final float tx;
       
   118         private final float ty;
    64 
   119 
    65         TranslateFilter(PathConsumer2D out,
   120         TranslateFilter(PathConsumer2D out,
    66                         float tx, float ty)
   121                         float tx, float ty)
    67         {
   122         {
    68             this.out = out;
   123             this.out = out;
   105         public long getNativeConsumer() {
   160         public long getNativeConsumer() {
   106             return 0;
   161             return 0;
   107         }
   162         }
   108     }
   163     }
   109 
   164 
   110     static class ScaleFilter implements PathConsumer2D {
   165     static final class ScaleFilter implements PathConsumer2D {
   111         PathConsumer2D out;
   166         private final PathConsumer2D out;
   112         float sx;
   167         private final float sx;
   113         float sy;
   168         private final float sy;
   114         float tx;
   169         private final float tx;
   115         float ty;
   170         private final float ty;
   116 
   171 
   117         ScaleFilter(PathConsumer2D out,
   172         ScaleFilter(PathConsumer2D out,
   118                     float sx, float sy, float tx, float ty)
   173                     float sx, float sy, float tx, float ty)
   119         {
   174         {
   120             this.out = out;
   175             this.out = out;
   159         public long getNativeConsumer() {
   214         public long getNativeConsumer() {
   160             return 0;
   215             return 0;
   161         }
   216         }
   162     }
   217     }
   163 
   218 
   164     static class TransformFilter implements PathConsumer2D {
   219     static final class TransformFilter implements PathConsumer2D {
   165         PathConsumer2D out;
   220         private final PathConsumer2D out;
   166         float Mxx;
   221         private final float Mxx;
   167         float Mxy;
   222         private final float Mxy;
   168         float Mxt;
   223         private final float Mxt;
   169         float Myx;
   224         private final float Myx;
   170         float Myy;
   225         private final float Myy;
   171         float Myt;
   226         private final float Myt;
   172 
   227 
   173         TransformFilter(PathConsumer2D out,
   228         TransformFilter(PathConsumer2D out,
   174                         float Mxx, float Mxy, float Mxt,
   229                         float Mxx, float Mxy, float Mxt,
   175                         float Myx, float Myy, float Myt)
   230                         float Myx, float Myy, float Myt)
   176         {
   231         {
   224 
   279 
   225         public long getNativeConsumer() {
   280         public long getNativeConsumer() {
   226             return 0;
   281             return 0;
   227         }
   282         }
   228     }
   283     }
       
   284 
       
   285     static final class DeltaScaleFilter implements PathConsumer2D {
       
   286         private final float sx, sy;
       
   287         private final PathConsumer2D out;
       
   288 
       
   289         public DeltaScaleFilter(PathConsumer2D out, float Mxx, float Myy) {
       
   290             sx = Mxx;
       
   291             sy = Myy;
       
   292             this.out = out;
       
   293         }
       
   294 
       
   295         public void moveTo(float x0, float y0) {
       
   296             out.moveTo(x0 * sx, y0 * sy);
       
   297         }
       
   298 
       
   299         public void lineTo(float x1, float y1) {
       
   300             out.lineTo(x1 * sx, y1 * sy);
       
   301         }
       
   302 
       
   303         public void quadTo(float x1, float y1,
       
   304                            float x2, float y2)
       
   305         {
       
   306             out.quadTo(x1 * sx, y1 * sy,
       
   307                        x2 * sx, y2 * sy);
       
   308         }
       
   309 
       
   310         public void curveTo(float x1, float y1,
       
   311                             float x2, float y2,
       
   312                             float x3, float y3)
       
   313         {
       
   314             out.curveTo(x1 * sx, y1 * sy,
       
   315                         x2 * sx, y2 * sy,
       
   316                         x3 * sx, y3 * sy);
       
   317         }
       
   318 
       
   319         public void closePath() {
       
   320             out.closePath();
       
   321         }
       
   322 
       
   323         public void pathDone() {
       
   324             out.pathDone();
       
   325         }
       
   326 
       
   327         public long getNativeConsumer() {
       
   328             return 0;
       
   329         }
       
   330     }
       
   331 
       
   332     static final class DeltaTransformFilter implements PathConsumer2D {
       
   333         private PathConsumer2D out;
       
   334         private final float Mxx;
       
   335         private final float Mxy;
       
   336         private final float Myx;
       
   337         private final float Myy;
       
   338 
       
   339         DeltaTransformFilter(PathConsumer2D out,
       
   340                              float Mxx, float Mxy,
       
   341                              float Myx, float Myy)
       
   342         {
       
   343             this.out = out;
       
   344             this.Mxx = Mxx;
       
   345             this.Mxy = Mxy;
       
   346             this.Myx = Myx;
       
   347             this.Myy = Myy;
       
   348         }
       
   349 
       
   350         public void moveTo(float x0, float y0) {
       
   351             out.moveTo(x0 * Mxx + y0 * Mxy,
       
   352                        x0 * Myx + y0 * Myy);
       
   353         }
       
   354 
       
   355         public void lineTo(float x1, float y1) {
       
   356             out.lineTo(x1 * Mxx + y1 * Mxy,
       
   357                        x1 * Myx + y1 * Myy);
       
   358         }
       
   359 
       
   360         public void quadTo(float x1, float y1,
       
   361                            float x2, float y2)
       
   362         {
       
   363             out.quadTo(x1 * Mxx + y1 * Mxy,
       
   364                        x1 * Myx + y1 * Myy,
       
   365                        x2 * Mxx + y2 * Mxy,
       
   366                        x2 * Myx + y2 * Myy);
       
   367         }
       
   368 
       
   369         public void curveTo(float x1, float y1,
       
   370                             float x2, float y2,
       
   371                             float x3, float y3)
       
   372         {
       
   373             out.curveTo(x1 * Mxx + y1 * Mxy,
       
   374                         x1 * Myx + y1 * Myy,
       
   375                         x2 * Mxx + y2 * Mxy,
       
   376                         x2 * Myx + y2 * Myy,
       
   377                         x3 * Mxx + y3 * Mxy,
       
   378                         x3 * Myx + y3 * Myy);
       
   379         }
       
   380 
       
   381         public void closePath() {
       
   382             out.closePath();
       
   383         }
       
   384 
       
   385         public void pathDone() {
       
   386             out.pathDone();
       
   387         }
       
   388 
       
   389         public long getNativeConsumer() {
       
   390             return 0;
       
   391         }
       
   392     }
   229 }
   393 }