Example usage for java.awt.geom Path2D.Float curveTo

List of usage examples for java.awt.geom Path2D.Float curveTo

Introduction

In this page you can find the example usage for java.awt.geom Path2D.Float curveTo.

Prototype

public abstract void curveTo(double x1, double y1, double x2, double y2, double x3, double y3);

Source Link

Document

Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates (x3,y3) , using the specified points (x1,y1) and (x2,y2) as Bézier control points.

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 ww.ja v a2 s  .  c o  m*/
        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;
    }
}