jdk/src/java.desktop/share/classes/sun/java2d/loops/ProcessPath.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 2005, 2014, 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.java2d.loops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.Path2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.QuadCurve2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.awt.SunHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/* This is the java implementation of the native code from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * src/share/native/sun/java2d/loops/ProcessPath.[c,h]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This code is written to be as much similar to the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * as it possible. So, it sometimes does not follow java naming conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * It's important to keep this code synchronized with native one.  See more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * comments, description and high level scheme of the rendering process in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * ProcessPath.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class ProcessPath {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /* Public interfaces and methods for drawing and filling general paths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static abstract class DrawHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        public int xMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        public int yMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        public int xMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        public int yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        public float xMinf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        public float yMinf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        public float xMaxf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        public float yMaxf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        public int strokeControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        public DrawHandler(int xMin, int yMin, int xMax, int yMax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                           int strokeControl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            setBounds(xMin, yMin, xMax, yMax, strokeControl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        public void setBounds(int xMin, int yMin, int xMax, int yMax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            this.xMin = xMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            this.yMin = yMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            this.xMax = xMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            this.yMax = yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            /*                Setting up fractional clipping box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
             * We are using following float -> int mapping:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
             *      xi = floor(xf + 0.5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             * So, fractional values that hit the [xmin, xmax) integer interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
             * will be situated inside the [xmin-0.5, xmax - 0.5) fractional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             * interval. We are using EPSF constant to provide that upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             * boundary is not included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            xMinf = xMin - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            yMinf = yMin - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            xMaxf = xMax - 0.5f - EPSF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            yMaxf = yMax - 0.5f - EPSF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        public void setBounds(int xMin, int yMin, int xMax, int yMax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                              int strokeControl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            this.strokeControl = strokeControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            setBounds(xMin, yMin, xMax, yMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public void adjustBounds(int bxMin, int byMin, int bxMax, int byMax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (xMin > bxMin) bxMin = xMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (xMax < bxMax) bxMax = xMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (yMin > byMin) byMin = yMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (yMax < byMax) byMax = yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            setBounds(bxMin, byMin, bxMax, byMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public DrawHandler(int xMin, int yMin, int xMax, int yMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            this(xMin, yMin, xMax, yMax, SunHints.INTVAL_STROKE_DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        public abstract void drawLine(int x0, int y0, int x1, int y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        public abstract void drawPixel(int x0, int y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        public abstract void drawScanline(int x0, int x1, int y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public interface EndSubPathHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        public void processEndSubPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public static final int PH_MODE_DRAW_CLIP = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static final int PH_MODE_FILL_CLIP = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static abstract class ProcessHandler implements EndSubPathHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        DrawHandler dhnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        int clipMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        public ProcessHandler(DrawHandler dhnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                              int clipMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            this.dhnd = dhnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            this.clipMode = clipMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        public abstract void processFixedLine(int x1, int y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                              int x2, int y2, int [] pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                              boolean checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                              boolean endSubPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static EndSubPathHandler noopEndSubPathHandler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        new EndSubPathHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            public void processEndSubPath() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static boolean fillPath(DrawHandler dhnd, Path2D.Float p2df,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                   int transX, int transY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        FillProcessHandler fhnd = new FillProcessHandler(dhnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (!doProcessPath(fhnd, p2df, transX, transY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        FillPolygon(fhnd, p2df.getWindingRule());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public static boolean drawPath(DrawHandler dhnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                   EndSubPathHandler endSubPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                   Path2D.Float p2df,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                   int transX, int transY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return doProcessPath(new DrawProcessHandler(dhnd, endSubPath),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                             p2df, transX, transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public static boolean drawPath(DrawHandler dhnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                   Path2D.Float p2df,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                   int transX, int transY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return doProcessPath(new DrawProcessHandler(dhnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                                    noopEndSubPathHandler),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                             p2df, transX, transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /* Private implementation of the rendering process */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /* Boundaries used for skipping huge path segments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final float UPPER_BND = Float.MAX_VALUE/4.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final float LOWER_BND = -UPPER_BND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /* Precision (in bits) used in forward differencing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final int FWD_PREC = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /* Precision (in bits) used for the rounding in the midpoint test */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private static final int MDP_PREC = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static final int MDP_MULT = 1 << MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static final int MDP_HALF_MULT = MDP_MULT >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /* Boundaries used for clipping large path segments (those are inside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * [UPPER/LOWER]_BND boundaries)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final int UPPER_OUT_BND = 1 << (30 - MDP_PREC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static final int LOWER_OUT_BND = -UPPER_OUT_BND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /* Calculation boundaries. They are used for switching to the more slow but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * allowing larger input values method of calculation of the initial values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * of the scan converted line segments inside the FillPolygon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static final float CALC_UBND = 1 << (30 - MDP_PREC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final float CALC_LBND = -CALC_UBND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /* Following constants are used for providing open boundaries of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * intervals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public static final int EPSFX = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final float EPSF = ((float)EPSFX)/MDP_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /* Bit mask used to separate whole part from the fraction part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private static final int MDP_W_MASK = -MDP_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /* Bit mask used to separate fractional part from the whole part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private static final int MDP_F_MASK = MDP_MULT - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *                  Constants for the forward differencing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *                      of the cubic and quad curves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /* Maximum size of the cubic curve (calculated as the size of the bounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * box of the control points) which could be rendered without splitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private static final int MAX_CUB_SIZE = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /* Maximum size of the quad curve (calculated as the size of the bounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * box of the control points) which could be rendered without splitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private static final int MAX_QUAD_SIZE = 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /* Default power of 2 steps used in the forward differencing. Here DF prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * stands for DeFault. Constants below are used as initial values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * adaptive forward differencing algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private static final int DF_CUB_STEPS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private static final int DF_QUAD_STEPS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /* Shift of the current point of the curve for preparing to the midpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private static final int DF_CUB_SHIFT = FWD_PREC + DF_CUB_STEPS*3 -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                            MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    private static final int DF_QUAD_SHIFT = FWD_PREC + DF_QUAD_STEPS*2 -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                             MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /* Default amount of steps of the forward differencing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private static final int DF_CUB_COUNT = (1<<DF_CUB_STEPS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private static final int DF_QUAD_COUNT = (1<<DF_QUAD_STEPS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /* Default boundary constants used to check the necessity of the restepping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private static final int DF_CUB_DEC_BND = 1<<DF_CUB_STEPS*3 + FWD_PREC + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private static final int DF_CUB_INC_BND = 1<<DF_CUB_STEPS*3 + FWD_PREC - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private static final int DF_QUAD_DEC_BND = 1<<DF_QUAD_STEPS*2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                                  FWD_PREC + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private static final int DF_QUAD_INC_BND = 1<<DF_QUAD_STEPS*2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                                  FWD_PREC - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /* Multipliers for the coefficients of the polynomial form of the cubic and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * quad curves representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private static final int CUB_A_SHIFT = FWD_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private static final int CUB_B_SHIFT = (DF_CUB_STEPS + FWD_PREC + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private static final int CUB_C_SHIFT = (DF_CUB_STEPS*2 + FWD_PREC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private static final int CUB_A_MDP_MULT = (1<<CUB_A_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private static final int CUB_B_MDP_MULT = (1<<CUB_B_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private static final int CUB_C_MDP_MULT = (1<<CUB_C_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private static final int QUAD_A_SHIFT = FWD_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static final int QUAD_B_SHIFT = (DF_QUAD_STEPS + FWD_PREC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static final int QUAD_A_MDP_MULT = (1<<QUAD_A_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static final int QUAD_B_MDP_MULT = (1<<QUAD_B_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /* Clipping macros for drawing and filling algorithms */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private static float CLIP(float a1, float b1, float a2, float b2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                              double t) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   283
        return (float)(b1 + (t - a1)*(b2 - b1) / (a2 - a1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private static int CLIP(int a1, int b1, int a2, int b2, double t) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   287
        return (int)(b1 + (t - a1)*(b2 - b1) / (a2 - a1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static final int CRES_MIN_CLIPPED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    private static final int CRES_MAX_CLIPPED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    private static final int CRES_NOT_CLIPPED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private static final int CRES_INVISIBLE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private static boolean IS_CLIPPED(int res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return res == CRES_MIN_CLIPPED || res == CRES_MAX_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /* This is java implementation of the macro from ProcessGeneralPath.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * To keep the logic of the java code similar to the native one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * array and set of indexes are used to point out the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private static int TESTANDCLIP(float LINE_MIN, float LINE_MAX, float[] c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                   int a1, int b1, int a2, int b2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        double t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int res = CRES_NOT_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (c[a1] < (LINE_MIN) || c[a1] > (LINE_MAX)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (c[a1] < (LINE_MIN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                if (c[a2] < (LINE_MIN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    return CRES_INVISIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                res = CRES_MIN_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                t = (LINE_MIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                if (c[a2] > (LINE_MAX)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    return CRES_INVISIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                res = CRES_MAX_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                t = (LINE_MAX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            c[b1] = CLIP(c[a1], c[b1], c[a2], c[b2], t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            c[a1] = (float)t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /* Integer version of the method above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static int TESTANDCLIP(int LINE_MIN, int LINE_MAX, int[] c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                   int a1, int b1, int a2, int b2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        double t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        int res = CRES_NOT_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (c[a1] < (LINE_MIN) || c[a1] > (LINE_MAX)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (c[a1] < (LINE_MIN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                if (c[a2] < (LINE_MIN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    return CRES_INVISIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                res = CRES_MIN_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                t = (LINE_MIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                if (c[a2] > (LINE_MAX)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    return CRES_INVISIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                res = CRES_MAX_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                t = (LINE_MAX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            c[b1] = CLIP(c[a1], c[b1], c[a2], c[b2], t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            c[a1] = (int)t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /* Following method is used for clipping and clumping filled shapes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * An example of this process is shown on the picture below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *                      ----+          ----+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *                    |/    |        |/    |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *                    +     |        +     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *                   /|     |        I     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *                  / |     |        I     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *                  | |     |  ===>  I     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *                  \ |     |        I     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *                   \|     |        I     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *                    +     |        +     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *                    |\    |        |\    |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *                    | ----+        | ----+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *                 boundary       boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * We can only perform clipping in case of right side of the output area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * because all segments passed out the right boundary don't influence on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * result of scan conversion algorithm (it correctly handles half open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * contours).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * This is java implementation of the macro from ProcessGeneralPath.c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * To keep the logic of the java code similar to the native one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * array and set of indexes are used to point out the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private static int CLIPCLAMP(float LINE_MIN, float LINE_MAX, float[] c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                 int a1, int b1, int a2, int b2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                 int a3, int b3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        c[a3] = c[a1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        c[b3] = c[b1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int res = TESTANDCLIP(LINE_MIN, LINE_MAX, c, a1, b1, a2, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (res == CRES_MIN_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            c[a3] = c[a1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } else if (res == CRES_MAX_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            c[a3] = c[a1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            res = CRES_MAX_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else if (res == CRES_INVISIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (c[a1] > LINE_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                res =  CRES_INVISIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                c[a1] = LINE_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                c[a2] = LINE_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                res = CRES_NOT_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /* Integer version of the method above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    private static int CLIPCLAMP(int LINE_MIN, int LINE_MAX, int[] c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                 int a1, int b1, int a2, int b2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                 int a3, int b3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        c[a3] = c[a1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        c[b3] = c[b1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int res = TESTANDCLIP(LINE_MIN, LINE_MAX, c, a1, b1, a2, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (res == CRES_MIN_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            c[a3] = c[a1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        } else if (res == CRES_MAX_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            c[a3] = c[a1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            res = CRES_MAX_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        } else if (res == CRES_INVISIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (c[a1] > LINE_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                res =  CRES_INVISIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                c[a1] = LINE_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                c[a2] = LINE_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                res = CRES_NOT_CLIPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private static class DrawProcessHandler extends ProcessHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        EndSubPathHandler processESP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        public DrawProcessHandler(DrawHandler dhnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                  EndSubPathHandler processESP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            super(dhnd, PH_MODE_DRAW_CLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            this.dhnd = dhnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            this.processESP = processESP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        public void processEndSubPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            processESP.processEndSubPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        void PROCESS_LINE(int fX0, int fY0, int fX1, int fY1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                          boolean checkBounds, int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            int X0 = fX0 >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            int Y0 = fY0 >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            int X1 = fX1 >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            int Y1 = fY1 >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
           /* Handling lines having just one pixel */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            if (((X0^X1) | (Y0^Y1)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                if (checkBounds &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    (dhnd.yMin > Y0  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                     dhnd.yMax <= Y0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                     dhnd.xMin > X0  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                     dhnd.xMax <= X0)) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                if (pixelInfo[0] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    pixelInfo[0] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    pixelInfo[1] = X0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    pixelInfo[2] = Y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    pixelInfo[3] = X0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    pixelInfo[4] = Y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    dhnd.drawPixel(X0, Y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                } else if ((X0 != pixelInfo[3] || Y0 != pixelInfo[4]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                           (X0 != pixelInfo[1] || Y0 != pixelInfo[2])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    dhnd.drawPixel(X0, Y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    pixelInfo[3] = X0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    pixelInfo[4] = Y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (!checkBounds ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                (dhnd.yMin <= Y0  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                 dhnd.yMax > Y0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                 dhnd.xMin <= X0  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                 dhnd.xMax > X0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                /* Switch off first pixel of the line before drawing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                if (pixelInfo[0] == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    ((pixelInfo[1] == X0 && pixelInfo[2] == Y0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                     (pixelInfo[3] == X0 && pixelInfo[4] == Y0)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    dhnd.drawPixel(X0, Y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            dhnd.drawLine(X0, Y0, X1, Y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (pixelInfo[0] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                pixelInfo[0] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                pixelInfo[1] = X0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                pixelInfo[2] = Y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                pixelInfo[3] = X0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                pixelInfo[4] = Y0;
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 on last pixel of the line if it was already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
             * drawn during rendering of the previous segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            if ((pixelInfo[1] == X1 && pixelInfo[2] == Y1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                (pixelInfo[3] == X1 && pixelInfo[4] == Y1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                if (checkBounds &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    (dhnd.yMin > Y1  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                     dhnd.yMax <= Y1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                     dhnd.xMin > X1  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                     dhnd.xMax <= X1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                dhnd.drawPixel(X1, Y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            pixelInfo[3] = X1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            pixelInfo[4] = Y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        void PROCESS_POINT(int fX, int fY, boolean checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                           int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            int _X = fX>> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            int _Y = fY>> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (checkBounds &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                (dhnd.yMin > _Y  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                 dhnd.yMax <= _Y ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                 dhnd.xMin > _X  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                 dhnd.xMax <= _X)) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
             *  (_X,_Y) should be inside boundaries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
             *  assert(dhnd.yMin <= _Y &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
             *         dhnd.yMax >  _Y &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
             *         dhnd.xMin <= _X &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
             *         dhnd.xMax >  _X);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (pixelInfo[0] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                pixelInfo[0] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                pixelInfo[1] = _X;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                pixelInfo[2] = _Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                pixelInfo[3] = _X;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                pixelInfo[4] = _Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                dhnd.drawPixel(_X, _Y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            } else if ((_X != pixelInfo[3] || _Y != pixelInfo[4]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                       (_X != pixelInfo[1] || _Y != pixelInfo[2])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                dhnd.drawPixel(_X, _Y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                pixelInfo[3] = _X;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                pixelInfo[4] = _Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        /*                  Drawing line with subpixel endpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         * (x1, y1), (x2, y2) -  fixed point coordinates of the endpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
         *                       with MDP_PREC bits for the fractional part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
         * pixelInfo          -  structure which keeps drawing info for avoiding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         *                       multiple drawing at the same position on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         *                       screen (required for the XOR mode of drawing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         *                          pixelInfo[0]   - state of the drawing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
         *                                           0 - no pixel drawn between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
         *                                           moveTo/close of the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         *                                           1 - there are drawn pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         *                          pixelInfo[1,2] - first pixel of the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         *                                           between moveTo/close of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         *                                           path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         *                          pixelInfo[3,4] - last drawn pixel between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         *                                           moveTo/close of the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * checkBounds        - flag showing necessity of checking the clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        public void  processFixedLine(int x1, int y1, int x2, int y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                      int[] pixelInfo, boolean checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                      boolean endSubPath)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            /* Checking if line is inside a (X,Y),(X+MDP_MULT,Y+MDP_MULT) box */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            int c = ((x1 ^ x2) | (y1 ^ y2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            int rx1, ry1, rx2, ry2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if ((c & MDP_W_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                /* Checking for the segments with integer coordinates having
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                 * the same start and end points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                if (c == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    PROCESS_POINT(x1 + MDP_HALF_MULT, y1 + MDP_HALF_MULT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                  checkBounds, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (x1 == x2 || y1 == y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                rx1 = x1 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                rx2 = x2 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                ry1 = y1 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                ry2 = y2 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                /* Neither dx nor dy can be zero because of the check above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                int dx = x2 - x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                int dy = y2 - y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                /* Floor of x1, y1, x2, y2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                int fx1 = x1 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                int fy1 = y1 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                int fx2 = x2 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                int fy2 = y2 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                /* Processing first endpoint */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                if (fx1 == x1 || fy1 == y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    /* Adding MDP_HALF_MULT to the [xy]1 if f[xy]1 == [xy]1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                     * will not affect the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    rx1 = x1 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    ry1 = y1 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    /* Boundary at the direction from (x1,y1) to (x2,y2) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    int bx1 = (x1 < x2) ? fx1 + MDP_MULT : fx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    int by1 = (y1 < y2) ? fy1 + MDP_MULT : fy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    /* intersection with column bx1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    int cross = y1 + ((bx1 - x1)*dy)/dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    if (cross >= fy1 && cross <= fy1 + MDP_MULT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                        rx1 = bx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        ry1 = cross + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        /* intersection with row by1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        cross = x1 + ((by1 - y1)*dx)/dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        rx1 = cross + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                        ry1 = by1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                /* Processing second endpoint */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                if (fx2 == x2 || fy2 == y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    /* Adding MDP_HALF_MULT to the [xy]2 if f[xy]2 == [xy]2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                     * will not affect the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    rx2 = x2 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    ry2 = y2 + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    /* Boundary at the direction from (x2,y2) to (x1,y1) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    int bx2 = (x1 > x2) ? fx2 + MDP_MULT : fx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    int by2 = (y1 > y2) ? fy2 + MDP_MULT : fy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    /* intersection with column bx2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    int cross = y2 + ((bx2 - x2)*dy)/dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    if (cross >= fy2 && cross <= fy2 + MDP_MULT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                        rx2 = bx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                        ry2 = cross + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                        /* intersection with row by2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        cross = x2 + ((by2 - y2)*dx)/dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                        rx2 = cross + MDP_HALF_MULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                        ry2 = by2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            PROCESS_LINE(rx1, ry1, rx2, ry2, checkBounds, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    /* Performing drawing of the monotonic in X and Y quadratic curves with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * sizes less than MAX_QUAD_SIZE by using forward differencing method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * calculation. See comments to the DrawMonotonicQuad in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * ProcessGeneralPath.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    private static void DrawMonotonicQuad(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                          float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                          boolean checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                          int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        int x0 = (int)(coords[0]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        int y0 = (int)(coords[1]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        int xe = (int)(coords[4]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        int ye = (int)(coords[5]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        /* Extracting fractional part of coordinates of first control point */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        int px = (x0 & (~MDP_W_MASK)) << DF_QUAD_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        int py = (y0 & (~MDP_W_MASK)) << DF_QUAD_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        /* Setting default amount of steps */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        int count = DF_QUAD_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        /* Setting default shift for preparing to the midpoint rounding */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        int shift =  DF_QUAD_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        int ax = (int)((coords[0] - 2*coords[2] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                         coords[4])*QUAD_A_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        int ay = (int)((coords[1] - 2*coords[3] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                         coords[5])*QUAD_A_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        int bx = (int)((-2*coords[0] + 2*coords[2])*QUAD_B_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        int by = (int)((-2*coords[1] + 2*coords[3])*QUAD_B_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        int ddpx = 2*ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        int ddpy = 2*ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        int dpx = ax + bx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        int dpy = ay + by;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        int x1, y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        int x2 = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        int y2 = y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        int maxDD = Math.max(Math.abs(ddpx),Math.abs(ddpy));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        int dx = xe - x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        int dy = ye - y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        int x0w = x0 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        int y0w = y0 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        /* Perform decreasing step in 2 times if slope of the first forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
         * difference changes too quickly (more than a pixel per step in X or Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
         * direction).  We can perform adjusting of the step size before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
         * rendering loop because the curvature of the quad curve remains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
         * same along all the curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        while (maxDD > DF_QUAD_DEC_BND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            dpx = (dpx<<1) - ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            dpy = (dpy<<1) - ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            count <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            maxDD >>= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            px <<=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            py <<=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            shift += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        while(count-- > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            px += dpx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            py += dpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            dpx += ddpx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            dpy += ddpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            x1 = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            y1 = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            x2 = x0w + (px >> shift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            y2 = y0w + (py >> shift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            /* Checking that we are not running out of the endpoint and bounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
             * violating coordinate.  The check is pretty simple because the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   747
             * curve passed to the DrawCubic already split into the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
             * monotonic in X and Y pieces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            /* Bounding x2 by xe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            if (((xe-x2)^dx) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                x2 = xe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            /* Bounding y2 by ye */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            if (((ye-y2)^dy) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                y2 = ye;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            hnd.processFixedLine(x1, y1, x2, y2, pixelInfo, checkBounds, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        /* We are performing one step less than necessary and use actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         * (xe,ye) endpoint of the curve instead of calculated. This prevent us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         * from running above the curve endpoint due to the accumulated errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         * during the iterations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        hnd.processFixedLine(x2, y2, xe, ye, pixelInfo, checkBounds, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Checking size of the quad curves and split them if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * Calling DrawMonotonicQuad for the curves of the appropriate size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Note: coords array could be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    private static void ProcessMonotonicQuad(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                                             float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                             int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        float[] coords1 = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        float tx, ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        float xMin, yMin, xMax, yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        xMin = xMax = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        yMin = yMax = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        for (int i = 2; i < 6; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            xMin = (xMin > coords[i])? coords[i] : xMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            xMax = (xMax < coords[i])? coords[i] : xMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            yMin = (yMin > coords[i + 1])? coords[i + 1] : yMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            yMax = (yMax < coords[i + 1])? coords[i + 1] : yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (hnd.clipMode == PH_MODE_DRAW_CLIP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
           /* In case of drawing we could just skip curves which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            * completely out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
           if (hnd.dhnd.xMaxf < xMin || hnd.dhnd.xMinf > xMax ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
               hnd.dhnd.yMaxf < yMin || hnd.dhnd.yMinf > yMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
               return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            /* In case of filling we could skip curves which are above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
             * below and behind the right boundary of the visible area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            if (hnd.dhnd.yMaxf < yMin || hnd.dhnd.yMinf > yMax ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                hnd.dhnd.xMaxf < xMin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            /* We could clamp x coordinates to the corresponding boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
             * if the curve is completely behind the left one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            if (hnd.dhnd.xMinf > xMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                coords[0] = coords[2] = coords[4] = hnd.dhnd.xMinf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (xMax - xMin > MAX_QUAD_SIZE || yMax - yMin > MAX_QUAD_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            coords1[4] = coords[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            coords1[5] = coords[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            coords1[2] = (coords[2] + coords[4])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            coords1[3] = (coords[3] + coords[5])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            coords[2] = (coords[0] + coords[2])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            coords[3] = (coords[1] + coords[3])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            coords[4] = coords1[0] = (coords[2] + coords1[2])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            coords[5] = coords1[1] = (coords[3] + coords1[3])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            ProcessMonotonicQuad(hnd, coords, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            ProcessMonotonicQuad(hnd, coords1, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            DrawMonotonicQuad(hnd, coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                              /* Set checkBounds parameter if curve intersects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                               * boundary of the visible area. We know that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                               * curve is visible, so the check is pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                               * simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                               */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                              hnd.dhnd.xMinf >= xMin ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                              hnd.dhnd.xMaxf <= xMax ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                              hnd.dhnd.yMinf >= yMin ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                              hnd.dhnd.yMaxf <= yMax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                              pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Split quadratic curve into monotonic in X and Y parts. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * ProcessMonotonicQuad for each monotonic piece of the curve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Note: coords array could be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    private static void ProcessQuad(ProcessHandler hnd, float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                                    int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        /* Temporary array for holding parameters corresponding to the extreme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
         * in X and Y points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        double params[] = new double[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        int cnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        double param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        /* Simple check for monotonicity in X before searching for the extreme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
         * points of the X(t) function. We first check if the curve is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * monotonic in X by seeing if all of the X coordinates are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         * ordered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        if ((coords[0] > coords[2] || coords[2] > coords[4]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            (coords[0] < coords[2] || coords[2] < coords[4]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            /* Searching for extreme points of the X(t) function  by solving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
             * dX(t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
             * ----  = 0 equation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
             *  dt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            double ax = coords[0] - 2*coords[2] + coords[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (ax != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                /* Calculating root of the following equation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                 * ax*t + bx = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                double bx = coords[0] - coords[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                param = bx/ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                if (param < 1.0 && param > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                    params[cnt++] = param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        /* Simple check for monotonicity in Y before searching for the extreme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
         * points of the Y(t) function. We first check if the curve is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         * monotonic in Y by seeing if all of the Y coordinates are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         * ordered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if ((coords[1] > coords[3] || coords[3] > coords[5]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            (coords[1] < coords[3] || coords[3] < coords[5]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            /* Searching for extreme points of the Y(t) function by solving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
             * dY(t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
             * ----- = 0 equation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
             *  dt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            double ay = coords[1] - 2*coords[3] + coords[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            if (ay != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                /* Calculating root of the following equation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                 * ay*t + by = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                double by = coords[1] - coords[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                param = by/ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                if (param < 1.0 && param > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    if (cnt > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                        /* Inserting parameter only if it differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                         * already stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                        if (params[0] >  param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                            params[cnt++] = params[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                            params[0] = param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                        } else if (params[0] <  param) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                            params[cnt++] = param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                        params[cnt++] = param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        /* Processing obtained monotonic parts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        switch(cnt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                ProcessFirstMonotonicPartOfQuad(hnd, coords, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                                (float)params[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                ProcessFirstMonotonicPartOfQuad(hnd, coords, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                                                (float)params[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                param = params[1] - params[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                if (param > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    ProcessFirstMonotonicPartOfQuad(hnd, coords, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                                           /* Scale parameter to match with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                                            * rest of the curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                                           (float)(param/(1.0 - params[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        ProcessMonotonicQuad(hnd,coords,pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * Bite the piece of the quadratic curve from start point till the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * corresponding to the specified parameter then call ProcessQuad for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * bitten part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * Note: coords array will be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    private static void ProcessFirstMonotonicPartOfQuad(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                                        float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                                        int[] pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                                        float t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        float[] coords1 = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        coords1[0] = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        coords1[1] = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        coords1[2] = coords[0] + t*(coords[2] - coords[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        coords1[3] = coords[1] + t*(coords[3] - coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        coords[2] = coords[2] + t*(coords[4] - coords[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        coords[3] = coords[3] + t*(coords[5] - coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        coords[0] = coords1[4] = coords1[2] + t*(coords[2] - coords1[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        coords[1] = coords1[5] = coords1[3] + t*(coords[3] - coords1[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        ProcessMonotonicQuad(hnd, coords1, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /* Performing drawing of the monotonic in X and Y cubic curves with sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * less than MAX_CUB_SIZE by using forward differencing method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * calculation.  See comments to the DrawMonotonicCubic in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * ProcessGeneralPath.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    private static void DrawMonotonicCubic(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                                           float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                                           boolean checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                                           int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        int x0 = (int)(coords[0]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        int y0 = (int)(coords[1]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        int xe = (int)(coords[6]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        int ye = (int)(coords[7]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        /* Extracting fractional part of coordinates of first control point */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        int px = (x0 & (~MDP_W_MASK)) << DF_CUB_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        int py = (y0 & (~MDP_W_MASK)) << DF_CUB_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        /* Setting default boundary values for checking first and second forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
         * difference for the necessity of the restepping. See comments to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         * boundary values in ProcessQuad for more info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        int incStepBnd = DF_CUB_INC_BND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        int decStepBnd = DF_CUB_DEC_BND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        /* Setting default amount of steps */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        int count = DF_CUB_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        /* Setting default shift for preparing to the midpoint rounding */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        int shift =  DF_CUB_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        int ax = (int)((-coords[0] + 3*coords[2] - 3*coords[4] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                 coords[6])*CUB_A_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        int ay = (int)((-coords[1] + 3*coords[3] - 3*coords[5] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                 coords[7])*CUB_A_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        int bx = (int)((3*coords[0] - 6*coords[2] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                 3*coords[4])*CUB_B_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        int by = (int)((3*coords[1] - 6*coords[3] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                 3*coords[5])*CUB_B_MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        int cx = (int)((-3*coords[0] + 3*coords[2])*(CUB_C_MDP_MULT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        int cy = (int)((-3*coords[1] + 3*coords[3])*(CUB_C_MDP_MULT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        int dddpx = 6*ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        int dddpy = 6*ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        int ddpx = dddpx + bx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        int ddpy = dddpy + by;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        int dpx = ax + (bx>>1) + cx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        int dpy = ay + (by>>1) + cy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        int x1, y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        int x2 = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        int y2 = y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        /* Calculating whole part of the first point of the curve */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        int x0w = x0 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        int y0w = y0 & MDP_W_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        int dx = xe - x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        int dy = ye - y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        while (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            /* Perform decreasing step in 2 times if necessary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            while (Math.abs(ddpx) > decStepBnd ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                   Math.abs(ddpy) > decStepBnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                ddpx = (ddpx<<1) - dddpx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                ddpy = (ddpy<<1) - dddpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                dpx = (dpx<<2) - (ddpx>>1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                dpy = (dpy<<2) - (ddpy>>1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                count <<=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                decStepBnd <<=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                incStepBnd <<=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                px <<=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                py <<=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                shift += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            /* Perform increasing step in 2 times if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
             * Note: we could do it only in even steps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            while ((count & 1) == 0 && shift > DF_CUB_SHIFT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                   Math.abs(dpx) <= incStepBnd &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                   Math.abs(dpy) <= incStepBnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                dpx = (dpx>>2) + (ddpx>>3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                dpy = (dpy>>2) + (ddpy>>3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                ddpx = (ddpx + dddpx)>>1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                ddpy = (ddpy + dddpy)>>1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                count >>=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                decStepBnd >>=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                incStepBnd >>=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                px >>=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                py >>=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                shift -= 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            count--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            /* Performing one step less than necessary and use actual (xe,ye)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
             * curve's endpoint instead of calculated. This prevent us from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
             * running above the curve endpoint due to the accumulated errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
             * during the iterations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                px += dpx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                py += dpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                dpx += ddpx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                dpy += ddpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                ddpx += dddpx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                ddpy += dddpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                x1 = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                y1 = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                x2 = x0w + (px >> shift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                y2 = y0w + (py >> shift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                /* Checking that we are not running out of the endpoint and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                 * bounding violating coordinate.  The check is pretty simple
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
  1108
                 * because the curve passed to the DrawCubic already split
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                 * into the monotonic in X and Y pieces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                /* Bounding x2 by xe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                if (((xe-x2)^dx) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    x2 = xe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                /* Bounding y2 by ye */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                if (((ye-y2)^dy) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                    y2 = ye;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                hnd.processFixedLine(x1, y1, x2, y2, pixelInfo, checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                                     false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                hnd.processFixedLine(x2, y2, xe, ye, pixelInfo, checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                                     false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * Checking size of the cubic curves and split them if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * Calling DrawMonotonicCubic for the curves of the appropriate size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * Note: coords array could be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    private static void ProcessMonotonicCubic(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                                              float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                                              int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        float[] coords1 = new float[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        float tx, ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        float xMin, xMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        float yMin, yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        xMin = xMax = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        yMin = yMax = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        for (int i = 2; i < 8; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            xMin = (xMin > coords[i])? coords[i] : xMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            xMax = (xMax < coords[i])? coords[i] : xMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            yMin = (yMin > coords[i + 1])? coords[i + 1] : yMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            yMax = (yMax < coords[i + 1])? coords[i + 1] : yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        if (hnd.clipMode == PH_MODE_DRAW_CLIP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            /* In case of drawing we could just skip curves which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
             * completely out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            if (hnd.dhnd.xMaxf < xMin || hnd.dhnd.xMinf > xMax ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                hnd.dhnd.yMaxf < yMin || hnd.dhnd.yMinf > yMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            /* In case of filling we could skip curves which are above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
             * below and behind the right boundary of the visible area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            if (hnd.dhnd.yMaxf < yMin || hnd.dhnd.yMinf > yMax ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                hnd.dhnd.xMaxf < xMin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            /* We could clamp x coordinates to the corresponding boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
             * if the curve is completely behind the left one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            if (hnd.dhnd.xMinf > xMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                coords[0] = coords[2] = coords[4] = coords[6] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    hnd.dhnd.xMinf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        if (xMax - xMin > MAX_CUB_SIZE || yMax - yMin > MAX_CUB_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            coords1[6] = coords[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            coords1[7] = coords[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            coords1[4] = (coords[4] + coords[6])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            coords1[5] = (coords[5] + coords[7])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            tx = (coords[2] + coords[4])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            ty = (coords[3] + coords[5])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            coords1[2] = (tx + coords1[4])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            coords1[3] = (ty + coords1[5])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            coords[2] =  (coords[0] + coords[2])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            coords[3] =  (coords[1] + coords[3])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            coords[4] = (coords[2] + tx)/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            coords[5] = (coords[3] + ty)/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            coords[6]=coords1[0]=(coords[4] + coords1[2])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            coords[7]=coords1[1]=(coords[5] + coords1[3])/2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            ProcessMonotonicCubic(hnd, coords, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            ProcessMonotonicCubic(hnd, coords1, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            DrawMonotonicCubic(hnd, coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                               /* Set checkBounds parameter if curve intersects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                                * boundary of the visible area. We know that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                                * the curve is visible, so the check is pretty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                                * simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                                hnd.dhnd.xMinf > xMin ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                                hnd.dhnd.xMaxf < xMax ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                                hnd.dhnd.yMinf > yMin ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                                hnd.dhnd.yMaxf < yMax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                                pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * Split cubic curve into monotonic in X and Y parts. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * ProcessMonotonicCubic for each monotonic piece of the curve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * Note: coords array could be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    private static void ProcessCubic(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                                     float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                                     int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        /* Temporary array for holding parameters corresponding to the extreme
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
         * in X and Y points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        double params[] = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        double eqn[] = new double[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        double res[] = new double[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        int cnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        /* Simple check for monotonicity in X before searching for the extreme
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
         * points of the X(t) function. We first check if the curve is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
         * monotonic in X by seeing if all of the X coordinates are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
         * ordered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        if ((coords[0] > coords[2] || coords[2] > coords[4] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
             coords[4] > coords[6]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            (coords[0] < coords[2] || coords[2] < coords[4] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
             coords[4] < coords[6]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            /* Searching for extreme points of the X(t) function  by solving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
             * dX(t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
             * ----  = 0 equation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
             *  dt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            eqn[2] = -coords[0] + 3*coords[2] - 3*coords[4] + coords[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            eqn[1] = 2*(coords[0] - 2*coords[2] + coords[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            eqn[0] = -coords[0] + coords[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            int nr = QuadCurve2D.solveQuadratic(eqn, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            /* Following code also correctly works in degenerate case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
             * the quadratic equation (nr = -1) because we do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
             * splitting in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            for (int i = 0; i < nr; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                if (res[i] > 0 && res[i] < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    params[cnt++] = res[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        /* Simple check for monotonicity in Y before searching for the extreme
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
         * points of the Y(t) function. We first check if the curve is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
         * monotonic in Y by seeing if all of the Y coordinates are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
         * ordered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        if ((coords[1] > coords[3] || coords[3] > coords[5] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
             coords[5] > coords[7]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            (coords[1] < coords[3] || coords[3] < coords[5] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
             coords[5] < coords[7]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            /* Searching for extreme points of the Y(t) function by solving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
             * dY(t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
             * ----- = 0 equation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
             *  dt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            eqn[2] = -coords[1] + 3*coords[3] - 3*coords[5] + coords[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            eqn[1] = 2*(coords[1] - 2*coords[3] + coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            eqn[0] = -coords[1] + coords[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            int nr = QuadCurve2D.solveQuadratic(eqn, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            /* Following code also correctly works in degenerate case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
             * the quadratic equation (nr = -1) because we do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
             * splitting in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            for (int i = 0; i < nr; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                if (res[i] > 0 && res[i] < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    params[cnt++] = res[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        if (cnt > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            /* Sorting parameter values corresponding to the extreme points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
             * of the curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            Arrays.sort(params, 0, cnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            /* Processing obtained monotonic parts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            ProcessFirstMonotonicPartOfCubic(hnd, coords, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                                             (float)params[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            for (int i = 1; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                double param = params[i] - params[i-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                if (param > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    ProcessFirstMonotonicPartOfCubic(hnd, coords, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                        /* Scale parameter to match with rest of the curve */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                        (float)(param/(1.0 - params[i - 1])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        ProcessMonotonicCubic(hnd,coords,pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * Bite the piece of the cubic curve from start point till the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * corresponding to the specified parameter then call ProcessCubic for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * bitten part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * Note: coords array will be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    private static void ProcessFirstMonotonicPartOfCubic(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                                                         float[] coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                                                         int[] pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                                                         float t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        float[] coords1 = new float[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        float tx, ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        coords1[0] = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        coords1[1] = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        tx = coords[2] + t*(coords[4] - coords[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        ty = coords[3] + t*(coords[5] - coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        coords1[2] =  coords[0] + t*(coords[2] - coords[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        coords1[3] =  coords[1] + t*(coords[3] - coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        coords1[4] = coords1[2] + t*(tx - coords1[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        coords1[5] = coords1[3] + t*(ty - coords1[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        coords[4] = coords[4] + t*(coords[6] - coords[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        coords[5] = coords[5] + t*(coords[7] - coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        coords[2] = tx + t*(coords[4] - tx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        coords[3] = ty + t*(coords[5] - ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        coords[0]=coords1[6]=coords1[4] + t*(coords[2] - coords1[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        coords[1]=coords1[7]=coords1[5] + t*(coords[3] - coords1[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        ProcessMonotonicCubic(hnd, coords1, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    /* Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * For more easy reading of the code below each java version of the macros
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * from the ProcessPath.c preceded by the commented origin call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * containing verbose names of the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    private static void ProcessLine(ProcessHandler hnd, float x1, float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                                    float x2, float y2, int[] pixelInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        float xMin, yMin, xMax, yMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        int X1, Y1, X2, Y2, X3, Y3, res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        boolean clipped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        float x3,y3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        float c[] = new float[]{x1, y1, x2, y2, 0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        boolean lastClipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        xMin = hnd.dhnd.xMinf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        yMin = hnd.dhnd.yMinf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        xMax = hnd.dhnd.xMaxf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        yMax = hnd.dhnd.yMaxf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        // TESTANDCLIP(yMin, yMax, y1, x1, y2, x2, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        res = TESTANDCLIP(yMin, yMax, c, 1, 0, 3, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        if (res == CRES_INVISIBLE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        clipped = IS_CLIPPED(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        // TESTANDCLIP(yMin, yMax, y2, x2, y1, x1, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        res = TESTANDCLIP(yMin, yMax, c, 3, 2, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        if (res == CRES_INVISIBLE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        lastClipped = IS_CLIPPED(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        clipped = clipped || lastClipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        if (hnd.clipMode == PH_MODE_DRAW_CLIP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            // TESTANDCLIP(xMin, xMax, x1, y1, x2, y2, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            res = TESTANDCLIP(xMin, xMax, c, 0, 1, 2, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            if (res == CRES_INVISIBLE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            clipped = clipped || IS_CLIPPED(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            // TESTANDCLIP(xMin, xMax, x2, y2, x1, y1, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            res = TESTANDCLIP(xMin, xMax, c, 2, 3, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            if (res == CRES_INVISIBLE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            lastClipped = lastClipped || IS_CLIPPED(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            clipped = clipped || lastClipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            X1 = (int)(c[0]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
            Y1 = (int)(c[1]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            X2 = (int)(c[2]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            Y2 = (int)(c[3]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            hnd.processFixedLine(X1, Y1, X2, Y2, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                                 clipped, /* enable boundary checking in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                                             case of clipping to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                                             entering out of bounds which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                                             could happens during rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                                           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                                 lastClipped /* Notify pProcessFixedLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                                                that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                                                this is the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                                                subpath (because of exiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                                                out of boundaries)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                                 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        } else {
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  1421
            /* Clamping starting from first vertex of the processed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
             * segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
             * CLIPCLAMP(xMin, xMax, x1, y1, x2, y2, x3, y3, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            res = CLIPCLAMP(xMin, xMax, c, 0, 1, 2, 3, 4, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            X1 = (int)(c[0]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            Y1 = (int)(c[1]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            /* Clamping only by left boundary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            if (res == CRES_MIN_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                X3 = (int)(c[4]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                Y3 = (int)(c[5]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                hnd.processFixedLine(X3, Y3, X1, Y1, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                                     false, lastClipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            } else if (res == CRES_INVISIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  1441
            /* Clamping starting from last vertex of the processed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
             * segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
             * CLIPCLAMP(xMin, xMax, x2, y2, x1, y1, x3, y3, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            res = CLIPCLAMP(xMin, xMax, c, 2, 3, 0, 1, 4, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            /* Checking if there was a clip by right boundary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            lastClipped = lastClipped || (res == CRES_MAX_CLIPPED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            X2 = (int)(c[2]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            Y2 = (int)(c[3]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            hnd.processFixedLine(X1, Y1, X2, Y2, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                                 false, lastClipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            /* Clamping only by left boundary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            if (res == CRES_MIN_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                X3 = (int)(c[4]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                Y3 = (int)(c[5]*MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                hnd.processFixedLine(X2, Y2, X3, Y3, pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                                     false, lastClipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    private static boolean doProcessPath(ProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                                         Path2D.Float p2df,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                                         float transXf, float transYf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        float coords[] = new float[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        float tCoords[] = new float[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        float closeCoord[] = new float[] {0.0f, 0.0f};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        float firstCoord[] = new float[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        int pixelInfo[] = new int[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        boolean subpathStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        boolean skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        float lastX, lastY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        pixelInfo[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        /* Adjusting boundaries to the capabilities of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
         * ProcessPath code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        hnd.dhnd.adjustBounds(LOWER_OUT_BND, LOWER_OUT_BND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                              UPPER_OUT_BND, UPPER_OUT_BND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        /* Adding support of the KEY_STROKE_CONTROL rendering hint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
         * Now we are supporting two modes: "pixels at centers" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
         * "pixels at corners".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
         * First one is disabled by default but could be enabled by setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
         * VALUE_STROKE_PURE to the rendering hint. It means that pixel at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
         * screen (x,y) has (x + 0.5, y + 0.5) float coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
         * Second one is enabled by default and means straightforward mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
         * (x,y) --> (x,y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        if (hnd.dhnd.strokeControl == SunHints.INTVAL_STROKE_PURE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            closeCoord[0] = -0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            closeCoord[1] = -0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            transXf -= 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            transYf -= 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        PathIterator pi = p2df.getPathIterator(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            switch (pi.currentSegment(coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                    /* Performing closing of the unclosed segments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                    if (subpathStarted && !skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                        if (hnd.clipMode == PH_MODE_FILL_CLIP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                            if (tCoords[0] != closeCoord[0] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                                tCoords[1] != closeCoord[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                                ProcessLine(hnd, tCoords[0], tCoords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                                            closeCoord[0], closeCoord[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                                            pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                        hnd.processEndSubPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    tCoords[0] = coords[0] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                    tCoords[1] = coords[1] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    /* Checking SEG_MOVETO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                     * [LOWER_BND, UPPER_BND] range.  This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                     * NaN and Infinity values. Skipping next path segment in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                     * case of invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                    if (tCoords[0] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                        tCoords[0] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                        tCoords[1] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                        tCoords[1] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                        subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                        skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                        closeCoord[0] = tCoords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                        closeCoord[1] = tCoords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                        skip = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                    pixelInfo[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                    lastX = tCoords[2] = coords[0] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                    lastY = tCoords[3] = coords[1] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                    /* Checking SEG_LINETO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                     * [LOWER_BND, UPPER_BND] range.  This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                     * NaN and Infinity values. Ignoring current path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                     * in case  of invalid data. If segment is skipped its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                     * endpoint (if valid) is used to begin new subpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                    if (lastX < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                        lastX > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                        lastY < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                        lastY > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                        if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                            tCoords[0] = closeCoord[0] = lastX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                            tCoords[1] = closeCoord[1] = lastY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                            subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                            skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                            ProcessLine(hnd, tCoords[0], tCoords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                                        tCoords[2], tCoords[3], pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                            tCoords[0] = lastX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                            tCoords[1] = lastY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                    tCoords[2] = coords[0] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                    tCoords[3] = coords[1] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    lastX = tCoords[4] = coords[2] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    lastY = tCoords[5] = coords[3] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                    /* Checking SEG_QUADTO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                     * [LOWER_BND, UPPER_BND] range.  This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                     * NaN and Infinity values. Ignoring current path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                     * in case  of invalid endpoints's data.  Equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                     * the SEG_LINETO if endpoint coordinates are valid but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                     * there are invalid data among other coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    if (lastX < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                        lastX > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                        lastY < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                        lastY > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                        if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                            tCoords[0] = closeCoord[0] = lastX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                            tCoords[1] = closeCoord[1] = lastY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                            subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                            skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                            if (tCoords[2] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                                tCoords[2] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                                tCoords[3] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                                tCoords[3] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                                ProcessQuad(hnd, tCoords, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                                ProcessLine(hnd, tCoords[0], tCoords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                                            tCoords[4], tCoords[5],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                                            pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                            tCoords[0] = lastX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                            tCoords[1] = lastY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                    tCoords[2] = coords[0] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                    tCoords[3] = coords[1] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                    tCoords[4] = coords[2] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                    tCoords[5] = coords[3] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                    lastX = tCoords[6] = coords[4] + transXf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                    lastY = tCoords[7] = coords[5] + transYf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                    /* Checking SEG_CUBICTO coordinates if they are out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                     * [LOWER_BND, UPPER_BND] range.  This check also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                     * NaN and Infinity values. Ignoring current path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                     * in case  of invalid endpoints's data.  Equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                     * the SEG_LINETO if endpoint coordinates are valid but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                     * there are invalid data among other coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                    if (lastX < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                        lastX > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                        lastY < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                        lastY > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                        if (skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                            tCoords[0] = closeCoord[0] = tCoords[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                            tCoords[1] = closeCoord[1] = tCoords[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                            subpathStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                            skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                            if (tCoords[2] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                                tCoords[2] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                                tCoords[3] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                                tCoords[3] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                                tCoords[4] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                                tCoords[4] > LOWER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                                tCoords[5] < UPPER_BND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                                tCoords[5] > LOWER_BND)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                                ProcessCubic(hnd, tCoords, pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                                ProcessLine(hnd, tCoords[0], tCoords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                                            tCoords[6], tCoords[7],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                                            pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                            tCoords[0] = lastX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                            tCoords[1] = lastY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                    if (subpathStarted && !skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                        skip = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                        if (tCoords[0] != closeCoord[0] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                            tCoords[1] != closeCoord[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                            ProcessLine(hnd, tCoords[0], tCoords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                                        closeCoord[0], closeCoord[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                                        pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                            /* Storing last path's point for using in following
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                             * segments without initial moveTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                            tCoords[0] = closeCoord[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                            tCoords[1] = closeCoord[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                        hnd.processEndSubPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        /* Performing closing of the unclosed segments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        if (subpathStarted & !skip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            if (hnd.clipMode == PH_MODE_FILL_CLIP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                if (tCoords[0] != closeCoord[0] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                    tCoords[1] != closeCoord[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                    ProcessLine(hnd, tCoords[0], tCoords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                                closeCoord[0], closeCoord[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                                pixelInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            hnd.processEndSubPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    private static class Point {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        public int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        public int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        public boolean lastPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        public Point prev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        public Point next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        public Point nextByY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        public Edge edge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        public Point(int x, int y, boolean lastPoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            this.lastPoint = lastPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    private static class Edge {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        int dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        Point p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        int  dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        Edge prev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        Edge next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        public Edge(Point p, int x, int dx, int dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            this.p = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            this.dx = dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            this.dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    /* Size of the default buffer in the FillData structure. This buffer is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * replaced with heap allocated in case of large paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    private static final int DF_MAX_POINT = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    /* Following class accumulates points of the non-continuous flattened
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * general path during iteration through the origin path's segments . The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * end of the each subpath is marked as lastPoint flag set at the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
    private static class FillData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        List<Point>  plgPnts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        public int  plgYMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        public int  plgYMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        public FillData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            plgPnts = new Vector<Point>(DF_MAX_POINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        public void addPoint(int x, int y, boolean lastPoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            if (plgPnts.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                plgYMin = plgYMax = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                plgYMin = (plgYMin > y)?y:plgYMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                plgYMax = (plgYMax < y)?y:plgYMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            plgPnts.add(new Point(x, y, lastPoint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            return plgPnts.size() == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        public boolean isEnded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            return plgPnts.get(plgPnts.size() - 1).lastPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        public boolean setEnded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            return plgPnts.get(plgPnts.size() - 1).lastPoint = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    private static class ActiveEdgeList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        Edge head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            return (head == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        public void insert(Point pnt, int cy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            Point np = pnt.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            int X1 = pnt.x, Y1 = pnt.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            int X2 = np.x, Y2 = np.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            Edge ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            if (Y1 == Y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                /* Skipping horizontal segments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                int dX = X2 - X1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                int dY = Y2 - Y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                int stepx, x0, dy, dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                if (Y1 < Y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                    x0 = X1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                    dy = cy - Y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                    dir = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                } else { // (Y1 > Y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                    x0 = X2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                    dy = cy - Y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                    dir = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                /* We need to worry only about dX because dY is in denominator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                 * and abs(dy) < MDP_MULT (cy is a first scanline of the scan
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                 * converted segment and we subtract y coordinate of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                 * nearest segment's end from it to obtain dy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                if (dX > CALC_UBND || dX < CALC_LBND)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                    stepx = (int)((((double)dX)*MDP_MULT)/dY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                    x0 = x0 + (int)((((double)dX)*dy)/dY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                    stepx = (dX<<MDP_PREC)/dY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                    x0 += (dX*dy)/dY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                ne = new Edge(pnt, x0, stepx, dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
            ne.next = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
            ne.prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            if (head != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                head.prev = ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
            head = pnt.edge = ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        public void delete(Edge e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            Edge prevp = e.prev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            Edge nextp = e.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            if (prevp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                prevp.next = nextp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                head = nextp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            if (nextp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                nextp.prev = prevp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
         * Bubble sorting in the ascending order of the linked list.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
         * implementation stops processing the list if there were no changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
         * during the previous pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
         * We could not use O(N) Radix sort here because in most cases list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
         * edges almost sorted.  So, bubble sort (O(N^2)) is working much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
         * better.  Note, in case of array of edges Shell sort is more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
         * efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        public void sort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            Edge p, q, r, s = null, temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            boolean wasSwap = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
            // r precedes p and s points to the node up to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            // comparisons are to be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            while (s != head.next && wasSwap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                r = p = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                q = p.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                wasSwap = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                while (p != s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                    if (p.x >= q.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                        wasSwap = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                        if (p == head) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                            temp = q.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                            q.next = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                            p.next = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                            head = q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                            r = q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                            temp = q.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                            q.next = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                            p.next = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                            r.next = q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                            r = q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                        r = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                        p = p.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                    q = p.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    if (q == s) s = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            // correction of the back links in the double linked edge list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            p = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            q = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            while (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                p.prev = q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                q = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                p = p.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
    private static void FillPolygon(FillProcessHandler hnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                                    int fillRule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        int k, y, n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        boolean drawing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        Edge active;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        int rightBnd = hnd.dhnd.xMax - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        FillData fd = hnd.fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        int yMin = fd.plgYMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        int yMax = fd.plgYMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        int hashSize = ((yMax - yMin)>>MDP_PREC) + 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        /* Because of support of the KEY_STROKE_CONTROL hint we are performing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
         * shift of the coordinates at the higher level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        int hashOffset = ((yMin - 1) & MDP_W_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        /* Winding counter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        int counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
        /* Calculating mask to be applied to the winding counter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        int counterMask =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            (fillRule == PathIterator.WIND_NON_ZERO)? -1:1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        int pntOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        List<Point> pnts = fd.plgPnts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        n = pnts.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        if (n <=1) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
        Point[] yHash = new Point[hashSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        /* Creating double linked list (prev, next links) describing path order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
         * and hash table with points which fall between scanlines. nextByY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
         * link is used for the points which are between same scanlines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
         * Scanlines are passed through the centers of the pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        Point curpt = pnts.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        curpt.prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        for (int i = 0; i < n - 1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            curpt = pnts.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            Point nextpt = pnts.get(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            int curHashInd = (curpt.y - hashOffset - 1) >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            curpt.nextByY = yHash[curHashInd];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            yHash[curHashInd] = curpt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            curpt.next = nextpt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            nextpt.prev = curpt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        Point ept = pnts.get(n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        int curHashInd = (ept.y - hashOffset - 1) >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        ept.nextByY = yHash[curHashInd];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        yHash[curHashInd] = ept;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
        ActiveEdgeList activeList = new ActiveEdgeList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
        for (y=hashOffset + MDP_MULT,k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
             y<=yMax && k < hashSize; y += MDP_MULT, k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            for(Point pt = yHash[k];pt != null; pt=pt.nextByY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                /* pt.y should be inside hashed interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                 * assert(y-MDP_MULT <= pt.y && pt.y < y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                if (pt.prev != null && !pt.prev.lastPoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
                    if (pt.prev.edge != null && pt.prev.y <= y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                        activeList.delete(pt.prev.edge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                        pt.prev.edge = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                    } else  if (pt.prev.y > y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                        activeList.insert(pt.prev, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                if (!pt.lastPoint && pt.next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                    if (pt.edge != null && pt.next.y <= y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                        activeList.delete(pt.edge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                        pt.edge = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                    } else if (pt.next.y > y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                        activeList.insert(pt, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            if (activeList.isEmpty()) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            activeList.sort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            counter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            drawing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            int xl, xr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            xl = xr = hnd.dhnd.xMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            Edge curEdge = activeList.head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            while (curEdge != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                counter += curEdge.dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                if ((counter & counterMask) != 0 && !drawing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                    xl = (curEdge.x + MDP_MULT - 1)>>MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                    drawing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                if ((counter & counterMask) == 0 && drawing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                    xr = (curEdge.x - 1) >> MDP_PREC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                    if (xl <= xr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                        hnd.dhnd.drawScanline(xl, xr, y >> MDP_PREC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                    drawing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                curEdge.x += curEdge.dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                curEdge = curEdge.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            /* Performing drawing till the right boundary (for correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
             * rendering shapes clipped at the right side)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            if (drawing && xl <= rightBnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                /* Support of the strokeHint was added into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                 * draw and fill methods of the sun.java2d.pipe.LoopPipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                hnd.dhnd.drawScanline(xl, rightBnd, y  >> MDP_PREC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
    private static class FillProcessHandler extends ProcessHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        FillData fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        /* Note: For more easy reading of the code below each java version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
         * the macros from the ProcessPath.c preceded by the commented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
         * origin call containing verbose names of the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        public void  processFixedLine(int x1, int y1, int x2, int y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                                      int[] pixelInfo, boolean checkBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                                      boolean endSubPath)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            int outXMin, outXMax, outYMin, outYMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            int res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            /* There is no need to round line coordinates to the forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
             * differencing precision anymore. Such a rounding was used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
             * preventing the curve go out the endpoint (this sometimes does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
             * not help). The problem was fixed in the forward differencing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
             * loops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
            if (checkBounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                boolean lastClipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                /* This function is used only for filling shapes, so there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                 * check for the type of clipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                int c[] = new int[]{x1, y1, x2, y2, 0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                outXMin = (int)(dhnd.xMinf * MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                outXMax = (int)(dhnd.xMaxf * MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                outYMin = (int)(dhnd.yMinf * MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                outYMax = (int)(dhnd.yMaxf * MDP_MULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                 * TESTANDCLIP(outYMin, outYMax, y1, x1, y2, x2, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                res = TESTANDCLIP(outYMin, outYMax, c, 1, 0, 3, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                if (res == CRES_INVISIBLE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                 * TESTANDCLIP(outYMin, outYMax, y2, x2, y1, x1, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                res = TESTANDCLIP(outYMin, outYMax, c, 3, 2, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                if (res == CRES_INVISIBLE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                lastClipped = IS_CLIPPED(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  2065
                /* Clamping starting from first vertex of the processed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                 * segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                 * CLIPCLAMP(outXMin, outXMax, x1, y1, x2, y2, x3, y3, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                res = CLIPCLAMP(outXMin, outXMax, c, 0, 1, 2, 3, 4, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                /* Clamping only by left boundary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                if (res == CRES_MIN_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                    processFixedLine(c[4], c[5], c[0], c[1], pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                                     false, lastClipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                } else if (res == CRES_INVISIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  2081
                /* Clamping starting from last vertex of the processed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                 * segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                 * CLIPCLAMP(outXMin, outXMax, x2, y2, x1, y1, x3, y3, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                res = CLIPCLAMP(outXMin, outXMax, c, 2, 3, 0, 1, 4, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                /* Checking if there was a clip by right boundary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                lastClipped = lastClipped || (res == CRES_MAX_CLIPPED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                processFixedLine(c[0], c[1], c[2], c[3], pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                                 false, lastClipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                /* Clamping only by left boundary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                if (res == CRES_MIN_CLIPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                    processFixedLine(c[2], c[3], c[4], c[5], pixelInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                                     false, lastClipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
            /* Adding first point of the line only in case of empty or just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
             * finished path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            if (fd.isEmpty() || fd.isEnded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                fd.addPoint(x1, y1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
            fd.addPoint(x2, y2, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            if (endSubPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                fd.setEnded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        FillProcessHandler(DrawHandler dhnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            super(dhnd, PH_MODE_FILL_CLIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            this.fd = new FillData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        public void processEndSubPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            if (!fd.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                fd.setEnded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
}