0N/A/*
2362N/A * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.pipe;
0N/A
0N/Aimport java.awt.geom.PathIterator;
0N/Aimport java.awt.Rectangle;
0N/Aimport sun.awt.geom.PathConsumer2D;
0N/A
0N/A/**
0N/A * This class can iterate individual span elements generated by scan
0N/A * converting a Shape.
0N/A * This particular implementation flattens the incoming path and then
0N/A * performs simple polygon tracing to calculate the spans.
0N/A *
0N/A * Note that this class holds pointers to native data which must be
0N/A * disposed. It is not marked as finalizable since it is intended
0N/A * to be very lightweight and finalization is a comparitively expensive
0N/A * procedure. The caller must specifically use try{} finally{} to
0N/A * manually ensure that the object is disposed after use, otherwise
0N/A * native data structures might be leaked.
0N/A *
0N/A * Here is a code sample for using this class:
0N/A *
0N/A * public void fillShape(Shape s, Rectangle clipRect) {
0N/A * ShapeSpanIterator ssi = new ShapeSpanIterator(false);
0N/A * try {
0N/A * ssi.setOutputArea(clipRect);
0N/A * ssi.appendPath(s.getPathIterator(null));
0N/A * int spanbox[] = new int[4];
0N/A * while (ssi.nextSpan(spanbox)) {
0N/A * int x = spanbox[0];
0N/A * int y = spanbox[1];
0N/A * int w = spanbox[2] - x;
0N/A * int h = spanbox[3] - y;
0N/A * fillRect(x, y, w, h);
0N/A * }
0N/A * } finally {
0N/A * ssi.dispose();
0N/A * }
0N/A * }
0N/A */
0N/Apublic final class ShapeSpanIterator
0N/A implements SpanIterator, PathConsumer2D
0N/A{
0N/A long pData;
0N/A
0N/A static {
0N/A initIDs();
0N/A }
0N/A
0N/A public static native void initIDs();
0N/A
0N/A public ShapeSpanIterator(boolean adjust) {
0N/A setNormalize(adjust);
0N/A }
0N/A
0N/A /*
0N/A * Appends the geometry and winding rule from the indicated
0N/A * path iterator.
0N/A */
0N/A public void appendPath(PathIterator pi) {
0N/A float coords[] = new float[6];
0N/A
0N/A setRule(pi.getWindingRule());
0N/A while (!pi.isDone()) {
0N/A addSegment(pi.currentSegment(coords), coords);
0N/A pi.next();
0N/A }
0N/A pathDone();
0N/A }
0N/A
0N/A /*
0N/A * Appends the geometry from the indicated set of polygon points.
0N/A */
0N/A public native void appendPoly(int xPoints[], int yPoints[], int nPoints,
0N/A int xoff, int yoff);
0N/A
0N/A /*
0N/A * Sets the normalization flag so that incoming data is
0N/A * adjusted to nearest (0.25, 0.25) subpixel position.
0N/A */
0N/A private native void setNormalize(boolean adjust);
0N/A
0N/A /*
0N/A * Sets the rectangle of interest for storing and returning
0N/A * span segments.
0N/A */
0N/A public void setOutputAreaXYWH(int x, int y, int w, int h) {
0N/A setOutputAreaXYXY(x, y, Region.dimAdd(x, w), Region.dimAdd(y, h));
0N/A }
0N/A
0N/A /*
0N/A * Sets the rectangle of interest for storing and returning
0N/A * span segments.
0N/A */
0N/A public native void setOutputAreaXYXY(int lox, int loy, int hix, int hiy);
0N/A
0N/A /*
0N/A * Sets the rectangle of interest for storing and returning
0N/A * span segments to the specified Rectangle.
0N/A */
0N/A public void setOutputArea(Rectangle r) {
0N/A setOutputAreaXYWH(r.x, r.y, r.width, r.height);
0N/A }
0N/A
0N/A /*
0N/A * Sets the rectangle of interest for storing and returning
0N/A * span segments to the bounds of the specified Region.
0N/A */
0N/A public void setOutputArea(Region r) {
0N/A setOutputAreaXYXY(r.lox, r.loy, r.hix, r.hiy);
0N/A }
0N/A
0N/A /*
0N/A * Sets the winding rule in the native data structures.
0N/A */
0N/A public native void setRule(int rule);
0N/A
0N/A /*
0N/A * Adds a single PathIterator segment to the internal list of
0N/A * path element structures.
0N/A */
0N/A public native void addSegment(int type, float coords[]);
0N/A
0N/A /*
0N/A * Gets the bbox of the available path segments, clipped to the
0N/A * OutputArea.
0N/A */
0N/A public native void getPathBox(int pathbox[]);
0N/A
0N/A /*
0N/A * Intersects the path box with the given bbox.
0N/A * Returned spans are clipped to this region, or discarded
0N/A * altogether if they lie outside it.
0N/A */
0N/A public native void intersectClipBox(int lox, int loy, int hix, int hiy);
0N/A
0N/A /*
0N/A * Fetches the next span that needs to be operated on.
0N/A * If the return value is false then there are no more spans.
0N/A */
0N/A public native boolean nextSpan(int spanbox[]);
0N/A
0N/A /**
0N/A * This method tells the iterator that it may skip all spans
0N/A * whose Y range is completely above the indicated Y coordinate.
0N/A */
0N/A public native void skipDownTo(int y);
0N/A
0N/A /**
0N/A * This method returns a native pointer to a function block that
0N/A * can be used by a native method to perform the same iteration
0N/A * cycle that the above methods provide while avoiding upcalls to
0N/A * the Java object.
0N/A * The definition of the structure whose pointer is returned by
0N/A * this method is defined in:
0N/A * <pre>
0N/A * src/share/native/sun/java2d/pipe/SpanIterator.h
0N/A * </pre>
0N/A */
0N/A public native long getNativeIterator();
0N/A
0N/A /*
0N/A * Cleans out all internal data structures.
0N/A */
0N/A public native void dispose();
0N/A
0N/A public native void moveTo(float x, float y);
0N/A public native void lineTo(float x, float y);
0N/A public native void quadTo(float x1, float y1,
0N/A float x2, float y2);
0N/A public native void curveTo(float x1, float y1,
0N/A float x2, float y2,
0N/A float x3, float y3);
0N/A public native void closePath();
0N/A public native void pathDone();
0N/A public native long getNativeConsumer();
0N/A}