jdk/src/share/classes/sun/dc/DuctusRenderingEngine.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7745 ebd6382e93fd
child 10419 12c063b39232
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: 7745
diff changeset
     2
 * Copyright (c) 2007, 2010, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.dc;
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.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.AffineTransform;
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.AATileGenerator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.pipe.RenderingEngine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.dc.pr.Rasterizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.dc.pr.PathStroker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.dc.pr.PathDasher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.dc.pr.PRException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.dc.path.PathConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.dc.path.PathException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.dc.path.FastPathProducer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class DuctusRenderingEngine extends RenderingEngine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final float PenUnits = 0.01f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final int MinPenUnits = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final int MinPenUnitsAA = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final float MinPenSizeAA = PenUnits * MinPenUnitsAA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final float UPPER_BND = Float.MAX_VALUE / 2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final float LOWER_BND = -UPPER_BND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final int RasterizerCaps[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        Rasterizer.BUTT, Rasterizer.ROUND, Rasterizer.SQUARE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final int RasterizerCorners[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Rasterizer.MITER, Rasterizer.ROUND, Rasterizer.BEVEL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static float[] getTransformMatrix(AffineTransform transform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        float matrix[] = new float[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        double dmatrix[] = new double[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        transform.getMatrix(dmatrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        for (int i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            matrix[i] = (float) dmatrix[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return matrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public Shape createStrokedShape(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                    float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                    int caps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                    int join,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                    float miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                    float dashes[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                    float dashphase)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        FillAdapter filler = new FillAdapter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        PathStroker stroker = new PathStroker(filler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        PathDasher dasher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            PathConsumer consumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            stroker.setPenDiameter(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            stroker.setPenT4(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            stroker.setCaps(RasterizerCaps[caps]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            stroker.setCorners(RasterizerCorners[join], miterlimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (dashes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                dasher = new PathDasher(stroker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                dasher.setDash(dashes, dashphase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                dasher.setDashT4(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                consumer = dasher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                consumer = stroker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            feedConsumer(consumer, src.getPathIterator(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            stroker.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (dasher != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                dasher.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return filler.getShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public void strokeTo(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                         AffineTransform transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                         BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                         boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                         boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                         boolean antialias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                         PathConsumer2D sr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        PathStroker stroker = new PathStroker(sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        PathConsumer consumer = stroker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        float matrix[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (!thin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            stroker.setPenDiameter(bs.getLineWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (transform != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                matrix = getTransformMatrix(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            stroker.setPenT4(matrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            stroker.setPenFitting(PenUnits, MinPenUnits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        stroker.setCaps(RasterizerCaps[bs.getEndCap()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        stroker.setCorners(RasterizerCorners[bs.getLineJoin()],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                           bs.getMiterLimit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        float[] dashes = bs.getDashArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (dashes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            PathDasher dasher = new PathDasher(stroker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            dasher.setDash(dashes, bs.getDashPhase());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (transform != null && matrix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                matrix = getTransformMatrix(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            dasher.setDashT4(matrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            consumer = dasher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            PathIterator pi = src.getPathIterator(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            feedConsumer(pi, consumer, normalize, 0.25f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } catch (PathException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw new InternalError("Unable to Stroke shape ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                    e.getMessage()+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            while (consumer != null && consumer != sr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                PathConsumer next = consumer.getConsumer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                consumer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                consumer = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Feed a path from a PathIterator to a Ductus PathConsumer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public static void feedConsumer(PathIterator pi, PathConsumer consumer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                    boolean normalize, float norm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        throws PathException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        consumer.beginPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        boolean pathClosed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        boolean skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        boolean subpathStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        float mx = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        float my = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        float point[]  = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        float rnd = (0.5f - norm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        float ax = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        float ay = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            int type = pi.currentSegment(point);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (pathClosed == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                pathClosed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                if (type != PathIterator.SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    // Force current point back to last moveto point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    consumer.beginSubpath(mx, my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (normalize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    index = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    index = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    float ox = point[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    float oy = point[index+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    float newax = (float) Math.floor(ox + rnd) + norm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    float neway = (float) Math.floor(oy + rnd) + norm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    point[index] = newax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    point[index+1] = neway;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    newax -= ox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    neway -= oy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                        point[0] += ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        point[1] += ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        point[2] += newax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        point[3] += neway;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        point[0] += (newax + ax) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                        point[1] += (neway + ay) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    ax = newax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    ay = neway;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                /* Checking SEG_MOVETO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                 * and Infinity values. Skipping next path segment in case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                 * invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    point[1] < UPPER_BND && point[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    mx = point[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    my = point[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    consumer.beginSubpath(mx, my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    skip = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                /* Checking SEG_LINETO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                 * and Infinity values. Ignoring current path segment in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                 * of invalid data. If segment is skipped its endpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                 * (if valid) is used to begin new subpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    point[1] < UPPER_BND && point[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        consumer.beginSubpath(point[0], point[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                        consumer.appendLine(point[0], point[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                // Quadratic curves take two points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                /* Checking SEG_QUADTO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                 * and Infinity values. Ignoring current path segment in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                 * of invalid endpoints's data. Equivalent to the SEG_LINETO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                 * if endpoint coordinates are valid but there are invalid data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                 * amoung other coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                if (point[2] < UPPER_BND && point[2] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    point[3] < UPPER_BND && point[3] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        consumer.beginSubpath(point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            point[1] < UPPER_BND && point[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                            consumer.appendQuadratic(point[0], point[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                                     point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                            consumer.appendLine(point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                // Cubic curves take three points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                /* Checking SEG_CUBICTO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                 * and Infinity values. Ignoring current path segment in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                 * of invalid endpoints's data. Equivalent to the SEG_LINETO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                 * if endpoint coordinates are valid but there are invalid data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                 * amoung other coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                if (point[4] < UPPER_BND && point[4] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    point[5] < UPPER_BND && point[5] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                        consumer.beginSubpath(point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                            point[1] < UPPER_BND && point[1] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                            point[2] < UPPER_BND && point[2] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                            point[3] < UPPER_BND && point[3] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                            consumer.appendCubic(point[0], point[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                                 point[2], point[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                                 point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                            consumer.appendLine(point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                if (subpathStarted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    consumer.closedSubpath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    subpathStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    pathClosed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        consumer.endPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    private static Rasterizer theRasterizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public synchronized static Rasterizer getRasterizer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        Rasterizer r = theRasterizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            r = new Rasterizer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            theRasterizer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public synchronized static void dropRasterizer(Rasterizer r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        r.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        theRasterizer = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public float getMinimumAAPenSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return MinPenSizeAA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public AATileGenerator getAATileGenerator(Shape s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                              AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                              Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                              BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                              boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                              boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                              int bbox[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        Rasterizer r = getRasterizer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        PathIterator pi = s.getPathIterator(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (bs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            float matrix[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            r.setUsage(Rasterizer.STROKE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (thin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                r.setPenDiameter(MinPenSizeAA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                r.setPenDiameter(bs.getLineWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    matrix = getTransformMatrix(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    r.setPenT4(matrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                r.setPenFitting(PenUnits, MinPenUnitsAA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            r.setCaps(RasterizerCaps[bs.getEndCap()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            r.setCorners(RasterizerCorners[bs.getLineJoin()],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                         bs.getMiterLimit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            float[] dashes = bs.getDashArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (dashes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                r.setDash(dashes, bs.getDashPhase());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                if (at != null && matrix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    matrix = getTransformMatrix(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                r.setDashT4(matrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            r.setUsage(pi.getWindingRule() == PathIterator.WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                       ? Rasterizer.EOFILL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                       : Rasterizer.NZFILL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        r.beginPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            boolean pathClosed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            boolean skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            boolean subpathStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            float mx = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            float my = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            float point[]  = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            float ax = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            float ay = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                int type = pi.currentSegment(point);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                if (pathClosed == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    pathClosed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    if (type != PathIterator.SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        // Force current point back to last moveto point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        r.beginSubpath(mx, my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                if (normalize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        index = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        index = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                        index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        float ox = point[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        float oy = point[index+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        float newax = (float) Math.floor(ox) + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        float neway = (float) Math.floor(oy) + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        point[index] = newax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        point[index+1] = neway;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        newax -= ox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        neway -= oy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                            point[0] += ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                            point[1] += ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                            point[2] += newax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                            point[3] += neway;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                            point[0] += (newax + ax) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                            point[1] += (neway + ay) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                        case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        ax = newax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        ay = neway;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                   /* Checking SEG_MOVETO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    * [LOWER_BND, UPPER_BND] range. This check also handles NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    * and Infinity values. Skipping next path segment in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    * of invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    if (point[0] < UPPER_BND &&  point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        point[1] < UPPER_BND &&  point[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        mx = point[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                        my = point[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        r.beginSubpath(mx, my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                        subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        skip = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    /* Checking SEG_LINETO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                     * [LOWER_BND, UPPER_BND] range. This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                     * NaN and Infinity values. Ignoring current path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                     * in case of invalid data. If segment is skipped its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                     * endpoint (if valid) is used to begin new subpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                        point[1] < UPPER_BND && point[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                        if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                            r.beginSubpath(point[0], point[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                            skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                            r.appendLine(point[0], point[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    // Quadratic curves take two points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    /* Checking SEG_QUADTO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                     * [LOWER_BND, UPPER_BND] range. This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                     * NaN and Infinity values. Ignoring current path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                     * in case of invalid endpoints's data. Equivalent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                     * SEG_LINETO if endpoint coordinates are valid but there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                     * are invalid data amoung other coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    if (point[2] < UPPER_BND && point[2] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        point[3] < UPPER_BND && point[3] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                        if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                            r.beginSubpath(point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                            subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                            skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                            if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                                point[1] < UPPER_BND && point[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                r.appendQuadratic(point[0], point[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                                  point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                r.appendLine(point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    // Cubic curves take three points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    /* Checking SEG_CUBICTO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                     * [LOWER_BND, UPPER_BND] range. This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                     * NaN and Infinity values. Ignoring  current path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                     * in case of invalid endpoints's data. Equivalent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                     * SEG_LINETO if endpoint coordinates are valid but there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                     * are invalid data amoung other coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    if (point[4] < UPPER_BND && point[4] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        point[5] < UPPER_BND && point[5] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                        if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                            r.beginSubpath(point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                            subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                            skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                            if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                point[1] < UPPER_BND && point[1] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                point[2] < UPPER_BND && point[2] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                point[3] < UPPER_BND && point[3] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                r.appendCubic(point[0], point[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                              point[2], point[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                              point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                r.appendLine(point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    if (subpathStarted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                        r.closedSubpath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        subpathStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                        pathClosed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            r.endPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            r.getAlphaBox(bbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            clip.clipBoxToBounds(bbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (bbox[0] >= bbox[2] || bbox[1] >= bbox[3]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                dropRasterizer(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            r.setOutputArea(bbox[0], bbox[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                            bbox[2] - bbox[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                            bbox[3] - bbox[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        } catch (PRException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
             * This exeption is thrown from the native part of the Ductus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
             * (only in case of a debug build) to indicate that some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
             * segments of the path have very large coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
             * See 4485298 for more info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            System.err.println("DuctusRenderingEngine.getAATileGenerator: "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   638
    /**
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   639
     * {@inheritDoc}
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   640
     */
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   641
    @Override
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   642
    public AATileGenerator getAATileGenerator(double x, double y,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   643
                                              double dx1, double dy1,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   644
                                              double dx2, double dy2,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   645
                                              double lw1, double lw2,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   646
                                              Region clip,
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   647
                                              int bbox[])
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   648
    {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   649
        // REMIND: Deal with large coordinates!
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   650
        double ldx1, ldy1, ldx2, ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   651
        boolean innerpgram = (lw1 > 0 && lw2 > 0);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   652
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   653
        if (innerpgram) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   654
            ldx1 = dx1 * lw1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   655
            ldy1 = dy1 * lw1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   656
            ldx2 = dx2 * lw2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   657
            ldy2 = dy2 * lw2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   658
            x -= (ldx1 + ldx2) / 2.0;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   659
            y -= (ldy1 + ldy2) / 2.0;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   660
            dx1 += ldx1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   661
            dy1 += ldy1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   662
            dx2 += ldx2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   663
            dy2 += ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   664
            if (lw1 > 1 && lw2 > 1) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   665
                // Inner parallelogram was entirely consumed by stroke...
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   666
                innerpgram = false;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   667
            }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   668
        } else {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   669
            ldx1 = ldy1 = ldx2 = ldy2 = 0;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   670
        }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   671
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   672
        Rasterizer r = getRasterizer();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   673
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   674
        r.setUsage(Rasterizer.EOFILL);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   675
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   676
        r.beginPath();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   677
        r.beginSubpath((float) x, (float) y);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   678
        r.appendLine((float) (x+dx1), (float) (y+dy1));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   679
        r.appendLine((float) (x+dx1+dx2), (float) (y+dy1+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   680
        r.appendLine((float) (x+dx2), (float) (y+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   681
        r.closedSubpath();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   682
        if (innerpgram) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   683
            x += ldx1 + ldx2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   684
            y += ldy1 + ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   685
            dx1 -= 2.0 * ldx1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   686
            dy1 -= 2.0 * ldy1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   687
            dx2 -= 2.0 * ldx2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   688
            dy2 -= 2.0 * ldy2;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   689
            r.beginSubpath((float) x, (float) y);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   690
            r.appendLine((float) (x+dx1), (float) (y+dy1));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   691
            r.appendLine((float) (x+dx1+dx2), (float) (y+dy1+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   692
            r.appendLine((float) (x+dx2), (float) (y+dy2));
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   693
            r.closedSubpath();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   694
        }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   695
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   696
        try {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   697
            r.endPath();
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   698
            r.getAlphaBox(bbox);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   699
            clip.clipBoxToBounds(bbox);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   700
            if (bbox[0] >= bbox[2] || bbox[1] >= bbox[3]) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   701
                dropRasterizer(r);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   702
                return null;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   703
            }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   704
            r.setOutputArea(bbox[0], bbox[1],
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   705
                            bbox[2] - bbox[0],
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   706
                            bbox[3] - bbox[1]);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   707
        } catch (PRException e) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   708
            /*
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   709
             * This exeption is thrown from the native part of the Ductus
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   710
             * (only in case of a debug build) to indicate that some
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   711
             * segments of the path have very large coordinates.
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   712
             * See 4485298 for more info.
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   713
             */
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   714
            System.err.println("DuctusRenderingEngine.getAATileGenerator: "+e);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   715
        }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   716
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   717
        return r;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   718
    }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   719
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    private void feedConsumer(PathConsumer consumer, PathIterator pi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            consumer.beginPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            boolean pathClosed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            float mx = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            float my = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            float point[]  = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                int type = pi.currentSegment(point);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                if (pathClosed == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                    pathClosed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    if (type != PathIterator.SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                        // Force current point back to last moveto point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                        consumer.beginSubpath(mx, my);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    mx = point[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    my = point[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    consumer.beginSubpath(point[0], point[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    consumer.appendLine(point[0], point[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    consumer.appendQuadratic(point[0], point[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                                             point[2], point[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    consumer.appendCubic(point[0], point[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                                         point[2], point[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                         point[4], point[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    consumer.closedSubpath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    pathClosed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            consumer.endPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        } catch (PathException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            throw new InternalError("Unable to Stroke shape ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                                    e.getMessage()+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    private class FillAdapter implements PathConsumer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        boolean closed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        Path2D.Float path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        public FillAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            // Ductus only supplies float coordinates so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            // Path2D.Double is not necessary here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            path = new Path2D.Float(Path2D.WIND_NON_ZERO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        public Shape getShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        public PathConsumer getConsumer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        public void beginPath() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        public void beginSubpath(float x0, float y0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            if (closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                path.closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            path.moveTo(x0, y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        public void appendLine(float x1, float y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            path.lineTo(x1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        public void appendQuadratic(float xm, float ym, float x1, float y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            path.quadTo(xm, ym, x1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        public void appendCubic(float xm, float ym,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                                float xn, float yn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                                float x1, float y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            path.curveTo(xm, ym, xn, yn, x1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        public void closedSubpath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            closed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        public void endPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            if (closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                path.closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        public void useProxy(FastPathProducer proxy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            throws PathException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            proxy.sendTo(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        public long getCPathConsumer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
}