diff options
author | Sven Gothel <[email protected]> | 2013-09-06 16:44:27 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-09-06 16:44:27 +0200 |
commit | de538efc92346cada023a6045d8aec3cbdd47e08 (patch) | |
tree | b5390977785309bd2328d47b673cb351951d1b25 /src | |
parent | 44346b334ab47838f6a770a02f02036aa640f18c (diff) |
GLCanvas Printing WIP: Perform all print* operations on AWT-EDT, clip before drawing image and show same; Test: Add offscreen print and add borders.
Diffstat (limited to 'src')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/awt/GLCanvas.java | 331 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java | 102 |
2 files changed, 260 insertions, 173 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index aa2936907..02e6e8121 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -55,6 +55,7 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.Rectangle; import java.awt.RenderingHints; +import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; @@ -495,7 +496,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } return; // not yet available .. } - if( isVisible() ) { + if( isVisible() && !printActive ) { Threading.invoke(true, displayOnEDTAction, getTreeLock()); } } @@ -633,7 +634,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } private boolean validateGLDrawable() { - if( Beans.isDesignTime() || !isDisplayable() || printActive ) { + if( Beans.isDesignTime() || !isDisplayable() ) { return false; // early out! } final GLDrawable _drawable = drawable; @@ -745,129 +746,160 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing private Graphics2D printGraphics = null; public void setupPrint() { + if( !validateGLDrawable() ) { + if(DEBUG) { + System.err.println(getThreadName()+": Info: GLCanvas setupPrint - skipped GL render, drawable not valid yet"); + } + return; // not yet available .. + } + if( !isVisible() ) { + if(DEBUG) { + System.err.println(getThreadName()+": Info: GLCanvas setupPrint - skipped GL render, drawable visible"); + } + return; // not yet available .. + } printActive = true; sendReshape = false; // clear reshape flag - printAnimator = helper.getAnimator(); - if( null != printAnimator ) { - printAnimator.remove(this); - } - 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 GLEventListener preTileGLEL = new GLEventListener() { - @Override - public void init(GLAutoDrawable drawable) { + AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, setupPrintOnEDT); + } + private final Runnable setupPrintOnEDT = new Runnable() { + @Override + public void run() { + sendReshape = false; // clear reshape flag + printAnimator = helper.getAnimator(); + if( null != printAnimator ) { + printAnimator.remove(GLCanvas.this); } - @Override - public void dispose(GLAutoDrawable drawable) {} - @Override - public void display(GLAutoDrawable drawable) { - final GL gl = drawable.getGL(); - 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()); + 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(GLCanvas.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 GLEventListener preTileGLEL = new GLEventListener() { + @Override + public void init(GLAutoDrawable drawable) { } - System.err.println("XXX tile-pre "+printRenderer); // FIXME - } - @Override - 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) {} - @Override - public void display(GLAutoDrawable drawable) { - // Copy temporary data into raster of BufferedImage for faster - // 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 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 = printBuffer.width; - int srcPos = 0; - int destPos = (tHeight - 1) * printBuffer.width; - for (; destPos >= 0; srcPos += incr, destPos -= incr) { - System.arraycopy(src, srcPos, dst, destPos, incr); + @Override + public void dispose(GLAutoDrawable drawable) {} + @Override + public void display(GLAutoDrawable drawable) { + final GL gl = drawable.getGL(); + 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 } - // Draw resulting image in one shot - 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; + @Override + 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; } - 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.setup "+printRenderer); // FIXME - System.err.println("AWT print.setup "+printGLAD); // FIXME - } + @Override + public void dispose(GLAutoDrawable drawable) {} + @Override + public void display(GLAutoDrawable drawable) { + // Copy temporary data into raster of BufferedImage for faster + // 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 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 = printBuffer.width; + int srcPos = 0; + int destPos = (tHeight - 1) * printBuffer.width; + for (; destPos >= 0; srcPos += incr, destPos -= incr) { + System.arraycopy(src, srcPos, dst, destPos, incr); + } + // Draw resulting image in one shot + final int tRows = printRenderer.getParam(TileRenderer.TR_ROWS); + final int tRow = printRenderer.getParam(TileRenderer.TR_CURRENT_ROW); + final int pX = printRenderer.getParam(TileRendererBase.TR_CURRENT_TILE_X_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; + } + final Shape oClip = printGraphics.getClip(); + printGraphics.clipRect(pX, pYf, tWidth, tHeight); + final Shape clip = printGraphics.getClip(); + 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); + { + final Rectangle r = oClip.getBounds(); + printGraphics.setColor(Color.YELLOW); + printGraphics.drawRect(r.x, r.y, r.width, r.height); + } + printGraphics.setClip(oClip); + System.err.println("XXX tile-post.X clip "+oClip+" -> "+clip); + System.err.println("XXX tile-post.X "+printRenderer); + System.err.println("XXX tile-post.X 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.setup "+printRenderer); // FIXME + } + }; public void releasePrint() { 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; - printAnimator = null; - if( null != printBuffer ) { - printBuffer.dispose(); - printBuffer = null; - } - if( null != printVFlipImage ) { - printVFlipImage.flush(); - printVFlipImage = null; - } - printGraphics = null; - System.err.println("AWT print.release "+printRenderer); // FIXME - System.err.println("AWT print.release "+this); // FIXME - printActive = false; + AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, releasePrintOnEDT); } + private final Runnable releasePrintOnEDT = new Runnable() { + @Override + public void run() { + printRenderer.detachFromAutoDrawable(); // tile-renderer -> printGLAD + createDrawableAndContext( false ); + GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, GLCanvas.this); + printGLAD.destroy(); + if( null != printAnimator ) { + printAnimator.add(GLCanvas.this); + } + System.err.println("AWT print.release "+printRenderer); // FIXME + printGLAD = null; + printRenderer = null; + printAnimator = null; + if( null != printBuffer ) { + printBuffer.dispose(); + printBuffer = null; + } + if( null != printVFlipImage ) { + printVFlipImage.flush(); + printVFlipImage = null; + } + printGraphics = null; + printActive = false; + } + }; @Override public void print(Graphics graphics) { @@ -875,43 +907,48 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing 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()); + AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, printOnEDT); + } + private final Runnable printOnEDT = new Runnable() { + @Override + public void run() { + sendReshape = false; // clear reshape flag + 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 = printGraphics.getClipBounds(); + final Rectangle gClip = new Rectangle(gClipOrig); + if( 0 > gClip.x ) { + gClip.width += gClip.x; + gClip.x = 0; + } + if( 0 > gClip.y ) { + gClip.height += gClip.y; + gClip.y = 0; + } + 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); } - // 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( 0 > gClip.y ) { - gClip.height += gClip.y; - gClip.y = 0; - } - 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 public void addGLEventListener(GLEventListener listener) { 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 85ea0a3df..71b4a958b 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 @@ -34,9 +34,11 @@ import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Label; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Paper; import java.awt.print.Printable; @@ -104,6 +106,8 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { final double a0WidthInch = a0WidthMM / mmPerInch; final double a0HeightInch = a0WidthMM / mmPerInch; + /** Helper to pass desired on- and offscreen mode ! **/ + boolean printOffscreen = false; /** Helper to pass desired DPI value ! **/ int printDPI = 72; @@ -142,7 +146,6 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { * User (0,0) is typically outside the imageable area, so we must * translate by the X and Y values in the PageFormat to avoid clipping */ - Graphics2D g2d = (Graphics2D)g; final int scaleComp; { @@ -157,7 +160,8 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { scale = Math.min(xScale, yScale); } - System.err.println("DPI: "+printDPI+", scaleComp "+scaleComp); + System.err.println("PRINT offscreen: "+printOffscreen); + System.err.println("PRINT DPI: "+printDPI+", scaleComp "+scaleComp); glCanvas.setupPrint(); final int frameWidth = frame.getWidth(); @@ -173,28 +177,56 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { double yMargin = (pf.getImageableHeight() - frameHeightS*scale)/2; moveX = pf.getImageableX() + xMargin; moveY = pf.getImageableY() + yMargin; - System.err.println("DPI: "+printDPI+", scale "+scale+", margin "+xMargin+"/"+yMargin+", move "+moveX+"/"+moveY+ + System.err.println("PRINT DPI: "+printDPI+", scale "+scale+", margin "+xMargin+"/"+yMargin+", move "+moveX+"/"+moveY+ ", frame: "+frameWidth+"x"+frameHeight+" -> "+frameWidthS+"x"+frameHeightS); frame.setSize(frameWidthS, frameHeightS); } else { moveX = pf.getImageableX(); moveY = pf.getImageableY(); - System.err.println("DPI: "+printDPI+", scale "+scale+", move "+moveX+"/"+moveY+ + System.err.println("PRINT DPI: "+printDPI+", scale "+scale+", move "+moveX+"/"+moveY+ ", frame: "+frameWidth+"x"+frameHeight); } - g2d.translate(moveX, moveY); - if( scaleComp != 1 ) { - g2d.scale(scale , scale ); + + final Graphics2D printG2D = (Graphics2D)g; + + final Graphics2D offscreenG2D; + final BufferedImage offscreenImage; + if( printOffscreen ) { + final int w = frame.getWidth(); + final int h = frame.getHeight(); + offscreenImage = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); + offscreenG2D = (Graphics2D) offscreenImage.getGraphics(); + offscreenG2D.setClip(0, 0, w, h); + } else { + offscreenG2D = null; + offscreenImage = null; + } + + final Graphics2D g2d = null != offscreenG2D ? offscreenG2D : printG2D; + + if( g2d != offscreenG2D ) { + g2d.translate(moveX, moveY); + if( scaleComp != 1 ) { + g2d.scale(scale , scale ); + } } - frame.printAll(g); + frame.printAll(g2d); glCanvas.releasePrint(); if( scaleComp != 1 ) { - System.err.println("DPI: reset frame size "+frameWidth+"x"+frameHeight); + System.err.println("PRINT DPI: reset frame size "+frameWidth+"x"+frameHeight); frame.setSize(frameWidth, frameHeight); } + + if( g2d == offscreenG2D ) { + printG2D.translate(moveX, moveY); + if( scaleComp != 1 ) { + printG2D.scale(scale , scale ); + } + printG2D.drawImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), null); // Null ImageObserver since image data is ready. + } /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; @@ -202,8 +234,9 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { private Frame frame; private GLCanvas glCanvas; - - protected void doPrintAuto(int dpi, int pOrientation, Paper paper) { + + private int printCount = 0; + protected void doPrintAuto(int pOrientation, Paper paper, boolean offscreen, int dpi) { final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A1); // 594 × 841 mm aset.add(MediaSizeName.ISO_A2); // 420 × 594 mm @@ -211,8 +244,6 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { 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"; @@ -220,12 +251,12 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { 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"); + final String fname = getPrintFilename(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)); + Assert.assertTrue(doPrintAutoImpl(pj, factories[0].getPrintService(outstream), pOrientation, paper, offscreen, dpi)); } catch (FileNotFoundException e) { Assert.assertNull("Unexpected exception", e); } @@ -235,20 +266,25 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { factories = PrinterJob.lookupStreamPrintServices(psMimeType); if (factories.length > 0) { - final String fname = String.format("%-"+maxSimpleTestNameLen+"s-n%04d-dpi%03d.%s", simpleTestName, printCount, dpi, "ps"); + final String fname = getPrintFilename(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)); + Assert.assertTrue(doPrintAutoImpl(pj, factories[0].getPrintService(outstream), pOrientation, paper, offscreen, dpi)); } 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) { + private String getPrintFilename(int dpi, String suffix) { + final int maxSimpleTestNameLen = getMaxTestNameLen()+getClass().getSimpleName().length()+1; + final String simpleTestName = getSimpleTestName("."); + return String.format("%-"+maxSimpleTestNameLen+"s-n%04d-dpi%03d.%s", simpleTestName, printCount, dpi, suffix).replace(' ', '_'); + } + private boolean doPrintAutoImpl(PrinterJob job, StreamPrintService ps, int pOrientation, Paper paper, boolean offscreen, int dpi) { + printOffscreen = offscreen; printDPI = dpi; boolean ok = true; try { @@ -284,7 +320,7 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { } } - protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException { + protected void runTestGL(GLCapabilities caps, boolean offscreenPrinting) throws InterruptedException, InvocationTargetException { glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); Dimension glc_sz = new Dimension(width, height); @@ -297,11 +333,11 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { final ActionListener print72DPIAction = new ActionListener() { public void actionPerformed(ActionEvent e) { - doPrintAuto(72, PageFormat.PORTRAIT, null); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT + doPrintManual(72); } }; final ActionListener print300DPIAction = new ActionListener() { public void actionPerformed(ActionEvent e) { - doPrintAuto(300, PageFormat.PORTRAIT, null); + doPrintManual(300); } }; final Button print72DPIButton = new Button("72dpi"); print72DPIButton.addActionListener(print72DPIAction); @@ -314,8 +350,17 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { Panel printPanel = new Panel(); printPanel.add(print72DPIButton); printPanel.add(print300DPIButton); + Panel southPanel = new Panel(); + southPanel.add(new Label("South")); + Panel eastPanel = new Panel(); + eastPanel.add(new Label("East")); + Panel westPanel = new Panel(); + westPanel.add(new Label("West")); frame.add(printPanel, BorderLayout.NORTH); frame.add(glCanvas, BorderLayout.CENTER); + frame.add(southPanel, BorderLayout.SOUTH); + frame.add(eastPanel, BorderLayout.EAST); + frame.add(westPanel, BorderLayout.WEST); frame.setTitle("Tiles AWT Print Test"); Animator animator = new Animator(glCanvas); @@ -338,10 +383,10 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { Thread.sleep(100); if( !dpi72Done ) { dpi72Done = true; - doPrintAuto(72, PageFormat.PORTRAIT, null); + doPrintAuto(PageFormat.LANDSCAPE, null, offscreenPrinting, 72); } else if( !dpi300Done ) { dpi300Done = true; - doPrintAuto(300, PageFormat.PORTRAIT, null); + doPrintAuto(PageFormat.LANDSCAPE, null, offscreenPrinting, 300); } } @@ -367,9 +412,14 @@ public class TestTiledPrintingGearsAWT extends UITestCase implements Printable { } @Test - public void test01() throws InterruptedException, InvocationTargetException { + public void test01_Onscreen() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps, false); + } + @Test + public void test02_Offscreen() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); - runTestGL(caps); + runTestGL(caps, true); } static long duration = 500; // ms |