Example usage for java.awt.geom GeneralPath GeneralPath

List of usage examples for java.awt.geom GeneralPath GeneralPath

Introduction

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

Prototype

public GeneralPath() 

Source Link

Document

Constructs a new empty single precision GeneralPath object with a default winding rule of #WIND_NON_ZERO .

Usage

From source file:org.apache.fontbox.ttf.GlyphRenderer.java

/**
 * Use the given points to calculate a GeneralPath.
 *
 * @param points the points to be used to generate the GeneralPath
 *
 * @return the calculated GeneralPath//from www  .  j  a  va  2  s  . c om
 */
private GeneralPath calculatePath(Point[] points) {
    GeneralPath path = new GeneralPath();
    int start = 0;
    for (int p = 0, len = points.length; p < len; ++p) {
        if (points[p].endOfContour) {
            Point firstPoint = points[start];
            Point lastPoint = points[p];
            List<Point> contour = new ArrayList<Point>();
            for (int q = start; q <= p; ++q) {
                contour.add(points[q]);
            }
            if (points[start].onCurve) {
                // using start point at the contour end
                contour.add(firstPoint);
            } else if (points[p].onCurve) {
                // first is off-curve point, trying to use one from the end
                contour.add(0, lastPoint);
            } else {
                // start and end are off-curve points, creating implicit one
                Point pmid = midValue(firstPoint, lastPoint);
                contour.add(0, pmid);
                contour.add(pmid);
            }
            moveTo(path, contour.get(0));
            for (int j = 1, clen = contour.size(); j < clen; j++) {
                Point pnow = contour.get(j);
                if (pnow.onCurve) {
                    lineTo(path, pnow);
                } else if (contour.get(j + 1).onCurve) {
                    quadTo(path, pnow, contour.get(j + 1));
                    ++j;
                } else {
                    quadTo(path, pnow, midValue(pnow, contour.get(j + 1)));
                }
            }
            path.closePath();
            start = p + 1;
        }
    }
    return path;
}

From source file:org.apache.fop.render.java2d.Java2DBorderPainter.java

/** {@inheritDoc} */
protected void lineTo(int x, int y) {
    if (currentPath == null) {
        currentPath = new GeneralPath();
    }//from   ww  w .  j  a v  a  2 s .  c om
    currentPath.lineTo(x, y);
}

From source file:org.apache.fop.render.java2d.Java2DBorderPainter.java

/** {@inheritDoc} */
protected void moveTo(int x, int y) {
    if (currentPath == null) {
        currentPath = new GeneralPath();
    }/*from  w  ww .  java2s  . c om*/
    currentPath.moveTo(x, y);
}

From source file:org.apache.fop.render.java2d.Java2DGraphicsPainter.java

/** {@inheritDoc} */
public void moveTo(int x, int y) throws IOException {
    if (currentPath == null) {
        currentPath = new GeneralPath();
    }//from w w w.ja  va2 s  . com
    currentPath.moveTo(x, y);
}

From source file:org.apache.fop.render.java2d.Java2DGraphicsPainter.java

/** {@inheritDoc} */
public void lineTo(int x, int y) throws IOException {
    if (currentPath == null) {
        currentPath = new GeneralPath();
    }//from  w ww.j a  v  a 2  s . c o m
    currentPath.lineTo(x, y);
}

From source file:org.apache.fop.render.pcl.PCLRenderer.java

/**
 * Appends a straight line segment from the current point to (x, y). The
 * new current point is (x, y).//  w  w  w.  j a v  a  2 s . co  m
 * @param x x coordinate
 * @param y y coordinate
 */
protected void lineTo(float x, float y) {
    if (currentPath == null) {
        currentPath = new GeneralPath();
    }
    currentPath.lineTo(x, y);
}

From source file:org.apache.fop.render.pcl.PCLRenderer.java

/**
 * Moves the current point to (x, y), omitting any connecting line segment.
 * @param x x coordinate//from w  w w . ja  v a 2 s.c o m
 * @param y y coordinate
 */
protected void moveTo(float x, float y) {
    if (currentPath == null) {
        currentPath = new GeneralPath();
    }
    currentPath.moveTo(x, y);
}

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

/**
 * Use the given points to calculate a GeneralPath.
 * /*from  w  w w.  j a  v  a 2s . c  o m*/
 * @param points the points to be used to generate the GeneralPath
 * 
 * @return the calculated GeneralPath
 */
