diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/awt/GLCanvas.java | 236 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java | 204 |
2 files changed, 276 insertions, 164 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 4cf3807c4..aa2936907 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -89,6 +89,7 @@ import javax.media.opengl.GLDrawable; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; +import javax.media.opengl.GLOffscreenAutoDrawable; import javax.media.opengl.GLProfile; import javax.media.opengl.GLRunnable; import javax.media.opengl.Threading; @@ -104,11 +105,12 @@ import com.jogamp.nativewindow.awt.AWTGraphicsScreen; import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol; import com.jogamp.nativewindow.awt.JAWTWindow; import com.jogamp.opengl.JoglVersion; -import com.jogamp.opengl.util.RandomTileRenderer; +import com.jogamp.opengl.util.GLDrawableUtil; import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes; +import com.jogamp.opengl.util.TileRenderer; import com.jogamp.opengl.util.TileRendererBase; import com.jogamp.opengl.util.awt.AWTGLPixelBuffer; -import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.SingleAWTGLPixelBufferProvider; +import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.AWTGLPixelBufferProvider; import jogamp.opengl.Debug; import jogamp.opengl.GLContextImpl; @@ -631,7 +633,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } private boolean validateGLDrawable() { - if( Beans.isDesignTime() || !isDisplayable() ) { + if( Beans.isDesignTime() || !isDisplayable() || printActive ) { return false; // early out! } final GLDrawable _drawable = drawable; @@ -733,67 +735,33 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing paint(g); } - private static SingleAWTGLPixelBufferProvider singleAWTGLPixelBufferProvider = null; - private static synchronized SingleAWTGLPixelBufferProvider getSingleAWTGLPixelBufferProvider() { - if( null == singleAWTGLPixelBufferProvider ) { - singleAWTGLPixelBufferProvider = new SingleAWTGLPixelBufferProvider( true /* allowRowStride */ ); - } - return singleAWTGLPixelBufferProvider; - } - private boolean printActive = false; - private boolean printAnimatorPaused = false; - private RandomTileRenderer printRenderer; - private Graphics2D printGraphics; - private int printWidth = 0; - private int printHeight = 0; - public void setupPrint (final double scaleX, final double scaleY) { - printActive = true; - // this.printWidth = scaleX; - // this.printHeight = scaleY; - } - private void initPrint() { - printActive = true; - final GLAnimatorControl animator = helper.getAnimator(); - if( animator.isAnimating() ) { - animator.pause(); - printAnimatorPaused = true; - } - if( 0 >= printWidth ) { - printWidth = getWidth(); - } - if( 0 >= printHeight ) { - printHeight = getHeight(); - } - System.err.println("AWT print.init: printSize "+printWidth+"x"+printHeight+", canvasSize "+getWidth()+"x"+getWidth()+ - ", drawableSize "+drawable.getWidth()+"x"+drawable.getHeight()+ - ", animatorPaused "+printAnimatorPaused); - { - final RenderingHints rHints = printGraphics.getRenderingHints(); - final Set<Entry<Object, Object>> rEntries = rHints.entrySet(); - int count = 0; - for(Iterator<Entry<Object, Object>> rEntryIter = rEntries.iterator(); rEntryIter.hasNext(); count++) { - final Entry<Object, Object> rEntry = rEntryIter.next(); - System.err.println("Hint["+count+"]: "+rEntry.getKey()+" -> "+rEntry.getValue()); - } + private static final int PRINT_TILE_SIZE = 256; + private volatile boolean printActive = false; + private GLOffscreenAutoDrawable printGLAD = null; + private TileRenderer printRenderer = null; + private GLAnimatorControl printAnimator = null; + private AWTGLPixelBuffer printBuffer = null; + private BufferedImage printVFlipImage = null; + private Graphics2D printGraphics = null; + + public void setupPrint() { + printActive = true; + sendReshape = false; // clear reshape flag + printAnimator = helper.getAnimator(); + if( null != printAnimator ) { + printAnimator.remove(this); } - // final GraphicsConfiguration gc = printGraphics.getDeviceConfiguration(); - final AffineTransform aTrans = printGraphics.getTransform(); - System.err.println(" scale "+aTrans.getScaleX()+" x "+aTrans.getScaleY()); - System.err.println(" move "+aTrans.getTranslateX()+" x "+aTrans.getTranslateY()); + final GLCapabilities caps = (GLCapabilities)getChosenGLCapabilities().cloneMutable(); + caps.setOnscreen(false); + final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile()); + printGLAD = factory.createOffscreenAutoDrawable(null, caps, null, PRINT_TILE_SIZE, PRINT_TILE_SIZE, null); + GLDrawableUtil.swapGLContextAndAllGLEventListener(this, printGLAD); + destroyOnEDTAction.run(); + printRenderer = new TileRenderer(); + printRenderer.setRowOrder(TileRenderer.TR_TOP_TO_BOTTOM); + printRenderer.setTileSize(printGLAD.getWidth(), printGLAD.getHeight(), 0); + printRenderer.attachToAutoDrawable(printGLAD); - final SingleAWTGLPixelBufferProvider printBufferProvider = getSingleAWTGLPixelBufferProvider(); - printRenderer = new RandomTileRenderer(); - printRenderer.setImageSize(printWidth, printHeight); - printRenderer.attachToAutoDrawable(this); - final int componentCount; - if( isOpaque() ) { - // w/o alpha - componentCount = 3; - } else { - // with alpha - componentCount = 4; - } - final BufferedImage[] cpuVFlipImageStore = { null }; final GLEventListener preTileGLEL = new GLEventListener() { @Override public void init(GLAutoDrawable drawable) { @@ -803,22 +771,13 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing @Override public void display(GLAutoDrawable drawable) { final GL gl = drawable.getGL(); - final GLPixelAttributes pixelAttribs = printBufferProvider.getAttributes(gl, componentCount); - final int tileWidth = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_WIDTH); - final int tileHeight = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_HEIGHT); - AWTGLPixelBuffer pixelBuffer = printBufferProvider.getSingleBuffer(pixelAttribs); - if( null != pixelBuffer && pixelBuffer.requiresNewBuffer(gl, tileWidth, tileHeight, 0) ) { - pixelBuffer.dispose(); - pixelBuffer = null; - } - if ( null == pixelBuffer ) { - pixelBuffer = printBufferProvider.allocate(gl, pixelAttribs, tileWidth, tileHeight, 1, true, 0); - printRenderer.setTileBuffer(pixelBuffer); - } - - final BufferedImage cpuVFlipImage = cpuVFlipImageStore[0]; - if( null == cpuVFlipImage || pixelBuffer.width > cpuVFlipImage.getWidth() || pixelBuffer.height > cpuVFlipImage.getHeight() ) { - cpuVFlipImageStore[0] = new BufferedImage(pixelBuffer.width, pixelBuffer.height, pixelBuffer.image.getType()); + if( null == printBuffer ) { + final int componentCount = isOpaque() ? 3 : 4; + final AWTGLPixelBufferProvider printBufferProvider = new AWTGLPixelBufferProvider( true /* allowRowStride */ ); + final GLPixelAttributes pixelAttribs = printBufferProvider.getAttributes(gl, componentCount); + printBuffer = printBufferProvider.allocate(gl, pixelAttribs, printGLAD.getWidth(), printGLAD.getHeight(), 1, true, 0); + printRenderer.setTileBuffer(printBuffer); + printVFlipImage = new BufferedImage(printBuffer.width, printBuffer.height, printBuffer.image.getType()); } System.err.println("XXX tile-pre "+printRenderer); // FIXME } @@ -826,8 +785,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} }; final GLEventListener postTileGLEL = new GLEventListener() { + int tTopRowHeight = 0; @Override public void init(GLAutoDrawable drawable) { + tTopRowHeight = 0; } @Override public void dispose(GLAutoDrawable drawable) {} @@ -837,58 +798,119 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing // blitting Note that we could avoid this copy in the cases // where !offscreenDrawable.isGLOriented(), // but that's the software rendering path which is very slow anyway. - final int tileHeight = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_HEIGHT); - final AWTGLPixelBuffer pixelBuffer = (AWTGLPixelBuffer) printRenderer.getTileBuffer(); - final BufferedImage srcImage = pixelBuffer.image; - final BufferedImage dstImage = cpuVFlipImageStore[0]; + final int tHeight = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_HEIGHT); + final int tWidth = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_WIDTH); + // final BufferedImage dstImage = printBuffer.image; + final BufferedImage srcImage = printBuffer.image; + final BufferedImage dstImage = printVFlipImage; final int[] src = ((DataBufferInt) srcImage.getRaster().getDataBuffer()).getData(); final int[] dst = ((DataBufferInt) dstImage.getRaster().getDataBuffer()).getData(); - final int incr = pixelBuffer.width; + final int incr = printBuffer.width; int srcPos = 0; - int destPos = (tileHeight - 1) * pixelBuffer.width; + int destPos = (tHeight - 1) * printBuffer.width; for (; destPos >= 0; srcPos += incr, destPos -= incr) { System.arraycopy(src, srcPos, dst, destPos, incr); } - System.err.println("XXX tile-post dst-img "+dstImage); // FIXME // Draw resulting image in one shot - printGraphics.drawImage(dstImage, 0, 0, dstImage.getWidth(), dstImage.getHeight(), null); // Null ImageObserver since image data is ready. - System.err.println("XXX tile-post.X"); // FIXME + final int tCols = printRenderer.getParam(TileRenderer.TR_COLUMNS); + final int tRows = printRenderer.getParam(TileRenderer.TR_ROWS); + final int tCol = printRenderer.getParam(TileRenderer.TR_CURRENT_COLUMN); + final int tRow = printRenderer.getParam(TileRenderer.TR_CURRENT_ROW); + final int pX = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_X_POS); + final int pY = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_Y_POS); + final int pYf; + if( tRow == tRows - 1 ) { + tTopRowHeight = tHeight; + pYf = 0; + } else if( tRow == tRows - 2 ){ + pYf = tTopRowHeight; + } else { + pYf = ( tRows - 2 - tRow ) * tHeight + tTopRowHeight; + } + printGraphics.drawImage(dstImage, pX, pYf, dstImage.getWidth(), dstImage.getHeight(), null); // Null ImageObserver since image data is ready. + printGraphics.setColor(Color.BLACK); + printGraphics.drawRect(pX, pYf, tWidth, tHeight); + System.err.println("XXX tile-post.X "+tCols+"x"+tRows+" ["+tCol+"]["+tRow+"] "+pX+"/"+pY+" "+tWidth+"x"+tHeight+" dst-img "+dstImage.getWidth()+"x"+dstImage.getHeight()+" -> "+pX+"/"+pYf); // +", "+dstImage); // FIXME } @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} }; printRenderer.setGLEventListener(preTileGLEL, postTileGLEL); - System.err.println("AWT print.init: "+printRenderer); + + System.err.println("AWT print.setup "+printRenderer); // FIXME + System.err.println("AWT print.setup "+printGLAD); // FIXME } + public void releasePrint() { - System.err.println("AWT print.release: "+printRenderer); - printRenderer.detachFromAutoDrawable(); + if( !printActive || null == printGLAD ) { + throw new IllegalStateException("setupPrint() not called"); + } + printRenderer.detachFromAutoDrawable(); // tile-renderer -> printGLAD + createDrawableAndContext( false ); + GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, this); + printGLAD.destroy(); + if( null != printAnimator ) { + printAnimator.add(this); + } + printGLAD = null; printRenderer = null; - this.printGraphics = null; - singleAWTGLPixelBufferProvider = null; - final GLAnimatorControl animator = printAnimatorPaused ? helper.getAnimator() : null; - if( null != animator ) { - animator.resume(); + printAnimator = null; + if( null != printBuffer ) { + printBuffer.dispose(); + printBuffer = null; + } + if( null != printVFlipImage ) { + printVFlipImage.flush(); + printVFlipImage = null; } - printAnimatorPaused = false; + printGraphics = null; + System.err.println("AWT print.release "+printRenderer); // FIXME + System.err.println("AWT print.release "+this); // FIXME printActive = false; } @Override public void print(Graphics graphics) { - this.printGraphics = (Graphics2D)graphics; - if( null == printRenderer ) { - initPrint(); + if( !printActive || null == printGLAD ) { + throw new IllegalStateException("setupPrint() not called"); + } + sendReshape = false; // clear reshape flag + + printGraphics = (Graphics2D)graphics; + + System.err.println("AWT print.0: canvasSize "+getWidth()+"x"+getWidth()+", printAnimator "+printAnimator); + { + final RenderingHints rHints = printGraphics.getRenderingHints(); + final Set<Entry<Object, Object>> rEntries = rHints.entrySet(); + int count = 0; + for(Iterator<Entry<Object, Object>> rEntryIter = rEntries.iterator(); rEntryIter.hasNext(); count++) { + final Entry<Object, Object> rEntry = rEntryIter.next(); + System.err.println("Hint["+count+"]: "+rEntry.getKey()+" -> "+rEntry.getValue()); + } + } + // final GraphicsConfiguration gc = printGraphics.getDeviceConfiguration(); + final AffineTransform aTrans = printGraphics.getTransform(); + System.err.println(" scale "+aTrans.getScaleX()+" x "+aTrans.getScaleY()); + System.err.println(" move "+aTrans.getTranslateX()+" x "+aTrans.getTranslateY()); + + final Rectangle gClipOrig = graphics.getClipBounds(); + final Rectangle gClip = new Rectangle(gClipOrig); + if( 0 > gClip.x ) { + gClip.width += gClip.x; + gClip.x = 0; } - if( null != printRenderer ) { - final Rectangle clip = graphics.getClipBounds(); - System.err.println("AWT print0.1: "+clip+", "+printRenderer); - printRenderer.setTileRect(clip.x, clip.y, clip.width, clip.height); + if( 0 > gClip.y ) { + gClip.height += gClip.y; + gClip.y = 0; } - System.err.println("AWT print0.2: "+printRenderer); - // super.print(graphics); - display(); - System.err.println("AWT print0.X: "+printRenderer); + printRenderer.setImageSize(gClip.width, gClip.height); + printRenderer.setTileOffset(gClip.x, gClip.y); + System.err.println("AWT print.0: "+gClipOrig+" -> "+gClip); + System.err.println("AWT print.0: "+printRenderer); + do { + printRenderer.display(); + } while ( !printRenderer.eot() ); + System.err.println("AWT print.X: "+printRenderer); } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java index 0f0f492b0..85ea0a3df 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java @@ -28,19 +28,6 @@ package com.jogamp.opengl.test.junit.jogl.tile; -import javax.media.opengl.*; - -import com.jogamp.opengl.util.Animator; -import javax.media.opengl.awt.GLCanvas; -import com.jogamp.newt.event.awt.AWTKeyAdapter; -import com.jogamp.newt.event.awt.AWTWindowAdapter; -import com.jogamp.newt.event.TraceKeyAdapter; -import com.jogamp.newt.event.TraceWindowAdapter; - -import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; -import com.jogamp.opengl.test.junit.util.UITestCase; -import com.jogamp.opengl.test.junit.util.QuitAdapter; - import java.awt.BorderLayout; import java.awt.Button; import java.awt.Dimension; @@ -56,17 +43,37 @@ import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import javax.print.StreamPrintService; +import javax.print.StreamPrintServiceFactory; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.MediaSizeName; + +import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.AfterClass; -import org.junit.Test; import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runners.MethodSorters; +import com.jogamp.newt.event.TraceKeyAdapter; +import com.jogamp.newt.event.TraceWindowAdapter; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { static GLProfile glp; @@ -137,44 +144,57 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { */ Graphics2D g2d = (Graphics2D)g; - final int xScaleComp = (int) Math.round(printDPI/72.0); - final int yScaleComp = (int) Math.round(printDPI/72.0); + final int scaleComp; + { + final int xScaleComp = (int) Math.round(printDPI/72.0); + final int yScaleComp = (int) Math.round(printDPI/72.0); + scaleComp = Math.min(xScaleComp, yScaleComp); + } + final double scale; + { + final double xScale = 72.0/printDPI; + final double yScale = 72.0/printDPI; + scale = Math.min(xScale, yScale); + } - System.err.println("DPI: "+printDPI+", scaleComp "+xScaleComp+"/"+xScaleComp); - glCanvas.setupPrint(xScaleComp, yScaleComp); + System.err.println("DPI: "+printDPI+", scaleComp "+scaleComp); + glCanvas.setupPrint(); final int frameWidth = frame.getWidth(); final int frameHeight= frame.getHeight(); - if( xScaleComp != 1 || yScaleComp != 1 ) { - final double xScale = 72.0/printDPI; - final double yScale = 72.0/printDPI; - - final int frameWidthS = frameWidth*xScaleComp; - final int frameHeightS = frameHeight*yScaleComp; + final double moveX, moveY; + + if( scaleComp != 1 ) { + final int frameWidthS = frameWidth*(scaleComp-1); + final int frameHeightS = frameHeight*(scaleComp-1); - double xMargin = (pf.getImageableWidth() - frameWidthS*xScale)/2; - double yMargin = (pf.getImageableHeight() - frameHeightS*yScale)/2; - final double moveX, moveY; + double xMargin = (pf.getImageableWidth() - frameWidthS*scale)/2; + double yMargin = (pf.getImageableHeight() - frameHeightS*scale)/2; moveX = pf.getImageableX() + xMargin; moveY = pf.getImageableY() + yMargin; - System.err.println("DPI: "+printDPI+", scale "+xScale+"/"+yScale+", margin "+xMargin+"/"+yMargin+", move "+moveX+"/"+moveY+ + System.err.println("DPI: "+printDPI+", scale "+scale+", margin "+xMargin+"/"+yMargin+", move "+moveX+"/"+moveY+ ", frame: "+frameWidth+"x"+frameHeight+" -> "+frameWidthS+"x"+frameHeightS); - frame.setSize(frameWidthS, frameHeightS); - g2d.translate(moveX, moveY); - g2d.scale(xScale , yScale ); + frame.setSize(frameWidthS, frameHeightS); } else { - g2d.translate(pf.getImageableX(), pf.getImageableY()); + moveX = pf.getImageableX(); + moveY = pf.getImageableY(); + System.err.println("DPI: "+printDPI+", scale "+scale+", move "+moveX+"/"+moveY+ + ", frame: "+frameWidth+"x"+frameHeight); + } + g2d.translate(moveX, moveY); + if( scaleComp != 1 ) { + g2d.scale(scale , scale ); } frame.printAll(g); + glCanvas.releasePrint(); - if( xScaleComp != 1 || yScaleComp != 1 ) { + if( scaleComp != 1 ) { System.err.println("DPI: reset frame size "+frameWidth+"x"+frameHeight); frame.setSize(frameWidth, frameHeight); } - glCanvas.releasePrint(); /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; @@ -182,7 +202,88 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { private Frame frame; private GLCanvas glCanvas; + + protected void doPrintAuto(int dpi, int pOrientation, Paper paper) { + final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); + aset.add(MediaSizeName.ISO_A1); // 594 × 841 mm + aset.add(MediaSizeName.ISO_A2); // 420 × 594 mm + aset.add(MediaSizeName.ISO_A3); // 297 × 420 mm + aset.add(MediaSizeName.ISO_A4); // 210 × 297 mm + + printCount++; + final int maxSimpleTestNameLen = getMaxTestNameLen()+getClass().getSimpleName().length()+1; + final String simpleTestName = getSimpleTestName("."); + + final String psMimeType = "application/postscript"; + final String pdfMimeType = "application/pdf"; + final PrinterJob pj = PrinterJob.getPrinterJob(); + StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(pdfMimeType); + if (factories.length > 0) { + final String fname = String.format("%-"+maxSimpleTestNameLen+"s-n%04d-dpi%03d.%s", simpleTestName, printCount, dpi, "pdf"); + System.err.println("doPrint: dpi "+dpi+", "+fname); + FileOutputStream outstream; + try { + outstream = new FileOutputStream(fname); + Assert.assertTrue(doPrintAutoImpl(pj, factories[0].getPrintService(outstream), dpi, pOrientation, paper)); + } catch (FileNotFoundException e) { + Assert.assertNull("Unexpected exception", e); + } + return; + } + System.err.println("No PDF"); + + factories = PrinterJob.lookupStreamPrintServices(psMimeType); + if (factories.length > 0) { + final String fname = String.format("%-"+maxSimpleTestNameLen+"s-n%04d-dpi%03d.%s", simpleTestName, printCount, dpi, "ps"); + System.err.println("doPrint: dpi "+dpi+", "+fname); + FileOutputStream outstream; + try { + outstream = new FileOutputStream(fname); + Assert.assertTrue(doPrintAutoImpl(pj, factories[0].getPrintService(outstream), dpi, pOrientation, paper)); + } catch (FileNotFoundException e) { + Assert.assertNull("Unexpected exception", e); + } + } + System.err.println("No PS"); + } + private int printCount = 0; + private boolean doPrintAutoImpl(PrinterJob job, StreamPrintService ps, int dpi, int pOrientation, Paper paper) { + printDPI = dpi; + boolean ok = true; + try { + PageFormat pageFormat = job.defaultPage(); + if( null != paper ) { + /** + Paper paper = new Paper(); + paper.setSize(500,500); // Large Address Dimension + paper.setImageableArea(20, 20, 450, 420); */ + pageFormat.setPaper(paper); + } + pageFormat.setOrientation(pOrientation); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT + job.setPrintService(ps); + job.setPrintable(TestTiledPrintingGearsAWT.this, pageFormat); + job.print(); + } catch (PrinterException pe) { + pe.printStackTrace(); + ok = false; + } + return ok; + } + protected void doPrintManual(int dpi) { + printDPI = dpi; + PrinterJob job = PrinterJob.getPrinterJob(); + job.setPrintable(TestTiledPrintingGearsAWT.this); + boolean ok = job.printDialog(); + if (ok) { + try { + job.print(); + } catch (PrinterException ex) { + ex.printStackTrace(); + } + } + } + protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException { glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); @@ -196,31 +297,11 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { final ActionListener print72DPIAction = new ActionListener() { public void actionPerformed(ActionEvent e) { - PrinterJob job = PrinterJob.getPrinterJob(); - job.setPrintable(TestTiledPrintingGearsAWT.this); - boolean ok = job.printDialog(); - if (ok) { - try { - printDPI = 72; // default - job.print(); - } catch (PrinterException ex) { - ex.printStackTrace(); - } - } + doPrintAuto(72, PageFormat.PORTRAIT, null); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT } }; final ActionListener print300DPIAction = new ActionListener() { public void actionPerformed(ActionEvent e) { - PrinterJob job = PrinterJob.getPrinterJob(); - job.setPrintable(TestTiledPrintingGearsAWT.this); - boolean ok = job.printDialog(); - if (ok) { - try { - printDPI = 300; - job.print(); - } catch (PrinterException ex) { - ex.printStackTrace(); - } - } + doPrintAuto(300, PageFormat.PORTRAIT, null); } }; final Button print72DPIButton = new Button("72dpi"); print72DPIButton.addActionListener(print72DPIAction); @@ -251,8 +332,17 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { animator.setUpdateFPSFrames(60, System.err); animator.start(); + boolean dpi72Done = false; + boolean dpi300Done = false; while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.getTotalFPSDuration()<duration )) { Thread.sleep(100); + if( !dpi72Done ) { + dpi72Done = true; + doPrintAuto(72, PageFormat.PORTRAIT, null); + } else if( !dpi300Done ) { + dpi300Done = true; + doPrintAuto(300, PageFormat.PORTRAIT, null); + } } Assert.assertNotNull(frame); |