< prev index next >

src/java.desktop/share/classes/sun/java2d/pipe/PixelToParallelogramConverter.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2011, 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


 184             return false;
 185         }
 186         BasicStroke bs = (BasicStroke) sg2d.stroke;
 187         int cap = bs.getEndCap();
 188         if (cap == BasicStroke.CAP_ROUND || bs.getDashArray() != null) {
 189             // TODO: we could construct the GeneralPath directly
 190             // for CAP_ROUND and save a lot of processing in that case...
 191             // And again, we would need to deal with dropout control...
 192             return false;
 193         }
 194         double lw = bs.getLineWidth();
 195         // Save the original dx, dy in case we need it to transform
 196         // the linewidth as a perpendicular vector below
 197         double dx = ux2 - ux1;
 198         double dy = uy2 - uy1;
 199         double x1, y1, x2, y2;
 200         switch (sg2d.transformState) {
 201         case SunGraphics2D.TRANSFORM_GENERIC:
 202         case SunGraphics2D.TRANSFORM_TRANSLATESCALE:
 203             {
 204                 double coords[] = {ux1, uy1, ux2, uy2};
 205                 sg2d.transform.transform(coords, 0, coords, 0, 2);
 206                 x1 = coords[0];
 207                 y1 = coords[1];
 208                 x2 = coords[2];
 209                 y2 = coords[3];
 210             }
 211             break;
 212         case SunGraphics2D.TRANSFORM_ANY_TRANSLATE:
 213         case SunGraphics2D.TRANSFORM_INT_TRANSLATE:
 214             {
 215                 double tx = sg2d.transform.getTranslateX();
 216                 double ty = sg2d.transform.getTranslateY();
 217                 x1 = ux1 + tx;
 218                 y1 = uy1 + ty;
 219                 x2 = ux2 + tx;
 220                 y2 = uy2 + ty;
 221             }
 222             break;
 223         case SunGraphics2D.TRANSFORM_ISIDENT:
 224             x1 = ux1;


 240                 int ix2 = (int) Math.floor(x2 - sg2d.transX);
 241                 int iy2 = (int) Math.floor(y2 - sg2d.transY);
 242                 ((PixelDrawPipe)outrenderer).drawLine(sg2d, ix1, iy1, ix2, iy2);
 243                 return true;
 244             }
 245             x1 = normalize(x1);
 246             y1 = normalize(y1);
 247             x2 = normalize(x2);
 248             y2 = normalize(y2);
 249         }
 250         if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
 251             // Transform the linewidth...
 252             // calculate the scaling factor for a unit vector
 253             // perpendicular to the original user space line.
 254             double len = len(dx, dy);
 255             if (len == 0) {
 256                 dx = len = 1;
 257                 // dy = 0; already
 258             }
 259             // delta transform the transposed (90 degree rotated) unit vector
 260             double unitvector[] = {dy/len, -dx/len};
 261             sg2d.transform.deltaTransform(unitvector, 0, unitvector, 0, 1);
 262             lw *= len(unitvector[0], unitvector[1]);
 263         }
 264         lw = Math.max(lw, minPenSize);
 265         dx = x2 - x1;
 266         dy = y2 - y1;
 267         double len = len(dx, dy);
 268         double udx, udy;
 269         if (len == 0) {
 270             if (cap == BasicStroke.CAP_BUTT) {
 271                 return true;
 272             }
 273             udx = lw;
 274             udy = 0;
 275         } else {
 276             udx = lw * dx / len;
 277             udy = lw * dy / len;
 278         }
 279         double px = x1 + udy / 2.0;
 280         double py = y1 - udx / 2.0;


   1 /*
   2  * Copyright (c) 2008, 2018, 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


 184             return false;
 185         }
 186         BasicStroke bs = (BasicStroke) sg2d.stroke;
 187         int cap = bs.getEndCap();
 188         if (cap == BasicStroke.CAP_ROUND || bs.getDashArray() != null) {
 189             // TODO: we could construct the GeneralPath directly
 190             // for CAP_ROUND and save a lot of processing in that case...
 191             // And again, we would need to deal with dropout control...
 192             return false;
 193         }
 194         double lw = bs.getLineWidth();
 195         // Save the original dx, dy in case we need it to transform
 196         // the linewidth as a perpendicular vector below
 197         double dx = ux2 - ux1;
 198         double dy = uy2 - uy1;
 199         double x1, y1, x2, y2;
 200         switch (sg2d.transformState) {
 201         case SunGraphics2D.TRANSFORM_GENERIC:
 202         case SunGraphics2D.TRANSFORM_TRANSLATESCALE:
 203             {
 204                 double[] coords = {ux1, uy1, ux2, uy2};
 205                 sg2d.transform.transform(coords, 0, coords, 0, 2);
 206                 x1 = coords[0];
 207                 y1 = coords[1];
 208                 x2 = coords[2];
 209                 y2 = coords[3];
 210             }
 211             break;
 212         case SunGraphics2D.TRANSFORM_ANY_TRANSLATE:
 213         case SunGraphics2D.TRANSFORM_INT_TRANSLATE:
 214             {
 215                 double tx = sg2d.transform.getTranslateX();
 216                 double ty = sg2d.transform.getTranslateY();
 217                 x1 = ux1 + tx;
 218                 y1 = uy1 + ty;
 219                 x2 = ux2 + tx;
 220                 y2 = uy2 + ty;
 221             }
 222             break;
 223         case SunGraphics2D.TRANSFORM_ISIDENT:
 224             x1 = ux1;


 240                 int ix2 = (int) Math.floor(x2 - sg2d.transX);
 241                 int iy2 = (int) Math.floor(y2 - sg2d.transY);
 242                 ((PixelDrawPipe)outrenderer).drawLine(sg2d, ix1, iy1, ix2, iy2);
 243                 return true;
 244             }
 245             x1 = normalize(x1);
 246             y1 = normalize(y1);
 247             x2 = normalize(x2);
 248             y2 = normalize(y2);
 249         }
 250         if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
 251             // Transform the linewidth...
 252             // calculate the scaling factor for a unit vector
 253             // perpendicular to the original user space line.
 254             double len = len(dx, dy);
 255             if (len == 0) {
 256                 dx = len = 1;
 257                 // dy = 0; already
 258             }
 259             // delta transform the transposed (90 degree rotated) unit vector
 260             double[] unitvector = {dy/len, -dx/len};
 261             sg2d.transform.deltaTransform(unitvector, 0, unitvector, 0, 1);
 262             lw *= len(unitvector[0], unitvector[1]);
 263         }
 264         lw = Math.max(lw, minPenSize);
 265         dx = x2 - x1;
 266         dy = y2 - y1;
 267         double len = len(dx, dy);
 268         double udx, udy;
 269         if (len == 0) {
 270             if (cap == BasicStroke.CAP_BUTT) {
 271                 return true;
 272             }
 273             udx = lw;
 274             udy = 0;
 275         } else {
 276             udx = lw * dx / len;
 277             udy = lw * dy / len;
 278         }
 279         double px = x1 + udy / 2.0;
 280         double py = y1 - udx / 2.0;


< prev index next >