package processpathtest; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import java.io.File; import javax.imageio.ImageIO; import sun.java2d.loops.*; import sun.java2d.pipe.*; import sun.java2d.*; public class ProcessPathTest { public static void main(String[] args) throws Exception { //prepare output image BufferedImage bimg = new BufferedImage(256, 256, BufferedImage.TYPE_INT_BGR); Graphics2D g2d = (Graphics2D) bimg.getGraphics(); g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, bimg.getWidth(), bimg.getHeight()); g2d.setColor(Color.BLACK); // create test geometry Rectangle2D rect = new Rectangle2D.Double(); rect.setRect(0.5, 0.50, 24, 24); Path2D.Float floatPath = new Path2D.Float(rect); //call test routines testProcessPath(floatPath, g2d); testShapeSpanIterator(floatPath, g2d); ImageIO.write(bimg, "png", new File("res.png")); } private static void testShapeSpanIterator(Path2D.Float floatPath, Graphics2D g2d) { ShapeSpanIterator ssi = LoopPipe.getFillSSI((SunGraphics2D) g2d); ssi.setOutputArea(new Rectangle(0, 0, 1024, 1024)); PathIterator pi = floatPath.getPathIterator(AffineTransform.getTranslateInstance(0, 0)); ssi.appendPath(pi); int[] spanBox = new int[4]; while (ssi.nextSpan(spanBox)) { int x = spanBox[0] + 10; int y = spanBox[1] + 50; int width = spanBox[2] - spanBox[0]; int height = spanBox[3] - spanBox[1]; System.out.println("span: "+x+"/"+y+ " - "+width+"/"+height); g2d.fillRect(x, y, width, height); } } private static void testProcessPath(Path2D.Float floatPath, final Graphics2D g2d) { ProcessPath.fillPath(new ProcessPath.DrawHandler(0, 0, 1024, 1024) { void validate(SunGraphics2D sg2d) { Region clip = sg2d.getCompClip(); setBounds(clip.getLoX(), clip.getLoY(), clip.getHiX(), clip.getHiY(), sg2d.strokeHint); } public void drawLine(int x1, int y1, int x2, int y2) { System.out.println("drawline: "+x1+"/"+y1+ " - "+x2+"/"+y2); g2d.drawLine(x1, y1, x2, y2); } public void drawPixel(int x, int y) { System.out.println("drawpixel: "+x+"/"+y); g2d.fillRect(x, y, 1, 1); } public void drawScanline(int x1, int x2, int y) { System.out.println("drawscanline: "+x1+"/"+x2+ " - "+y); g2d.fillRect(x1, y, x2 - x1 + 1, 1); } }, floatPath, 10, 10); } }