Search in sources :

Example 31 with PathIterator

use of java.awt.geom.PathIterator in project jdk8u_jdk by JetBrains.

the class PiscesRenderingEngine method getAATileGenerator.

/**
     * Construct an antialiased tile generator for the given shape with
     * the given rendering attributes and store the bounds of the tile
     * iteration in the bbox parameter.
     * The {@code at} parameter specifies a transform that should affect
     * both the shape and the {@code BasicStroke} attributes.
     * The {@code clip} parameter specifies the current clip in effect
     * in device coordinates and can be used to prune the data for the
     * operation, but the renderer is not required to perform any
     * clipping.
     * If the {@code BasicStroke} parameter is null then the shape
     * should be filled as is, otherwise the attributes of the
     * {@code BasicStroke} should be used to specify a draw operation.
     * The {@code thin} parameter indicates whether or not the
     * transformed {@code BasicStroke} represents coordinates smaller
     * than the minimum resolution of the antialiasing rasterizer as
     * specified by the {@code getMinimumAAPenWidth()} method.
     * <p>
     * Upon returning, this method will fill the {@code bbox} parameter
     * with 4 values indicating the bounds of the iteration of the
     * tile generator.
     * The iteration order of the tiles will be as specified by the
     * pseudo-code:
     * <pre>
     *     for (y = bbox[1]; y < bbox[3]; y += tileheight) {
     *         for (x = bbox[0]; x < bbox[2]; x += tilewidth) {
     *         }
     *     }
     * </pre>
     * If there is no output to be rendered, this method may return
     * null.
     *
     * @param s the shape to be rendered (fill or draw)
     * @param at the transform to be applied to the shape and the
     *           stroke attributes
     * @param clip the current clip in effect in device coordinates
     * @param bs if non-null, a {@code BasicStroke} whose attributes
     *           should be applied to this operation
     * @param thin true if the transformed stroke attributes are smaller
     *             than the minimum dropout pen width
     * @param normalize true if the {@code VALUE_STROKE_NORMALIZE}
     *                  {@code RenderingHint} is in effect
     * @param bbox returns the bounds of the iteration
     * @return the {@code AATileGenerator} instance to be consulted
     *         for tile coverages, or null if there is no output to render
     * @since 1.7
     */
public AATileGenerator getAATileGenerator(Shape s, AffineTransform at, Region clip, BasicStroke bs, boolean thin, boolean normalize, int[] bbox) {
    Renderer r;
    NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF;
    if (bs == null) {
        PathIterator pi;
        if (normalize) {
            pi = new NormalizingPathIterator(s.getPathIterator(at), norm);
        } else {
            pi = s.getPathIterator(at);
        }
        r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), pi.getWindingRule());
        pathTo(pi, r);
    } else {
        r = new Renderer(3, 3, clip.getLoX(), clip.getLoY(), clip.getWidth(), clip.getHeight(), PathIterator.WIND_NON_ZERO);
        strokeTo(s, at, bs, thin, norm, true, r);
    }
    r.endRendering();
    PiscesTileGenerator ptg = new PiscesTileGenerator(r, r.MAX_AA_ALPHA);
    ptg.getBbox(bbox);
    return ptg;
}
Also used : PathIterator(java.awt.geom.PathIterator)

Example 32 with PathIterator

use of java.awt.geom.PathIterator in project WordCram by danbernier.

the class SvgWordRenderer method renderShape.

private void renderShape(Shape shape) {
    Path2D.Double path2d = new Path2D.Double(shape);
    // or WIND_NON_ZERO
    path2d.setWindingRule(Path2D.WIND_EVEN_ODD);
    PathIterator pathIter = path2d.getPathIterator(null);
    float[] coords = new float[6];
    p("<path d=\"");
    while (!pathIter.isDone()) {
        int type = pathIter.currentSegment(coords);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                p("M" + coords[0] + " " + coords[1]);
                break;
            case PathIterator.SEG_LINETO:
                p("L" + coords[0] + " " + coords[1]);
                break;
            case PathIterator.SEG_QUADTO:
                p("Q" + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                p("C" + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3] + " " + coords[4] + " " + coords[5]);
                break;
            case PathIterator.SEG_CLOSE:
                p("Z");
                break;
        }
        pathIter.next();
    }
    pl("\"/>");
}
Also used : PathIterator(java.awt.geom.PathIterator) Path2D(java.awt.geom.Path2D)

Example 33 with PathIterator

use of java.awt.geom.PathIterator in project processing by processing.

the class PFont method getShape.

