jdk/src/share/classes/sun/java2d/pisces/PiscesRenderingEngine.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8131 e2932d8114cb
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8131
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3927
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3927
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3927
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3927
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3927
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d.pisces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.BasicStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.Path2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.geom.PathConsumer2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.pipe.RenderingEngine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.pipe.AATileGenerator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class PiscesRenderingEngine extends RenderingEngine {
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
    40
    private static enum NormMode {OFF, ON_NO_AA, ON_WITH_AA}
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Create a widened path as specified by the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * The specified {@code src} {@link Shape} is widened according
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * to the specified attribute parameters as per the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * {@link BasicStroke} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @param src the source path to be widened
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param width the width of the widened path as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @param caps the end cap decorations as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @param join the segment join decorations as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param miterlimit the miter limit as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @param dashes the dash length array as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param dashphase the initial dash phase as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @return the widened path stored in a new {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public Shape createStrokedShape(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                    float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                    int caps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                    int join,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                    float miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                    float dashes[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                    float dashphase)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        final Path2D p2d = new Path2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        strokeTo(src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                 width,
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
    72
                 NormMode.OFF,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                 caps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                 join,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                 miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                 dashes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                 dashphase,
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    78
                 new PathConsumer2D() {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    79
                     public void moveTo(float x0, float y0) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    80
                         p2d.moveTo(x0, y0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                     }
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    82
                     public void lineTo(float x1, float y1) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    83
                         p2d.lineTo(x1, y1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                     }
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    85
                     public void closePath() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                         p2d.closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                     }
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    88
                     public void pathDone() {}
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    89
                     public void curveTo(float x1, float y1,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    90
                                         float x2, float y2,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    91
                                         float x3, float y3) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    92
                         p2d.curveTo(x1, y1, x2, y2, x3, y3);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    93
                     }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    94
                     public void quadTo(float x1, float y1, float x2, float y2) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    95
                         p2d.quadTo(x1, y1, x2, y2);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    96
                     }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    97
                     public long getNativeConsumer() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    98
                         throw new InternalError("Not using a native peer");
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
    99
                     }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return p2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Sends the geometry for a widened path as specified by the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * to the specified consumer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * The specified {@code src} {@link Shape} is widened according
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * to the parameters specified by the {@link BasicStroke} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Adjustments are made to the path as appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * {@link VALUE_STROKE_NORMALIZE} hint if the {@code normalize}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * boolean parameter is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Adjustments are made to the path as appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * {@link VALUE_ANTIALIAS_ON} hint if the {@code antialias}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * boolean parameter is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * The geometry of the widened path is forwarded to the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * {@link PathConsumer2D} object as it is calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param src the source path to be widened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param bs the {@code BasicSroke} object specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *           decorations to be applied to the widened path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param normalize indicates whether stroke normalization should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *                  be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param antialias indicates whether or not adjustments appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *                  to antialiased rendering should be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param consumer the {@code PathConsumer2D} instance to forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *                 the widened geometry to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void strokeTo(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                         AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                         BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                         boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                         boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                         boolean antialias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                         final PathConsumer2D consumer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    {
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   139
        NormMode norm = (normalize) ?
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   140
                ((antialias) ? NormMode.ON_WITH_AA : NormMode.ON_NO_AA)
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   141
                : NormMode.OFF;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   142
        strokeTo(src, at, bs, thin, norm, antialias, consumer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    void strokeTo(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                  AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                  BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                  boolean thin,
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   149
                  NormMode normalize,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                  boolean antialias,
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   151
                  PathConsumer2D pc2d)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        float lw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (thin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (antialias) {
3927
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   156
                lw = userSpaceLineWidth(at, 0.5f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            } else {
3927
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   158
                lw = userSpaceLineWidth(at, 1.0f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            lw = bs.getLineWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        strokeTo(src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                 at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                 lw,
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   166
                 normalize,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                 bs.getEndCap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                 bs.getLineJoin(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                 bs.getMiterLimit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                 bs.getDashArray(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                 bs.getDashPhase(),
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   172
                 pc2d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
3927
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   175
    private float userSpaceLineWidth(AffineTransform at, float lw) {
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   176
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   177
        double widthScale;
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   178
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   179
        if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   180
                            AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   181
            widthScale = Math.sqrt(at.getDeterminant());
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   182
        } else {
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   183
            /* First calculate the "maximum scale" of this transform. */
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   184
            double A = at.getScaleX();       // m00
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   185
            double C = at.getShearX();       // m01
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   186
            double B = at.getShearY();       // m10
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   187
            double D = at.getScaleY();       // m11
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   188
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   189
            /*
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   190
             * Given a 2 x 2 affine matrix [ A B ] such that
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   191
             *                             [ C D ]
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   192
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   193
             * find the maximum magnitude (norm) of the vector v'
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   194
             * with the constraint (x^2 + y^2 = 1).
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   195
             * The equation to maximize is
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   196
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   197
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   198
             * Since sqrt is monotonic we can maximize |v'|^2
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   199
             * instead and plug in the substitution y = sqrt(1 - x^2).
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   200
             * Trigonometric equalities can then be used to get
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   201
             * rid of most of the sqrt terms.
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   202
             */
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   203
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   204
            double EA = A*A + B*B;          // x^2 coefficient
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   205
            double EB = 2*(A*C + B*D);      // xy coefficient
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   206
            double EC = C*C + D*D;          // y^2 coefficient
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   207
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   208
            /*
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   209
             * There is a lot of calculus omitted here.
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   210
             *
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   211
             * Conceptually, in the interests of understanding the
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   212
             * terms that the calculus produced we can consider
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   213
             * that EA and EC end up providing the lengths along
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   214
             * the major axes and the hypot term ends up being an
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   215
             * adjustment for the additional length along the off-axis
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   216
             * angle of rotated or sheared ellipses as well as an
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   217
             * adjustment for the fact that the equation below
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   218
             * averages the two major axis lengths.  (Notice that
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   219
             * the hypot term contains a part which resolves to the
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   220
             * difference of these two axis lengths in the absence
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   221
             * of rotation.)
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   222
             *
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   223
             * In the calculus, the ratio of the EB and (EA-EC) terms
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   224
             * ends up being the tangent of 2*theta where theta is
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   225
             * the angle that the long axis of the ellipse makes
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   226
             * with the horizontal axis.  Thus, this equation is
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   227
             * calculating the length of the hypotenuse of a triangle
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   228
             * along that axis.
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   229
             */
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   230
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   231
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   232
            /* sqrt omitted, compare to squared limits below. */
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   233
            double widthsquared = ((EA + EC + hypot)/2.0);
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   234
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   235
            widthScale = Math.sqrt(widthsquared);
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   236
        }
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   237
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   238
        return (float) (lw / widthScale);
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   239
    }
d717df90e151 6829673: ThinLineTest: A line < 1 pixel disappears.
jgodinez
parents: 2391
diff changeset
   240
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    void strokeTo(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                  AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                  float width,
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   244
                  NormMode normalize,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                  int caps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                  int join,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                  float miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                  float dashes[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                  float dashphase,
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   250
                  PathConsumer2D pc2d)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   252
        // We use strokerat and outat so that in Stroker and Dasher we can work only
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   253
        // with the pre-transformation coordinates. This will repeat a lot of
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   254
        // computations done in the path iterator, but the alternative is to
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   255
        // work with transformed paths and compute untransformed coordinates
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   256
        // as needed. This would be faster but I do not think the complexity
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   257
        // of working with both untransformed and transformed coordinates in
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   258
        // the same code is worth it.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   259
        // However, if a path's width is constant after a transformation,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   260
        // we can skip all this untransforming.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   261
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   262
        // If normalization is off we save some transformations by not
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   263
        // transforming the input to pisces. Instead, we apply the
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   264
        // transformation after the path processing has been done.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   265
        // We can't do this if normalization is on, because it isn't a good
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   266
        // idea to normalize before the transformation is applied.
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   267
        AffineTransform strokerat = null;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   268
        AffineTransform outat = null;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   269
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   270
        PathIterator pi = null;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   271
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   272
        if (at != null && !at.isIdentity()) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   273
            final double a = at.getScaleX();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   274
            final double b = at.getShearX();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   275
            final double c = at.getShearY();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   276
            final double d = at.getScaleY();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   277
            final double det = a * d - c * b;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   278
            if (Math.abs(det) <= 2 * Float.MIN_VALUE) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   279
                // this rendering engine takes one dimensional curves and turns
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   280
                // them into 2D shapes by giving them width.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   281
                // However, if everything is to be passed through a singular
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   282
                // transformation, these 2D shapes will be squashed down to 1D
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   283
                // again so, nothing can be drawn.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   284
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   285
                // Every path needs an initial moveTo and a pathDone. If these
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   286
                // are not there this causes a SIGSEGV in libawt.so (at the time
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   287
                // of writing of this comment (September 16, 2010)). Actually,
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   288
                // I am not sure if the moveTo is necessary to avoid the SIGSEGV
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   289
                // but the pathDone is definitely needed.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   290
                pc2d.moveTo(0, 0);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   291
                pc2d.pathDone();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   292
                return;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   293
            }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   294
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   295
            // If the transform is a constant multiple of an orthogonal transformation
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   296
            // then every length is just multiplied by a constant, so we just
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   297
            // need to transform input paths to stroker and tell stroker
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   298
            // the scaled width. This condition is satisfied if
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   299
            // a*b == -c*d && a*a+c*c == b*b+d*d. In the actual check below, we
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   300
            // leave a bit of room for error.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   301
            if (nearZero(a*b + c*d, 2) && nearZero(a*a+c*c - (b*b+d*d), 2)) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   302
                double scale = Math.sqrt(a*a + c*c);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   303
                if (dashes != null) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   304
                    dashes = java.util.Arrays.copyOf(dashes, dashes.length);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   305
                    for (int i = 0; i < dashes.length; i++) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   306
                        dashes[i] = (float)(scale * dashes[i]);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   307
                    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   308
                    dashphase = (float)(scale * dashphase);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   309
                }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   310
                width = (float)(scale * width);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   311
                pi = src.getPathIterator(at);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   312
                if (normalize != NormMode.OFF) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   313
                    pi = new NormalizingPathIterator(pi, normalize);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   314
                }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   315
                // by now strokerat == null && outat == null. Input paths to
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   316
                // stroker (and maybe dasher) will have the full transform at
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   317
                // applied to them and nothing will happen to the output paths.
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   318
            } else {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   319
                if (normalize != NormMode.OFF) {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   320
                    strokerat = at;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   321
                    pi = src.getPathIterator(at);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   322
                    pi = new NormalizingPathIterator(pi, normalize);
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   323
                    // by now strokerat == at && outat == null. Input paths to
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   324
                    // stroker (and maybe dasher) will have the full transform at
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   325
                    // applied to them, then they will be normalized, and then
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   326
                    // the inverse of *only the non translation part of at* will
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   327
                    // be applied to the normalized paths. This won't cause problems
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   328
                    // in stroker, because, suppose at = T*A, where T is just the
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   329
                    // translation part of at, and A is the rest. T*A has already
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   330
                    // been applied to Stroker/Dasher's input. Then Ainv will be
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   331
                    // applied. Ainv*T*A is not equal to T, but it is a translation,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   332
                    // which means that none of stroker's assumptions about its
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   333
                    // input will be violated. After all this, A will be applied
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   334
                    // to stroker's output.
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   335
                } else {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   336
                    outat = at;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   337
                    pi = src.getPathIterator(null);
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   338
                    // outat == at && strokerat == null. This is because if no
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   339
                    // normalization is done, we can just apply all our
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   340
                    // transformations to stroker's output.
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   341
                }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   342
            }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   343
        } else {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   344
            // either at is null or it's the identity. In either case
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   345
            // we don't transform the path.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   346
            pi = src.getPathIterator(null);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   347
            if (normalize != NormMode.OFF) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   348
                pi = new NormalizingPathIterator(pi, normalize);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   349
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   351
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   352
        // by now, at least one of outat and strokerat will be null. Unless at is not
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   353
        // a constant multiple of an orthogonal transformation, they will both be
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   354
        // null. In other cases, outat == at if normalization is off, and if
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   355
        // normalization is on, strokerat == at.
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   356
        pc2d = TransformingPathConsumer2D.transformConsumer(pc2d, outat);
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   357
        pc2d = TransformingPathConsumer2D.deltaTransformConsumer(pc2d, strokerat);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   358
        pc2d = new Stroker(pc2d, width, caps, join, miterlimit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (dashes != null) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   360
            pc2d = new Dasher(pc2d, dashes, dashphase);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   362
        pc2d = TransformingPathConsumer2D.inverseDeltaTransformConsumer(pc2d, strokerat);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   363
        pathTo(pi, pc2d);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   364
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   365
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   366
    private static boolean nearZero(double num, int nulps) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   367
        return Math.abs(num) < nulps * Math.ulp(num);
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   368
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   370
    private static class NormalizingPathIterator implements PathIterator {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   371
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   372
        private final PathIterator src;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   373
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   374
        // the adjustment applied to the current position.
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   375
        private float curx_adjust, cury_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   376
        // the adjustment applied to the last moveTo position.
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   377
        private float movx_adjust, movy_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   378
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   379
        // constants used in normalization computations
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   380
        private final float lval, rval;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   381
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   382
        NormalizingPathIterator(PathIterator src, NormMode mode) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   383
            this.src = src;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   384
            switch (mode) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   385
            case ON_NO_AA:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   386
                // round to nearest (0.25, 0.25) pixel
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   387
                lval = rval = 0.25f;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   388
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   389
            case ON_WITH_AA:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   390
                // round to nearest pixel center
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   391
                lval = 0f;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   392
                rval = 0.5f;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   393
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   394
            case OFF:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   395
                throw new InternalError("A NormalizingPathIterator should " +
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   396
                         "not be created if no normalization is being done");
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   397
            default:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   398
                throw new InternalError("Unrecognized normalization mode");
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   399
            }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   400
        }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   401
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   402
        public int currentSegment(float[] coords) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   403
            int type = src.currentSegment(coords);
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   404
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   405
            int lastCoord;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   406
            switch(type) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   407
            case PathIterator.SEG_CUBICTO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   408
                lastCoord = 4;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   409
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   410
            case PathIterator.SEG_QUADTO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   411
                lastCoord = 2;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   412
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   413
            case PathIterator.SEG_LINETO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   414
            case PathIterator.SEG_MOVETO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   415
                lastCoord = 0;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   416
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   417
            case PathIterator.SEG_CLOSE:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   418
                // we don't want to deal with this case later. We just exit now
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   419
                curx_adjust = movx_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   420
                cury_adjust = movy_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   421
                return type;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   422
            default:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   423
                throw new InternalError("Unrecognized curve type");
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   424
            }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   425
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   426
            // normalize endpoint
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   427
            float x_adjust = (float)Math.floor(coords[lastCoord] + lval) +
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   428
                         rval - coords[lastCoord];
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   429
            float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) +
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   430
                         rval - coords[lastCoord + 1];
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   431
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   432
            coords[lastCoord    ] += x_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   433
            coords[lastCoord + 1] += y_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   434
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   435
            // now that the end points are done, normalize the control points
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   436
            switch(type) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   437
            case PathIterator.SEG_CUBICTO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   438
                coords[0] += curx_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   439
                coords[1] += cury_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   440
                coords[2] += x_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   441
                coords[3] += y_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   442
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   443
            case PathIterator.SEG_QUADTO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   444
                coords[0] += (curx_adjust + x_adjust) / 2;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   445
                coords[1] += (cury_adjust + y_adjust) / 2;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   446
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   447
            case PathIterator.SEG_LINETO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   448
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   449
            case PathIterator.SEG_MOVETO:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   450
                movx_adjust = x_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   451
                movy_adjust = y_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   452
                break;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   453
            case PathIterator.SEG_CLOSE:
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   454
                throw new InternalError("This should be handled earlier.");
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   455
            }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   456
            curx_adjust = x_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   457
            cury_adjust = y_adjust;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   458
            return type;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   459
        }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   460
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   461
        public int currentSegment(double[] coords) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   462
            float[] tmp = new float[6];
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   463
            int type = this.currentSegment(tmp);
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   464
            for (int i = 0; i < 6; i++) {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   465
                coords[i] = (float) tmp[i];
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   466
            }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   467
            return type;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   468
        }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   469
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   470
        public int getWindingRule() {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   471
            return src.getWindingRule();
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   472
        }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   473
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   474
        public boolean isDone() {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   475
            return src.isDone();
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   476
        }
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   477
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   478
        public void next() {
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   479
            src.next();
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   480
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   483
    static void pathTo(PathIterator pi, PathConsumer2D pc2d) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   484
        RenderingEngine.feedConsumer(pi, pc2d);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   485
        pc2d.pathDone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Construct an antialiased tile generator for the given shape with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * the given rendering attributes and store the bounds of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * iteration in the bbox parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * The {@code at} parameter specifies a transform that should affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * both the shape and the {@code BasicStroke} attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * The {@code clip} parameter specifies the current clip in effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * in device coordinates and can be used to prune the data for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * operation, but the renderer is not required to perform any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * clipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * If the {@code BasicStroke} parameter is null then the shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * should be filled as is, otherwise the attributes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * {@code BasicStroke} should be used to specify a draw operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * The {@code thin} parameter indicates whether or not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * transformed {@code BasicStroke} represents coordinates smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * than the minimum resolution of the antialiasing rasterizer as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * specified by the {@code getMinimumAAPenWidth()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Upon returning, this method will fill the {@code bbox} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * with 4 values indicating the bounds of the iteration of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * tile generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * The iteration order of the tiles will be as specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * pseudo-code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *     for (y = bbox[1]; y < bbox[3]; y += tileheight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *         for (x = bbox[0]; x < bbox[2]; x += tilewidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * If there is no output to be rendered, this method may return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param s the shape to be rendered (fill or draw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param at the transform to be applied to the shape and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *           stroke attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param clip the current clip in effect in device coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @param bs if non-null, a {@code BasicStroke} whose attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *           should be applied to this operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @param thin true if the transformed stroke attributes are smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *             than the minimum dropout pen width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param normalize true if the {@code VALUE_STROKE_NORMALIZE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *                  {@code RenderingHint} is in effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @param bbox returns the bounds of the iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @return the {@code AATileGenerator} instance to be consulted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *         for tile coverages, or null if there is no output to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public AATileGenerator getAATileGenerator(Shape s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                              AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                              Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                              BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                              boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                              boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                              int bbox[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   543
        Renderer r;
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   544
        NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (bs == null) {
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   546
            PathIterator pi;
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   547
            if (normalize) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   548
                pi = new NormalizingPathIterator(s.getPathIterator(at), norm);
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   549
            } else {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   550
                pi = s.getPathIterator(at);
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   551
            }
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   552
            r = new Renderer(3, 3,
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   553
                             clip.getLoX(), clip.getLoY(),
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   554
                             clip.getWidth(), clip.getHeight(),
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   555
                             pi.getWindingRule());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            pathTo(pi, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } else {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   558
            r = new Renderer(3, 3,
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   559
                             clip.getLoX(), clip.getLoY(),
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   560
                             clip.getWidth(), clip.getHeight(),
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   561
                             PathIterator.WIND_NON_ZERO);
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   562
            strokeTo(s, at, bs, thin, norm, true, r);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        r.endRendering();
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6285
diff changeset
   565
        PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        ptg.getBbox(bbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        return ptg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   570
    public AATileGenerator getAATileGenerator(double x, double y,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   571
                                              double dx1, double dy1,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   572
                                              double dx2, double dy2,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   573
                                              double lw1, double lw2,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   574
                                              Region clip,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   575
                                              int bbox[])
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   576
    {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   577
        // REMIND: Deal with large coordinates!
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   578
        double ldx1, ldy1, ldx2, ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   579
        boolean innerpgram = (lw1 > 0 && lw2 > 0);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   580
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   581
        if (innerpgram) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   582
            ldx1 = dx1 * lw1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   583
            ldy1 = dy1 * lw1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   584
            ldx2 = dx2 * lw2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   585
            ldy2 = dy2 * lw2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   586
            x -= (ldx1 + ldx2) / 2.0;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   587
            y -= (ldy1 + ldy2) / 2.0;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   588
            dx1 += ldx1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   589
            dy1 += ldy1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   590
            dx2 += ldx2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   591
            dy2 += ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   592
            if (lw1 > 1 && lw2 > 1) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   593
                // Inner parallelogram was entirely consumed by stroke...
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   594
                innerpgram = false;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   595
            }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   596
        } else {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   597
            ldx1 = ldy1 = ldx2 = ldy2 = 0;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   598
        }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   599
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   600
        Renderer r = new Renderer(3, 3,
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   601
                clip.getLoX(), clip.getLoY(),
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   602
                clip.getWidth(), clip.getHeight(),
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7762
diff changeset
   603
                PathIterator.WIND_EVEN_ODD);
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   604
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   605
        r.moveTo((float) x, (float) y);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   606
        r.lineTo((float) (x+dx1), (float) (y+dy1));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   607
        r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   608
        r.lineTo((float) (x+dx2), (float) (y+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   609
        r.closePath();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   610
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   611
        if (innerpgram) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   612
            x += ldx1 + ldx2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   613
            y += ldy1 + ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   614
            dx1 -= 2.0 * ldx1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   615
            dy1 -= 2.0 * ldy1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   616
            dx2 -= 2.0 * ldx2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   617
            dy2 -= 2.0 * ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   618
            r.moveTo((float) x, (float) y);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   619
            r.lineTo((float) (x+dx1), (float) (y+dy1));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   620
            r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   621
            r.lineTo((float) (x+dx2), (float) (y+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   622
            r.closePath();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   623
        }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   624
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   625
        r.pathDone();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   626
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   627
        r.endRendering();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   628
        PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   629
        ptg.getBbox(bbox);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   630
        return ptg;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   631
    }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 6997
diff changeset
   632
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Returns the minimum pen width that the antialiasing rasterizer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * can represent without dropouts occuring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public float getMinimumAAPenSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (PathIterator.WIND_NON_ZERO != Renderer.WIND_NON_ZERO ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            PathIterator.WIND_EVEN_ODD != Renderer.WIND_EVEN_ODD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            BasicStroke.JOIN_MITER != Stroker.JOIN_MITER ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            BasicStroke.JOIN_ROUND != Stroker.JOIN_ROUND ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            BasicStroke.JOIN_BEVEL != Stroker.JOIN_BEVEL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            BasicStroke.CAP_BUTT != Stroker.CAP_BUTT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            BasicStroke.CAP_ROUND != Stroker.CAP_ROUND ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            BasicStroke.CAP_SQUARE != Stroker.CAP_SQUARE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            throw new InternalError("mismatched renderer constants");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
}
6285
96a57de47def 6976265: No STROKE_CONTROL
dlila
parents: 6284
diff changeset
   656