package org.apache.xmlgraphics.java2d.ps; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.ByteArrayOutputStream; import junit.framework.TestCase; import org.apache.xmlgraphics.java2d.GraphicContext; import org.apache.xmlgraphics.ps.PSGenerator; public class PSDocumentGraphics2DTest extends TestCase { private ByteArrayOutputStream out; private PSDocumentGraphics2D graphics; protected void setUp() { out = new ByteArrayOutputStream(); graphics = new PSDocumentGraphics2D(false); graphics.setGraphicContext(new GraphicContext()); } protected void tearDown() { graphics.finalize(); graphics = null; out = null; } public void testStartPage() throws Exception { graphics.setupDocument(out, 598, 842); graphics.preparePainting(); graphics.translate(4, 4); AffineTransform current = graphics.getTransform(); PSGenerator gen = graphics.getPSGenerator(); gen.concatMatrix(current); boolean newTransform = gen.getCurrentState().checkTransform(current); assertFalse("Transformation state incorrect", newTransform); } public void testStartPageUseCase() throws Exception { graphics.setupDocument(out, 598, 842); graphics.preparePainting(); graphics.translate(4, 4); AffineTransform current = graphics.getTransform(); PSGenerator gen = graphics.getPSGenerator(); gen.saveGraphicsState(); gen.concatMatrix(current); graphics.establishColor(graphics.getColor()); graphics.applyPaint(graphics.getPaint(), false); graphics.applyStroke(graphics.getStroke()); graphics.draw(new Rectangle2D.Double(1, 1, 10, 1)); graphics.draw(new Rectangle2D.Double(1, 1, 1, 10)); graphics.draw(new Rectangle2D.Double(1, 11, 10, 1)); graphics.draw(new Rectangle2D.Double(11, 1, 1, 10)); gen.restoreGraphicsState(); graphics.finish(); System.out.println(new String(out.toByteArray(), "US-ASCII")); } }