Example usage for java.awt.geom PathIterator SEG_CUBICTO

List of usage examples for java.awt.geom PathIterator SEG_CUBICTO

Introduction

In this page you can find the example usage for java.awt.geom PathIterator SEG_CUBICTO.

Prototype

int SEG_CUBICTO

To view the source code for java.awt.geom PathIterator SEG_CUBICTO.

Click Source Link

Document

The segment type constant for the set of 3 points that specify a cubic parametric curve to be drawn from the most recently specified point.

Usage

From source file:org.apache.pdfbox.pdfviewer.font.CFFGlyph2D.java

private GeneralPath transformGlyph(GeneralPath glyph) {
    // we have to invert all y-coordinates due to the moved 0,0-reference
    PathIterator iter = glyph.getPathIterator(null);
    float[] currentSegment = new float[6];
    Path2D.Float path = new Path2D.Float(iter.getWindingRule());
    boolean glyphTransformed = false;
    while (!iter.isDone()) {
        glyphTransformed = true;/*from   w w w . j a v  a  2 s  . com*/
        int type = iter.currentSegment(currentSegment);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            path.moveTo(currentSegment[0], -currentSegment[1]);
            break;
        case PathIterator.SEG_LINETO:
            path.lineTo(currentSegment[0], -currentSegment[1]);
            break;
        case PathIterator.SEG_QUADTO:
            path.quadTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            path.curveTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3],
                    currentSegment[4], -currentSegment[5]);
            break;
        case PathIterator.SEG_CLOSE:
            path.closePath();
            break;
        }
        iter.next();
    }
    if (glyphTransformed) {
        return new GeneralPath(path);
    } else {
        return glyph;
    }
}

From source file:org.apache.pdfbox.rendering.PageDrawer.java

/**
 * Returns true if the given path is rectangular.
 *//*w  ww.j a  v a2 s .com*/
private boolean isRectangular(GeneralPath path) {
    PathIterator iter = path.getPathIterator(null);
    double[] coords = new double[6];
    int count = 0;
    int[] xs = new int[4];
    int[] ys = new int[4];
    while (!iter.isDone()) {
        switch (iter.currentSegment(coords)) {
        case PathIterator.SEG_MOVETO:
            if (count == 0) {
                xs[count] = (int) Math.floor(coords[0]);
                ys[count] = (int) Math.floor(coords[1]);
            } else {
                return false;
            }
            count++;
            break;

        case PathIterator.SEG_LINETO:
            if (count < 4) {
                xs[count] = (int) Math.floor(coords[0]);
                ys[count] = (int) Math.floor(coords[1]);
            } else {
                return false;
            }
            count++;
            break;

        case PathIterator.SEG_CUBICTO:
            return false;

        case PathIterator.SEG_CLOSE:
            break;
        }
        iter.next();
    }

    if (count == 4) {
        return xs[0] == xs[1] || xs[0] == xs[2] || ys[0] == ys[1] || ys[0] == ys[3];
    }
    return false;
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

protected Element createShape(Shape shape) {
    PathIterator pathIter = shape.getPathIterator(null);
    StringBuffer pathStr = new StringBuffer();
    while (!pathIter.isDone()) {
        float[] points = new float[6];
        int TYPE = pathIter.currentSegment(points);
        switch (TYPE) {
        case PathIterator.SEG_CLOSE:
            pathStr.append(" Z"); //$NON-NLS-1$
            break;
        case PathIterator.SEG_LINETO:
            pathStr.append(" L").append(toString(points, 2, ' ')); //$NON-NLS-1$ 
            break;
        case PathIterator.SEG_QUADTO:
            pathStr.append(" Q").append(toString(points, 4, ' ')); //$NON-NLS-1$ 
            break;
        case PathIterator.SEG_CUBICTO:
            pathStr.append(" C").append(toString(points, 6, ' ')); //$NON-NLS-1$ 
            break;
        case PathIterator.SEG_MOVETO:
            pathStr.append(" M").append(toString(points, 2, ' ')); //$NON-NLS-1$ 
            break;
        }//from   w ww.  j  a v  a  2 s .c om
        pathIter.next();
    }
    Element elem = dom.createElement("path"); //$NON-NLS-1$
    elem.setAttribute("d", pathStr.toString()); //$NON-NLS-1$
    return elem;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void followPath(Shape s, final int drawType) {
    if (s == null) {
        return;/*from ww w . j  a va  2 s. co  m*/
    }
    if (drawType == PdfGraphics2D.STROKE) {
        if (!(stroke instanceof BasicStroke)) {
            s = stroke.createStrokedShape(s);
            followPath(s, PdfGraphics2D.FILL);
            return;
        }
    }
    if (drawType == PdfGraphics2D.STROKE) {
        setStrokeDiff(stroke, oldStroke);
        oldStroke = stroke;
        setStrokePaint();
    } else if (drawType == PdfGraphics2D.FILL) {
        setFillPaint();
    }
    final PathIterator points;
    if (drawType == PdfGraphics2D.CLIP) {
        points = s.getPathIterator(PdfGraphics2D.IDENTITY);
    } else {
        points = s.getPathIterator(transform);
    }
    final float[] coords = new float[6];
    int traces = 0;
    while (!points.isDone()) {
        ++traces;
        final int segtype = points.currentSegment(coords);
        normalizeY(coords);
        switch (segtype) {
        case PathIterator.SEG_CLOSE:
            cb.closePath();
            break;

        case PathIterator.SEG_CUBICTO:
            cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;

        case PathIterator.SEG_LINETO:
            cb.lineTo(coords[0], coords[1]);
            break;

        case PathIterator.SEG_MOVETO:
            cb.moveTo(coords[0], coords[1]);
            break;

        case PathIterator.SEG_QUADTO:
            cb.curveTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        default:
            throw new IllegalStateException("Invalid segment type in path");
        }
        points.next();
    }
    switch (drawType) {
    case PdfGraphics2D.FILL:
        if (traces > 0) {
            if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
                cb.eoFill();
            } else {
                cb.fill();
            }
        }
        break;
    case PdfGraphics2D.STROKE:
        if (traces > 0) {
            cb.stroke();
        }
        break;
    default: // drawType==CLIP
        if (traces == 0) {
            cb.rectangle(0, 0, 0, 0);
        }
        if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
            cb.eoClip();
        } else {
            cb.clip();
        }
        cb.newPath();
    }
}