public PShape getShape(char ch, float detail) {
    Font font = (Font) getNative();
    if (font == null) {
        throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
    }
    PShape s = new PShape(PShape.PATH);
    // six element array received from the Java2D path iterator
    float[] iterPoints = new float[6];
    // array passed to createGylphVector
    char[] textArray = new char[] { ch };
    //Graphics2D graphics = (Graphics2D) this.getGraphics();
    //FontRenderContext frc = graphics.getFontRenderContext();
    @SuppressWarnings("deprecation") FontRenderContext frc = Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
    GlyphVector gv = font.createGlyphVector(frc, textArray);
    Shape shp = gv.getOutline();
    // make everything into moveto and lineto
    PathIterator iter = (detail == 0) ? // maintain curves
    shp.getPathIterator(null) : // convert to line segments
    shp.getPathIterator(null, detail);
    int contours = 0;
    //    boolean contour = false;
    while (!iter.isDone()) {
        int type = iter.currentSegment(iterPoints);
        switch(type) {
            case // 1 point (2 vars) in textPoints
            PathIterator.SEG_MOVETO:
                //        if (!contour) {
                if (contours == 0) {
                    s.beginShape();
                } else {
                    s.beginContour();
                //          contour = true;
                }
                contours++;
                s.vertex(iterPoints[0], iterPoints[1]);
                break;
            case // 1 point
            PathIterator.SEG_LINETO:
                //        System.out.println("lineto");
                //        PApplet.println(PApplet.subset(iterPoints, 0, 2));
                s.vertex(iterPoints[0], iterPoints[1]);
                break;
            case // 2 points
            PathIterator.SEG_QUADTO:
                //        System.out.println("quadto");
                //        PApplet.println(PApplet.subset(iterPoints, 0, 4));
                s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3]);
                break;
            case // 3 points
            PathIterator.SEG_CUBICTO:
                //        System.out.println("cubicto");
                //        PApplet.println(iterPoints);
                s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3], iterPoints[4], iterPoints[5]);
                break;
            case PathIterator.SEG_CLOSE:
                //        System.out.println("close");
                if (contours > 1) {
                    //        contours--;
                    //        if (contours == 0) {
                    ////          s.endShape();
                    //        } else {
                    s.endContour();
                }
                break;
        }
        //      PApplet.println(iterPoints);
        iter.next();
    }
    s.endShape(CLOSE);
    return s;
}
Also used : GlyphVector(java.awt.font.GlyphVector) PathIterator(java.awt.geom.PathIterator) FontRenderContext(java.awt.font.FontRenderContext)

Example 34 with PathIterator

use of java.awt.geom.PathIterator in project android_frameworks_base by ParanoidAndroid.

the class Path_Delegate method transform.

/**
     * Transform the points in this path by matrix, and write the answer
     * into dst. If dst is null, then the the original path is modified.
     *
     * @param matrix The matrix to apply to the path
     * @param dst    The transformed path is written here. If dst is null,
     *               then the the original path is modified
     */
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
    if (matrix.hasPerspective()) {
        assert false;
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
    }
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
    newPath.append(iterator, false);
    if (dst != null) {
        dst.mPath = newPath;
    } else {
        mPath = newPath;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator)

Example 35 with PathIterator

use of java.awt.geom.PathIterator in project openblocks by mikaelhg.

the class InfixBlockShape method appendPath.

/** Append gp2 to gp1.  If reversed == true, then add the segments in reverse order 
     * NOTE: copied and pasted from starlogoblocks/blockengine/BlockShape.java */
private void appendPath(GeneralPath gp1, GeneralPath gp2, boolean reversed) {
    // Each element is an array consisting of one Integer and six Floats
    ArrayList<Number[]> points = new ArrayList<Number[]>();
    PathIterator i = gp2.getPathIterator(new AffineTransform());
    float[] segment = new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
    float leftmost = Float.POSITIVE_INFINITY;
    while (!i.isDone()) {
        int type = i.currentSegment(segment);
        i.next();
        points.add(new Number[] { new Integer(type), new Float(segment[0]), new Float(segment[1]), new Float(segment[2]), new Float(segment[3]), new Float(segment[4]), new Float(segment[5]) });
    }
    if (!reversed) {
        float deltaX = (float) gp1.getCurrentPoint().getX() - ((Float) points.get(0)[1]).floatValue();
        float deltaY = (float) gp1.getCurrentPoint().getY() - ((Float) points.get(0)[2]).floatValue();
        for (int j = 1; j < points.size(); j++) {
            Object[] typeAndPoints = points.get(j);
            int type = ((Integer) typeAndPoints[0]).intValue();
            float x1 = ((Float) typeAndPoints[1]).floatValue();
            float y1 = ((Float) typeAndPoints[2]).floatValue();
            float x2 = ((Float) typeAndPoints[3]).floatValue();
            float y2 = ((Float) typeAndPoints[4]).floatValue();
            float x3 = ((Float) typeAndPoints[5]).floatValue();
            float y3 = ((Float) typeAndPoints[6]).floatValue();
            if (type == PathIterator.SEG_MOVETO) {
            } else if (type == PathIterator.SEG_LINETO) {
                gp1.lineTo(x1 + deltaX, y1 + deltaY);
                leftmost = Math.min(leftmost, x1 + deltaX);
            } else if (type == PathIterator.SEG_QUADTO) {
                gp1.quadTo(x1 + deltaX, y1 + deltaY, x2 + deltaX, y2 + deltaY);
                leftmost = Math.min(leftmost, x2 + deltaX);
            } else if (type == PathIterator.SEG_CUBICTO) {
                gp1.curveTo(x1 + deltaX, y1 + deltaY, x2 + deltaX, y2 + deltaY, x3 + deltaX, y3 + deltaY);
                leftmost = Math.min(leftmost, x3 + deltaX);
            } else {
                assert false : type;
            }
        }
    }
}
Also used : PathIterator(java.awt.geom.PathIterator) ArrayList(java.util.ArrayList) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

PathIterator (java.awt.geom.PathIterator)56 AffineTransform (java.awt.geom.AffineTransform)16 GeneralPath (java.awt.geom.GeneralPath)14 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)10 ArrayList (java.util.ArrayList)9 Point2D (java.awt.geom.Point2D)7 CachedPathIterator (com.android.layoutlib.bridge.util.CachedPathIteratorFactory.CachedPathIterator)5 Point (java.awt.Point)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Path2D (java.awt.geom.Path2D)3 Paint (java.awt.Paint)2 Rectangle (java.awt.Rectangle)2 TDoubleArrayList (gnu.trove.TDoubleArrayList)1 GradientPaint (java.awt.GradientPaint)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Shape (java.awt.Shape)1 TexturePaint (java.awt.TexturePaint)1 FontRenderContext (java.awt.font.FontRenderContext)1 GlyphVector (java.awt.font.GlyphVector)1