Java Code Examples for java.awt.geom.GeneralPath#getBounds2D()

The following examples show how to use java.awt.geom.GeneralPath#getBounds2D() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardGlyphVector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 2
Source File: StandardGlyphVector.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 3
Source File: StandardGlyphVector.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 4
Source File: StandardGlyphVector.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 5
Source File: StandardGlyphVector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 6
Source File: StandardGlyphVector.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 7
Source File: StandardGlyphVector.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 8
Source File: StandardGlyphVector.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 9
Source File: StandardGlyphVector.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 10
Source File: StandardGlyphVector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 11
Source File: GUIHex.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
private GeneralPath getInnerHexagon(GeneralPath hexagon, HexPoint center) {
    //inner hexagons are drawn outlined (not filled)
    //for this draw, the stroke width is half the scale reduction
    //the scale factor is multiplied by the average of hex width / height in order
    //to get a good estimate for which for stroke width the hex borders are touched
    //by the stroke

    AffineTransform at =
            AffineTransform.getScaleInstance(getHexDrawScale(), getHexDrawScale());
    GeneralPath innerHexagon = (GeneralPath) hexagon.createTransformedShape(at);

    // Translate innerHexagon to make it concentric.
    Rectangle2D innerBounds = innerHexagon.getBounds2D();
    HexPoint innerCenter = new HexPoint(
            innerBounds.getX() + innerBounds.getWidth() / 2.0,
            innerBounds.getY() + innerBounds.getHeight() / 2.0
    );
    HexPoint difference = HexPoint.difference(center, innerCenter);

    at = AffineTransform.getTranslateInstance(difference.getX(), difference.getY());
    innerHexagon.transform(at);

    return innerHexagon;
}
 
Example 12
Source File: StandardGlyphVector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 13
Source File: StandardGlyphVector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 14
Source File: Polygon2D.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
private void calculatePath() {
	path = new GeneralPath();
	path.moveTo(xpoints[0], ypoints[0]);
	for (int i = 1; i < npoints; i++) {
		path.lineTo(xpoints[i], ypoints[i]);
	}
	bounds = path.getBounds2D();
	closedPath = null;
}
 
Example 15
Source File: StarsTransition2D.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
protected static void fit(GeneralPath p, float length, float centerX, float centerY, GeneralPath path, Dimension size, float progress) {
    Rectangle2D r = p.getBounds2D();
    AffineTransform t = new AffineTransform();
    t.translate(-r.getX() - r.getWidth() / 2, -r.getY() - r.getHeight() / 2);
    t.rotate((1 - progress) * 1);
    double scaleProgress = Math.pow(progress, 3) * 0.75f;
    t.scale(length / r.getWidth() * (0.02 + 1.8 * scaleProgress), length / r
            .getWidth() * (0.02 + 1.8 * scaleProgress));
    p.transform(t);

    if (progress > 1) {
        progress = 1;
    }
    if (progress < 0) {
        progress = 0;
    }
    Point2D endPoint = ShapeUtils.getPoint(path, 1);
    Point2D startPoint = ShapeUtils.getPoint(path, progress);
    Rectangle2D pathBounds = ShapeBounds.getBounds(path);
    AffineTransform pathTransform = RectangularTransform.create(
            pathBounds,
            new Rectangle2D.Float(0, 0, size.width + 100, size.height)
    );
    pathTransform.transform(endPoint, endPoint);
    pathTransform.transform(startPoint, startPoint);
    r = p.getBounds();
    t.setToTranslation(-r.getCenterX() + centerX - endPoint.getX() + startPoint.getX(),
            -r.getCenterY() + centerY - endPoint.getY() + startPoint.getY());

    p.transform(t);
}
 
Example 16
Source File: StarsTransition2D.java    From pumpernickel with MIT License 5 votes vote down vote up
protected void fit(GeneralPath p, float length, float centerX,
		float centerY, GeneralPath path, Dimension size, float progress) {
	Rectangle2D r = p.getBounds2D();
	AffineTransform t = new AffineTransform();
	t.translate(-r.getX() - r.getWidth() / 2, -r.getY() - r.getHeight() / 2);
	t.rotate((1 - progress) * 1);
	double scaleProgress = Math.pow(progress, 3) * .75f;
	t.scale(length / r.getWidth() * (.02 + 1.8 * scaleProgress),
			length / r.getWidth() * (.02 + 1.8 * scaleProgress));
	p.transform(t);

	if (progress > 1)
		progress = 1;
	if (progress < 0)
		progress = 0;
	Point2D endPoint = ShapeUtils.getPoint(path, 1);
	Point2D startPoint = ShapeUtils.getPoint(path, progress);
	Rectangle2D pathBounds = ShapeBounds.getBounds(path);
	AffineTransform pathTransform = RectangularTransform.create(pathBounds,
			new Rectangle2D.Float(0, 0, size.width + 100, size.height));
	pathTransform.transform(endPoint, endPoint);
	pathTransform.transform(startPoint, startPoint);
	r = p.getBounds();
	t.setToTranslation(-r.getCenterX() + centerX - endPoint.getX()
			+ startPoint.getX(),
			-r.getCenterY() + centerY - endPoint.getY() + startPoint.getY());

	p.transform(t);
}
 
