modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGRegion.java
Print this page
@@ -1679,13 +1679,19 @@
* that the fill never looks scaled. For example, a tile-imaged based background will look stretched
* if we were to render a scaled shape. Instead, we produce a new shape based on the scaled size and
* then fill that shape without additional transforms.
*/
private Shape resizeShape(float topOffset, float rightOffset, float bottomOffset, float leftOffset) {
+ return resizeShape(shape, scaleShape, centerShape, width, height, topOffset, rightOffset, bottomOffset, leftOffset);
+ }
+
+ public static Shape resizeShape(Shape shape, boolean scale, boolean center,
+ float width, float height,
+ float topOffset, float rightOffset, float bottomOffset, float leftOffset) {
// The bounds of the shape, before any centering / scaling takes place
final RectBounds bounds = shape.getBounds();
- if (scaleShape) {
+ if (scale) {
// First we need to modify the transform to scale the shape so that it will fit
// within the insets.
SCRATCH_AFFINE.setToIdentity();
SCRATCH_AFFINE.translate(leftOffset, topOffset);
// width & height are the width and height of the region. w & h are the width and height
@@ -1693,15 +1699,15 @@
final float w = width - leftOffset - rightOffset;
final float h = height - topOffset - bottomOffset;
SCRATCH_AFFINE.scale(w / bounds.getWidth(), h / bounds.getHeight());
// If we also need to center it, we need to adjust the transform so as to place
// the shape in the center of the bounds
- if (centerShape) {
+ if (center) {
SCRATCH_AFFINE.translate(-bounds.getMinX(), -bounds.getMinY());
}
return SCRATCH_AFFINE.createTransformedShape(shape);
- } else if (centerShape) {
+ } else if (center) {
// We are only centering. In this case, what we want is for the
// original shape to be centered. If there are offsets (insets)
// then we must pre-scale about the center to account for it.
final float boundsWidth = bounds.getWidth();
final float boundsHeight = bounds.getHeight();