use of java.awt.geom.AffineTransform 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;
}
};
}
use of java.awt.geom.AffineTransform in project android by JetBrains.
the class GraphicsLayoutRenderer method render.
/**
* Render the layout to the passed {@link Graphics2D} instance using the defined viewport.
* <p/>
* <p/>Please note that this method is not thread safe so, if used from multiple threads, it's the caller's responsibility to synchronize
* the access to it.
*/
public boolean render(@NotNull final Graphics2D graphics) {
myRenderSessionLock.readLock().lock();
try {
if (!SystemInfo.isMac) {
// Do not enable anti-aliasing on MAC. It doesn't improve much and causes has performance issues when filling the background using
// alpha values.
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
myImageFactory.setGraphics(graphics);
AffineTransform oldTransform = graphics.getTransform();
if (myScale != 1.0) {
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
AffineTransform scaleTransform = new AffineTransform(oldTransform);
scaleTransform.scale(myScale, myScale);
graphics.setTransform(scaleTransform);
}
Result result = null;
try {
result = RenderService.runRenderAction(new Callable<Result>() {
@Override
public Result call() {
if (mySecurityManager != null) {
mySecurityManager.setActive(true, myCredential);
}
try {
return myRenderSession.render(RenderParams.DEFAULT_TIMEOUT, myInvalidate);
} finally {
if (mySecurityManager != null) {
mySecurityManager.setActive(false, myCredential);
}
}
}
});
} catch (Exception e) {
LOG.warn("Exception running render action", e);
}
if (myScale != 1.0) {
graphics.setTransform(oldTransform);
}
// access the system properties.
if (result != null && result.getStatus() != Result.Status.SUCCESS) {
//noinspection ThrowableResultOfMethodCallIgnored
if (result.getException() != null) {
LOG.warn(result.getException());
} else {
LOG.warn("Render error (no exception). Status=" + result.getStatus().name());
}
return false;
}
myInvalidate = false;
return true;
} finally {
myRenderSessionLock.readLock().unlock();
}
}
use of java.awt.geom.AffineTransform in project adempiere by adempiere.
the class ImageElement method paint.
/**
* Paint Image
* @param g2D Graphics
* @param pageStart top left Location of page
* @param pageNo page number for multi page support (0 = header/footer) - ignored
* @param ctx print context
* @param isView true if online view (IDs are links)
*/
public void paint(Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView) {
if (m_image == null)
return;
// Position
Point2D.Double location = getAbsoluteLocation(pageStart);
int x = (int) location.x;
if (MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight.equals(p_FieldAlignmentType))
x += p_maxWidth - p_width;
else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Center.equals(p_FieldAlignmentType))
x += (p_maxWidth - p_width) / 2;
int y = (int) location.y;
// map a scaled and shifted version of the image to device space
AffineTransform transform = new AffineTransform();
transform.translate(x, y);
transform.scale(m_scaleFactor, m_scaleFactor);
g2D.drawImage(m_image, transform, this);
}
use of java.awt.geom.AffineTransform in project poi by apache.
the class ShapeRenderer method visit.
@Override
public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {
AffineTransform savedTr = _graphics.getTransform();
_graphics.transform(globalTransform);
drawPath(shape);
drawText(shape);
// we're done, undo the transforms
_graphics.setTransform(savedTr);
}
use of java.awt.geom.AffineTransform in project poi by apache.
the class TestXSLFBugs method bug54542.
@Test
@Ignore("Similar to TestFontRendering it doesn't make sense to compare images because of tiny rendering differences in windows/unix")
public void bug54542() throws Exception {
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("54542_cropped_bitmap.pptx");
Dimension pgsize = ss.getPageSize();
XSLFSlide slide = ss.getSlides().get(0);
// render it
double zoom = 1;
AffineTransform at = new AffineTransform();
at.setToScale(zoom, zoom);
BufferedImage imgActual = new BufferedImage((int) Math.ceil(pgsize.width * zoom), (int) Math.ceil(pgsize.height * zoom), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D graphics = imgActual.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.setTransform(at);
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
slide.draw(graphics);
ImageIO.write(imgActual, "PNG", new File("bug54542.png"));
ss.close();
}
Aggregations