Package sun.dc.pr

Examples of sun.dc.pr.Rasterizer


                                              BasicStroke bs,
                                              boolean thin,
                                              boolean normalize,
                                              int bbox[])
    {
        Rasterizer r = getRasterizer();
        PathIterator pi = s.getPathIterator(at);

        if (bs != null) {
            float matrix[] = null;
            r.setUsage(Rasterizer.STROKE);
            if (thin) {
                r.setPenDiameter(MinPenSizeAA);
            } else {
                r.setPenDiameter(bs.getLineWidth());
                if (at != null) {
                    matrix = getTransformMatrix(at);
                    r.setPenT4(matrix);
                }
                r.setPenFitting(PenUnits, MinPenUnitsAA);
            }
            r.setCaps(RasterizerCaps[bs.getEndCap()]);
            r.setCorners(RasterizerCorners[bs.getLineJoin()],
                         bs.getMiterLimit());
            float[] dashes = bs.getDashArray();
            if (dashes != null) {
                r.setDash(dashes, bs.getDashPhase());
                if (at != null && matrix == null) {
                    matrix = getTransformMatrix(at);
                }
                r.setDashT4(matrix);
            }
        } else {
            r.setUsage(pi.getWindingRule() == PathIterator.WIND_EVEN_ODD
                       ? Rasterizer.EOFILL
                       : Rasterizer.NZFILL);
        }

        r.beginPath();
        {
            boolean pathClosed = false;
            boolean skip = false;
            boolean subpathStarted = false;
            float mx = 0.0f;
            float my = 0.0f;
            float point[]  = new float[6];
            float ax = 0.0f;
            float ay = 0.0f;

            while (!pi.isDone()) {
                int type = pi.currentSegment(point);
                if (pathClosed == true) {
                    pathClosed = false;
                    if (type != PathIterator.SEG_MOVETO) {
                        // Force current point back to last moveto point
                        r.beginSubpath(mx, my);
                        subpathStarted = true;
                    }
                }
                if (normalize) {
                    int index;
                    switch (type) {
                    case PathIterator.SEG_CUBICTO:
                        index = 4;
                        break;
                    case PathIterator.SEG_QUADTO:
                        index = 2;
                        break;
                    case PathIterator.SEG_MOVETO:
                    case PathIterator.SEG_LINETO:
                        index = 0;
                        break;
                    case PathIterator.SEG_CLOSE:
                    default:
                        index = -1;
                        break;
                    }
                    if (index >= 0) {
                        float ox = point[index];
                        float oy = point[index+1];
                        float newax = (float) Math.floor(ox) + 0.5f;
                        float neway = (float) Math.floor(oy) + 0.5f;
                        point[index] = newax;
                        point[index+1] = neway;
                        newax -= ox;
                        neway -= oy;
                        switch (type) {
                        case PathIterator.SEG_CUBICTO:
                            point[0] += ax;
                            point[1] += ay;
                            point[2] += newax;
                            point[3] += neway;
                            break;
                        case PathIterator.SEG_QUADTO:
                            point[0] += (newax + ax) / 2;
                            point[1] += (neway + ay) / 2;
                            break;
                        case PathIterator.SEG_MOVETO:
                        case PathIterator.SEG_LINETO:
                        case PathIterator.SEG_CLOSE:
                            break;
                        }
                        ax = newax;
                        ay = neway;
                    }
                }
                switch (type) {
                case PathIterator.SEG_MOVETO:

                   /* Checking SEG_MOVETO coordinates if they are out of the
                    * [LOWER_BND, UPPER_BND] range. This check also handles NaN
                    * and Infinity values. Skipping next path segment in case
                    * of invalid data.
                    */

                    if (point[0] < UPPER_BND &&  point[0] > LOWER_BND &&
                        point[1] < UPPER_BND &&  point[1] > LOWER_BND)
                    {
                        mx = point[0];
                        my = point[1];
                        r.beginSubpath(mx, my);
                        subpathStarted = true;
                        skip = false;
                    } else {
                        skip = true;
                    }
                    break;

                case PathIterator.SEG_LINETO:
                    /* Checking SEG_LINETO coordinates if they are out of the
                     * [LOWER_BND, UPPER_BND] range. This check also handles
                     * NaN and Infinity values. Ignoring current path segment
                     * in case of invalid data. If segment is skipped its
                     * endpoint (if valid) is used to begin new subpath.
                     */
                    if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
                        point[1] < UPPER_BND && point[1] > LOWER_BND)
                    {
                        if (skip) {
                            r.beginSubpath(point[0], point[1]);
                            subpathStarted = true;
                            skip = false;
                        } else {
                            r.appendLine(point[0], point[1]);
                        }
                    }
                    break;

                case PathIterator.SEG_QUADTO:
                    // Quadratic curves take two points

                    /* Checking SEG_QUADTO coordinates if they are out of the
                     * [LOWER_BND, UPPER_BND] range. This check also handles
                     * NaN and Infinity values. Ignoring current path segment
                     * in case of invalid endpoints's data. Equivalent to the
                     * SEG_LINETO if endpoint coordinates are valid but there
                     * are invalid data amoung other coordinates
                     */
                    if (point[2] < UPPER_BND && point[2] > LOWER_BND &&
                        point[3] < UPPER_BND && point[3] > LOWER_BND)
                    {
                        if (skip) {
                            r.beginSubpath(point[2], point[3]);
                            subpathStarted = true;
                            skip = false;
                        } else {
                            if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
                                point[1] < UPPER_BND && point[1] > LOWER_BND)
                            {
                                r.appendQuadratic(point[0], point[1],
                                                  point[2], point[3]);
                            } else {
                                r.appendLine(point[2], point[3]);
                            }
                        }
                    }
                    break;
                case PathIterator.SEG_CUBICTO:
                    // Cubic curves take three points

                    /* Checking SEG_CUBICTO coordinates if they are out of the
                     * [LOWER_BND, UPPER_BND] range. This check also handles
                     * NaN and Infinity values. Ignoring  current path segment
                     * in case of invalid endpoints's data. Equivalent to the
                     * SEG_LINETO if endpoint coordinates are valid but there
                     * are invalid data amoung other coordinates
                     */

                    if (point[4] < UPPER_BND && point[4] > LOWER_BND &&
                        point[5] < UPPER_BND && point[5] > LOWER_BND)
                    {
                        if (skip) {
                            r.beginSubpath(point[4], point[5]);
                            subpathStarted = true;
                            skip = false;
                        } else {
                            if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
                                point[1] < UPPER_BND && point[1] > LOWER_BND &&
                                point[2] < UPPER_BND && point[2] > LOWER_BND &&
                                point[3] < UPPER_BND && point[3] > LOWER_BND)
                            {
                                r.appendCubic(point[0], point[1],
                                              point[2], point[3],
                                              point[4], point[5]);
                            } else {
                                r.appendLine(point[4], point[5]);
                            }
                        }
                    }
                    break;
                case PathIterator.SEG_CLOSE:
                    if (subpathStarted) {
                        r.closedSubpath();
                        subpathStarted = false;
                        pathClosed = true;
                    }
                    break;
                }
                pi.next();
            }
        }

        try {
            r.endPath();
            r.getAlphaBox(bbox);
            clip.clipBoxToBounds(bbox);
            if (bbox[0] >= bbox[2] || bbox[1] >= bbox[3]) {
                dropRasterizer(r);
                return null;
            }
            r.setOutputArea(bbox[0], bbox[1],
                            bbox[2] - bbox[0],
                            bbox[3] - bbox[1]);
        } catch (PRException e) {
            /*
             * This exeption is thrown from the native part of the Ductus
View Full Code Here


    };

    private static Rasterizer theRasterizer;

    public synchronized static Rasterizer getRasterizer() {
        Rasterizer r = theRasterizer;
        if (r == null) {
            r = new Rasterizer();
        } else {
            theRasterizer = null;
        }
        return r;
    }
View Full Code Here

                                                   AffineTransform transform,
                                                   BasicStroke stroke,
                                                   boolean thin,
                                                   boolean normalize,
                                                   float norm) {
        Rasterizer r = getRasterizer();

        if (stroke != null) {
            float matrix[] = null;
            r.setUsage(Rasterizer.STROKE);
            if (thin) {
                r.setPenDiameter(MinPenSizeAA);
            } else {
                r.setPenDiameter(stroke.getLineWidth());
                if (transform != null) {
                    matrix = new float[4];
                    double dmatrix[] = new double[6];
                    transform.getMatrix(dmatrix);
                    for (int i = 0; i < 4; i++) {
                        matrix[i] = (float) dmatrix[i];
                    }
                    r.setPenT4(matrix);
                }
                r.setPenFitting(PenUnits, MinPenUnitsAA);
            }
            r.setCaps(RasterizerCaps[stroke.getEndCap()]);
            r.setCorners(RasterizerCorners[stroke.getLineJoin()],
                         stroke.getMiterLimit());
            float[] dashes = stroke.getDashArray();
            if (dashes != null) {
                r.setDash(dashes, stroke.getDashPhase());
                r.setDashT4(matrix);
            }
        } else {
            r.setUsage(pi.getWindingRule() == PathIterator.WIND_EVEN_ODD
                       ? Rasterizer.EOFILL
                       : Rasterizer.NZFILL);
        }

        r.beginPath();
        {
            boolean pathClosed = false;
            boolean subpathBegin = false;
            boolean subpathOpened = false;
            float mx = 0.0f;
            float my = 0.0f;
            float point[]  = new float[6];
            float rnd = (0.5f - norm);
            float ax = 0.0f;
            float ay = 0.0f;

            while (!pi.isDone()) {
                int type = pi.currentSegment(point);
                if (pathClosed == true) {
                    pathClosed = false;
                    if (type != PathIterator.SEG_MOVETO) {
                        // Force current point back to last moveto point
                        r.beginSubpath(mx, my);
                        subpathOpened = true;
                    }
                }
                if (normalize) {
                    int index;
                    switch (type) {
                    case PathIterator.SEG_CUBICTO:
                        index = 4;
                        break;
                    case PathIterator.SEG_QUADTO:
                        index = 2;
                        break;
                    case PathIterator.SEG_MOVETO:
                    case PathIterator.SEG_LINETO:
                        index = 0;
                        break;
                    case PathIterator.SEG_CLOSE:
                    default:
                        index = -1;
                        break;
                    }
                    if (index >= 0) {
                        float ox = point[index];
                        float oy = point[index+1];
                        float newax = (float) Math.floor(ox + rnd) + norm;
                        float neway = (float) Math.floor(oy + rnd) + norm;
                        point[index] = newax;
                        point[index+1] = neway;
                        newax -= ox;
                        neway -= oy;
                        switch (type) {
                        case PathIterator.SEG_CUBICTO:
                            point[0] += ax;
                            point[1] += ay;
                            point[2] += newax;
                            point[3] += neway;
                            break;
                        case PathIterator.SEG_QUADTO:
                            point[0] += (newax + ax) / 2;
                            point[1] += (neway + ay) / 2;
                            break;
                        case PathIterator.SEG_MOVETO:
                        case PathIterator.SEG_LINETO:
                        case PathIterator.SEG_CLOSE:
                            break;
                        }
                        ax = newax;
                        ay = neway;
                    }
                }
                switch (type) {
                default:
                    break;
                case PathIterator.SEG_MOVETO:
                    if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
                        point[1] < UPPER_BND && point[1] > LOWER_BND) {
                        mx = point[0];
                        my = point[1];
                        r.beginSubpath(mx, my);
                        subpathOpened = true;
                        subpathBegin = false;
                    } else {
                        subpathBegin = true;
                    }
                    break;
                case PathIterator.SEG_LINETO:
                    if (point[0] >= UPPER_BND || point[0] <= LOWER_BND ||
                        point[1] >= UPPER_BND || point[1] <= LOWER_BND) {
                        break;
                    }
                    if (subpathBegin) {
                        r.beginSubpath(point[0], point[1]);
                        subpathOpened = true;
                        subpathBegin = false;
                    } else {
                        r.appendLine(point[0], point[1]);
                    }
                    break;
                case PathIterator.SEG_QUADTO:
                    // Quadratic curves take two points
                    if (point[2] >= UPPER_BND || point[2] <= LOWER_BND ||
                        point[3] >= UPPER_BND || point[3] <= LOWER_BND) {
                        break;
                    }
                    if (subpathBegin) {
                        r.beginSubpath(point[2], point[3]);
                        subpathOpened = true;
                        subpathBegin = false;
                        break;
                    }
                    if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
                        point[1] < UPPER_BND && point[1] > LOWER_BND) {
                        r.appendQuadratic(point[0], point[1],
                                          point[2], point[3]);
                    } else {
                        r.appendLine(point[2], point[3]);
                    }
                    break;
                case PathIterator.SEG_CUBICTO:
                    // Cubic curves take three points
                    if (point[4] >= UPPER_BND || point[4] <= LOWER_BND ||
                        point[5] >= UPPER_BND || point[5] <= LOWER_BND) {
                        break;
                    }
                    if (subpathBegin) {
                        r.beginSubpath(point[4], point[5]);
                        subpathOpened = true;
                        subpathBegin = false;
                        break;
                    }
                    if (point[0] < UPPER_BND && point[0] > LOWER_BND &&
                        point[1] < UPPER_BND && point[1] > LOWER_BND &&
                        point[2] < UPPER_BND && point[2] > LOWER_BND &&
                        point[3] < UPPER_BND && point[3] > LOWER_BND) {
                        r.appendCubic(point[0], point[1],
                                      point[2], point[3],
                                      point[4], point[5]);
                    } else {
                        r.appendLine(point[4], point[5]);
                    }
                    break;
                case PathIterator.SEG_CLOSE:
                    if (subpathOpened) {
                        r.closedSubpath();
                        subpathOpened = false;
                        pathClosed = true;
                    }
                    break;
                }
                pi.next();
            }
        }

        try {
            r.endPath();
        } catch (PRException e) {
            e.printStackTrace();
        }

        return r;
View Full Code Here

TOP

Related Classes of sun.dc.pr.Rasterizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.