use of com.intellij.ui.Graphics2DDelegate in project android by JetBrains.
the class FakeImageFactory method getImage.
@Override
public BufferedImage getImage(final int w, final int h) {
// only in the createGraphics call.
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB) {
@Override
public Graphics2D createGraphics() {
myRequestedHeight = h;
myRequestedWidth = w;
// TODO: Check if we can stop layoutlib from resetting the transforms.
final Shape originalClip = myGraphics.getClip();
final AffineTransform originalTx = ((Graphics2D) myGraphics).getTransform();
AffineTransform inverse = null;
if (originalTx != null) {
try {
inverse = originalTx.createInverse();
} catch (NoninvertibleTransformException e) {
LOG.error(e);
}
}
final AffineTransform originalTxInverse = inverse;
return new Graphics2DDelegate((Graphics2D) myGraphics.create()) {
@Nullable
private Shape intersect(@Nullable Shape s1, @Nullable Shape s2) {
if (s1 == null || s2 == null) {
return s1 == null ? s2 : s1;
}
Area a1 = new Area(s1);
Area a2 = new Area(s2);
a1.intersect(a2);
return a1;
}
@Override
public void clip(@Nullable Shape s) {
if (s == null) {
setClip(null);
return;
}
super.clip(s);
}
@Override
public void setClip(@Nullable Shape sh) {
try {
super.setClip(intersect(getTransform().createInverse().createTransformedShape(originalClip), sh));
} catch (NoninvertibleTransformException e) {
LOG.error(e);
}
}
@Override
public void setTransform(AffineTransform Tx) {
if (originalTx != null) {
AffineTransform transform = (AffineTransform) originalTx.clone();
transform.concatenate(Tx);
super.setTransform(transform);
} else {
super.setTransform(Tx);
}
}
@Override
public AffineTransform getTransform() {
AffineTransform currentTransform = super.getTransform();
if (originalTxInverse != null) {
currentTransform.concatenate(originalTxInverse);
}
return currentTransform;
}
};
}
@Override
public int getWidth() {
return w;
}
@Override
public int getHeight() {
return h;
}
};
}
Aggregations