< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/TransformingPathConsumer2D.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  41     PathConsumer2D wrapPath2d(Path2D.Float p2d)
  42     {
  43         return wp_Path2DWrapper.init(p2d);
  44     }
  45 
  46     // recycled PathConsumer2D instances from deltaTransformConsumer()
  47     private final DeltaScaleFilter     dt_DeltaScaleFilter     = new DeltaScaleFilter();
  48     private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter();
  49 
  50     PathConsumer2D deltaTransformConsumer(PathConsumer2D out,
  51                                           AffineTransform at)
  52     {
  53         if (at == null) {
  54             return out;
  55         }
  56         float mxx = (float) at.getScaleX();
  57         float mxy = (float) at.getShearX();
  58         float myx = (float) at.getShearY();
  59         float myy = (float) at.getScaleY();
  60 
  61         if (mxy == 0f && myx == 0f) {
  62             if (mxx == 1f && myy == 1f) {
  63                 return out;
  64             } else {
  65                 return dt_DeltaScaleFilter.init(out, mxx, myy);
  66             }
  67         } else {
  68             return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
  69         }
  70     }
  71 
  72     // recycled PathConsumer2D instances from inverseDeltaTransformConsumer()
  73     private final DeltaScaleFilter     iv_DeltaScaleFilter     = new DeltaScaleFilter();
  74     private final DeltaTransformFilter iv_DeltaTransformFilter = new DeltaTransformFilter();
  75 
  76     PathConsumer2D inverseDeltaTransformConsumer(PathConsumer2D out,
  77                                                  AffineTransform at)
  78     {
  79         if (at == null) {
  80             return out;
  81         }
  82         float mxx = (float) at.getScaleX();
  83         float mxy = (float) at.getShearX();
  84         float myx = (float) at.getShearY();
  85         float myy = (float) at.getScaleY();
  86 
  87         if (mxy == 0f && myx == 0f) {
  88             if (mxx == 1f && myy == 1f) {
  89                 return out;
  90             } else {
  91                 return iv_DeltaScaleFilter.init(out, 1.0f/mxx, 1.0f/myy);
  92             }
  93         } else {
  94             float det = mxx * myy - mxy * myx;
  95             return iv_DeltaTransformFilter.init(out,
  96                                                 myy / det,
  97                                                -mxy / det,
  98                                                -myx / det,
  99                                                 mxx / det);
 100         }
 101     }
 102 
 103 
 104     static final class DeltaScaleFilter implements PathConsumer2D {
 105         private PathConsumer2D out;
 106         private float sx, sy;
 107 
 108         DeltaScaleFilter() {}


   1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  41     PathConsumer2D wrapPath2d(Path2D.Float p2d)
  42     {
  43         return wp_Path2DWrapper.init(p2d);
  44     }
  45 
  46     // recycled PathConsumer2D instances from deltaTransformConsumer()
  47     private final DeltaScaleFilter     dt_DeltaScaleFilter     = new DeltaScaleFilter();
  48     private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter();
  49 
  50     PathConsumer2D deltaTransformConsumer(PathConsumer2D out,
  51                                           AffineTransform at)
  52     {
  53         if (at == null) {
  54             return out;
  55         }
  56         float mxx = (float) at.getScaleX();
  57         float mxy = (float) at.getShearX();
  58         float myx = (float) at.getShearY();
  59         float myy = (float) at.getScaleY();
  60 
  61         if (mxy == 0.0f && myx == 0.0f) {
  62             if (mxx == 1.0f && myy == 1.0f) {
  63                 return out;
  64             } else {
  65                 return dt_DeltaScaleFilter.init(out, mxx, myy);
  66             }
  67         } else {
  68             return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
  69         }
  70     }
  71 
  72     // recycled PathConsumer2D instances from inverseDeltaTransformConsumer()
  73     private final DeltaScaleFilter     iv_DeltaScaleFilter     = new DeltaScaleFilter();
  74     private final DeltaTransformFilter iv_DeltaTransformFilter = new DeltaTransformFilter();
  75 
  76     PathConsumer2D inverseDeltaTransformConsumer(PathConsumer2D out,
  77                                                  AffineTransform at)
  78     {
  79         if (at == null) {
  80             return out;
  81         }
  82         float mxx = (float) at.getScaleX();
  83         float mxy = (float) at.getShearX();
  84         float myx = (float) at.getShearY();
  85         float myy = (float) at.getScaleY();
  86 
  87         if (mxy == 0.0f && myx == 0.0f) {
  88             if (mxx == 1.0f && myy == 1.0f) {
  89                 return out;
  90             } else {
  91                 return iv_DeltaScaleFilter.init(out, 1.0f/mxx, 1.0f/myy);
  92             }
  93         } else {
  94             float det = mxx * myy - mxy * myx;
  95             return iv_DeltaTransformFilter.init(out,
  96                                                 myy / det,
  97                                                -mxy / det,
  98                                                -myx / det,
  99                                                 mxx / det);
 100         }
 101     }
 102 
 103 
 104     static final class DeltaScaleFilter implements PathConsumer2D {
 105         private PathConsumer2D out;
 106         private float sx, sy;
 107 
 108         DeltaScaleFilter() {}


< prev index next >