src/share/classes/sun/java2d/SunGraphics2D.java
Print this page
*** 1793,1829 ****
public Stroke getStroke() {
return stroke;
}
public Rectangle getClipBounds() {
- Rectangle r;
if (clipState == CLIP_DEVICE) {
! r = null;
! } else if (transformState <= TRANSFORM_INT_TRANSLATE) {
! if (usrClip instanceof Rectangle) {
! r = new Rectangle((Rectangle) usrClip);
! } else {
! r = usrClip.getBounds();
! }
! r.translate(-transX, -transY);
! } else {
! r = getClip().getBounds();
}
! return r;
}
public Rectangle getClipBounds(Rectangle r) {
if (clipState != CLIP_DEVICE) {
if (transformState <= TRANSFORM_INT_TRANSLATE) {
if (usrClip instanceof Rectangle) {
r.setBounds((Rectangle) usrClip);
} else {
! r.setBounds(usrClip.getBounds());
}
r.translate(-transX, -transY);
} else {
! r.setBounds(getClip().getBounds());
}
} else if (r == null) {
throw new NullPointerException("null rectangle parameter");
}
return r;
--- 1793,1819 ----
public Stroke getStroke() {
return stroke;
}
public Rectangle getClipBounds() {
if (clipState == CLIP_DEVICE) {
! return null;
}
! return getClipBounds(new Rectangle());
}
public Rectangle getClipBounds(Rectangle r) {
if (clipState != CLIP_DEVICE) {
if (transformState <= TRANSFORM_INT_TRANSLATE) {
if (usrClip instanceof Rectangle) {
r.setBounds((Rectangle) usrClip);
} else {
! r.setFrame(usrClip.getBounds2D());
}
r.translate(-transX, -transY);
} else {
! r.setFrame(getClip().getBounds2D());
}
} else if (r == null) {
throw new NullPointerException("null rectangle parameter");
}
return r;
*** 1994,2016 ****
matrix[0] = rect.getX();
matrix[1] = rect.getY();
matrix[2] = matrix[0] + rect.getWidth();
matrix[3] = matrix[1] + rect.getHeight();
tx.transform(matrix, 0, matrix, 0, 2);
! rect = new Rectangle2D.Float();
! rect.setFrameFromDiagonal(matrix[0], matrix[1],
! matrix[2], matrix[3]);
! return rect;
}
if (tx.isIdentity()) {
return cloneShape(clip);
}
return tx.createTransformedShape(clip);
}
public void clipRect(int x, int y, int w, int h) {
clip(new Rectangle(x, y, w, h));
}
public void setClip(int x, int y, int w, int h) {
--- 1984,2022 ----
matrix[0] = rect.getX();
matrix[1] = rect.getY();
matrix[2] = matrix[0] + rect.getWidth();
matrix[3] = matrix[1] + rect.getHeight();
tx.transform(matrix, 0, matrix, 0, 2);
! fixRectangleOrientation(matrix, rect);
! return new Rectangle2D.Double(matrix[0], matrix[1],
! matrix[2] - matrix[0],
! matrix[3] - matrix[1]);
}
if (tx.isIdentity()) {
return cloneShape(clip);
}
return tx.createTransformedShape(clip);
}
+ /**
+ * Sets orientation of the rectangle according to the clip.
+ */
+ private static void fixRectangleOrientation(double[] m, Rectangle2D clip) {
+ if (clip.getWidth() > 0 != (m[2] - m[0] > 0)) {
+ double t = m[0];
+ m[0] = m[2];
+ m[2] = t;
+ }
+ if (clip.getHeight() > 0 != (m[3] - m[1] > 0)) {
+ double t = m[1];
+ m[1] = m[3];
+ m[3] = t;
+ }
+ }
+
public void clipRect(int x, int y, int w, int h) {
clip(new Rectangle(x, y, w, h));
}
public void setClip(int x, int y, int w, int h) {