private GeneralPath calculatePath(Point[] points) {
    GeneralPath path = new GeneralPath();
    int numberOfPoints = points.length;
    int i = 0;
    boolean endOfContour = true;
    Point startingPoint = null;
    Point offCurveStartPoint = null;
    while (i < numberOfPoints) {
        Point point = points[i % numberOfPoints];
        Point nextPoint1 = points[(i + 1) % numberOfPoints];
        Point nextPoint2 = points[(i + 2) % numberOfPoints];
        // new contour
        if (endOfContour) {
            // skip endOfContour points
            if (point.endOfContour) {
                i++;
                continue;
            }
            // move to the starting point
            moveTo(path, point);
            endOfContour = false;
            startingPoint = point;

            offCurveStartPoint = null;
            if (!point.onCurve && !nextPoint1.onCurve) {
                // off curve start
                offCurveStartPoint = point;
                startingPoint = midValue(point, nextPoint1);
                moveTo(path, startingPoint);
            }
        }

        if (point.onCurve) {
            offCurveStartPoint = null;
        }
        // lineTo
        if (point.onCurve && nextPoint1.onCurve) {
            lineTo(path, nextPoint1);
            i++;
            if (point.endOfContour || nextPoint1.endOfContour) {
                endOfContour = true;
                closePath(path);
            }
            continue;
        }
        // quadratic bezier
        if (point.onCurve && !nextPoint1.onCurve && nextPoint2.onCurve) {
            if (nextPoint1.endOfContour) {
                // use the starting point as end point
                quadTo(path, nextPoint1, startingPoint);
            } else {
                quadTo(path, nextPoint1, nextPoint2);
            }
            if (nextPoint1.endOfContour || nextPoint2.endOfContour) {
                endOfContour = true;
                closePath(path);
            }
            i += 2;
            continue;
        }

        // TH segment for curves that start with an off-curve point
        if (offCurveStartPoint != null && !nextPoint1.onCurve && !nextPoint2.onCurve) {
            // interpolate endPoint
            quadTo(path, nextPoint1, midValue(nextPoint1, nextPoint2));
            if (point.endOfContour || nextPoint1.endOfContour || nextPoint2.endOfContour) {
                quadTo(path, nextPoint2, midValue(nextPoint2, offCurveStartPoint));
                quadTo(path, offCurveStartPoint, startingPoint);
                endOfContour = true;
                i += 2;
                continue;
            }
            ++i;
            continue;
        }

        if (point.onCurve && !nextPoint1.onCurve && !nextPoint2.onCurve) {
            // interpolate endPoint
            quadTo(path, nextPoint1, midValue(nextPoint1, nextPoint2));
            if (point.endOfContour || nextPoint1.endOfContour || nextPoint2.endOfContour) {
                quadTo(path, nextPoint2, startingPoint);
                endOfContour = true;
                closePath(path);
            }
            i += 2;
            continue;
        }

        // TH the control point is never interpolated
        if (!point.onCurve && !nextPoint1.onCurve) {
            quadTo(path, point, midValue(point, nextPoint1));
            if (point.endOfContour || nextPoint1.endOfContour) {
                endOfContour = true;
                quadTo(path, nextPoint1, startingPoint);
            }
            i++;
            continue;
        }

        if (!point.onCurve && nextPoint1.onCurve) {
            quadTo(path, point, nextPoint1);
            if (point.endOfContour || nextPoint1.endOfContour) {
                endOfContour = true;
                closePath(path);
            }
            i++;
            continue;
        }
        LOG.error("Unknown glyph command!!");
        break;
    }
    return path;
}

From source file:org.apache.pdfbox.pdmodel.font.PDCIDFontType2.java

@Override
public GeneralPath getPath(int code) throws IOException {
    if (ttf instanceof OpenTypeFont && ((OpenTypeFont) ttf).isPostScript()) {
        int cid = codeToCID(code);
        Type2CharString charstring = ((OpenTypeFont) ttf).getCFF().getFont().getType2CharString(cid);
        return charstring.getPath();
    } else {/* ww w  .  j  a v a  2s .  c om*/
        int gid = codeToGID(code);
        GlyphData glyph = ttf.getGlyph().getGlyph(gid);
        if (glyph != null) {
            return glyph.getPath();
        }
        return new GeneralPath();
    }
}

From source file:org.apache.pdfbox.pdmodel.graphics.PDGraphicsState.java

/**
 * This will set the current clipping path.
 *
 * @param pCurrentClippingPath The current clipping path.
 *
 *//*w ww .  ja  v  a 2 s. c  om*/
public void setCurrentClippingPath(Shape pCurrentClippingPath) {
    if (pCurrentClippingPath != null) {
        if (pCurrentClippingPath instanceof GeneralPath) {
            currentClippingPath = (GeneralPath) pCurrentClippingPath;
        } else {
            currentClippingPath = new GeneralPath();
            currentClippingPath.append(pCurrentClippingPath, false);
        }
    } else {
        currentClippingPath = null;
    }
}