Example 17
Source File: StandardGlyphVector.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        if (sgv.invdtx.getShearX() == 0 && sgv.invdtx.getShearY() == 0) {
            final Rectangle2D.Float rect = strike.getGlyphOutlineBounds(glyphID);
            result = new Rectangle2D.Float(
                (float)(rect.x*sgv.invdtx.getScaleX() + sgv.invdtx.getTranslateX()),
                (float)(rect.y*sgv.invdtx.getScaleY() + sgv.invdtx.getTranslateY()),
                (float)(rect.width*sgv.invdtx.getScaleX()),
                (float)(rect.height*sgv.invdtx.getScaleY()));
        } else {
            GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
            gp.transform(sgv.invdtx);
            result = gp.getBounds2D();
        }
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 18
Source File: FreeForm.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public java.awt.Rectangle getBounds() {
    GeneralPath p = new GeneralPath();
    p.moveTo(points.get(0).x, points.get(0).y);
    for (int i = 1; i < points.size(); i++) {
        p.lineTo(points.get(i).x, points.get(i).y);
    }

    Rectangle2D r2d = p.getBounds2D();
    return new java.awt.Rectangle((int) r2d.getX(), (int) r2d.getY(), (int) r2d.getWidth(), (int) r2d.getHeight());
}
 
Example 19
Source File: WorldMapPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void zoomToProduct(Product product) {
    if (product == null || product.getSceneGeoCoding() == null) {
        return;
    }
    final GeneralPath[] generalPaths = getGeoBoundaryPaths(product);
    Rectangle2D modelArea = new Rectangle2D.Double();
    final Viewport viewport = getLayerCanvas().getViewport();
    for (GeneralPath generalPath : generalPaths) {
        final Rectangle2D rectangle2D = generalPath.getBounds2D();
        if (modelArea.isEmpty()) {
            if (!viewport.isModelYAxisDown()) {
                modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(),
                                   rectangle2D.getWidth(), rectangle2D.getHeight());
            }
            modelArea = rectangle2D;
        } else {
            modelArea.add(rectangle2D);
        }
    }
    Rectangle2D modelBounds = modelArea.getBounds2D();
    modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2,
                         modelBounds.getWidth() + 4, modelBounds.getHeight() + 4);

    modelBounds = cropToMaxModelBounds(modelBounds);

    viewport.zoom(modelBounds);
    fireScrolled();
}
 
Example 20
Source File: NestWorldMapPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void zoomToProduct(Product product) {
    final NestWorldMapPaneDataModel.Boundary[] selGeoBoundaries = dataModel.getSelectedGeoBoundaries();

    final GeneralPath[] generalPaths;
    if (product != null && product.getSceneGeoCoding() != null) {
        generalPaths = getGeoBoundaryPaths(product);
    } else if (selGeoBoundaries.length > 0) {
        generalPaths = assemblePathList(selGeoBoundaries[0].geoBoundary);//selGeoBoundaries[0].boundaryPaths;
    } else {
        return;
    }

    Rectangle2D modelArea = new Rectangle2D.Double();
    final Viewport viewport = layerCanvas.getViewport();
    for (GeneralPath generalPath : generalPaths) {
        final Rectangle2D rectangle2D = generalPath.getBounds2D();
        if (modelArea.isEmpty()) {
            if (!viewport.isModelYAxisDown()) {
                modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(),
                                   rectangle2D.getWidth(), rectangle2D.getHeight());
            }
            modelArea = rectangle2D;
        } else {
            modelArea.add(rectangle2D);
        }
    }
    Rectangle2D modelBounds = modelArea.getBounds2D();
    modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2,
                         modelBounds.getWidth() + 4, modelBounds.getHeight() + 4);

    modelBounds = cropToMaxModelBounds(modelBounds);

    viewport.zoom(modelBounds);
}