Search in sources :

Example 1 with SplineStart

use of org.apache.poi.xdgf.usermodel.section.geometry.SplineStart in project poi by apache.

the class GeometrySection method getPath.

public Path2D.Double getPath(XDGFShape parent) {
    Iterator<GeometryRow> rows = getCombinedRows().iterator();
    // special cases
    GeometryRow first = rows.next();
    if (first instanceof Ellipse) {
        return ((Ellipse) first).getPath();
    } else if (first instanceof InfiniteLine) {
        return ((InfiniteLine) first).getPath();
    } else if (first instanceof SplineStart) {
        throw new POIXMLException("SplineStart must be preceded by another type");
    } else {
        // everything else is a path
        Path2D.Double path = new Path2D.Double();
        // dealing with splines makes this more complex
        SplineCollector renderer = null;
        GeometryRow row;
        while (true) {
            if (first != null) {
                row = first;
                first = null;
            } else {
                if (!rows.hasNext())
                    break;
                row = rows.next();
            }
            if (row instanceof SplineStart) {
                if (renderer != null)
                    throw new POIXMLException("SplineStart found multiple times!");
                renderer = new SplineCollector((SplineStart) row);
            } else if (row instanceof SplineKnot) {
                if (renderer == null)
                    throw new POIXMLException("SplineKnot found without SplineStart!");
                renderer.addKnot((SplineKnot) row);
            } else {
                if (renderer != null) {
                    renderer.addToPath(path, parent);
                    renderer = null;
                }
                row.addToPath(path, parent);
            }
        }
        // just in case we end iteration
        if (renderer != null)
            renderer.addToPath(path, parent);
        return path;
    }
}
Also used : GeometryRow(org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow) SplineStart(org.apache.poi.xdgf.usermodel.section.geometry.SplineStart) Ellipse(org.apache.poi.xdgf.usermodel.section.geometry.Ellipse) Path2D(java.awt.geom.Path2D) POIXMLException(org.apache.poi.POIXMLException) SplineKnot(org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot) InfiniteLine(org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine) SplineCollector(org.apache.poi.xdgf.geom.SplineCollector)

Aggregations

Path2D (java.awt.geom.Path2D)1 POIXMLException (org.apache.poi.POIXMLException)1 SplineCollector (org.apache.poi.xdgf.geom.SplineCollector)1 Ellipse (org.apache.poi.xdgf.usermodel.section.geometry.Ellipse)1 GeometryRow (org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow)1 InfiniteLine (org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine)1 SplineKnot (org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot)1 SplineStart (org.apache.poi.xdgf.usermodel.section.geometry.SplineStart)1