diff options
author | Sven Gothel <[email protected]> | 2013-09-27 13:49:59 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-09-27 13:49:59 +0200 |
commit | 469311764a1cb3c3af8439c1638160926741c1e5 (patch) | |
tree | abacead9f574b85bb51e6ef2f49af2a99418afe4 /src | |
parent | 9a8f9b9f7e6148b60b6f0f4326df8d213774284c (diff) |
Test AWT Printing: Frame size contains border/insets, use as-is for scaling; Only force TEXT AA print-rendering hint.
Diffstat (limited to 'src')
3 files changed, 22 insertions, 25 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java index 37ad8c361..bd526419c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java @@ -31,6 +31,7 @@ import java.awt.Container; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; +import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Paper; @@ -121,36 +122,34 @@ public class OffscreenPrintable extends PrintableBase implements Printable { /** * See: 'Scaling of Frame and GL content' in Class description! + * Note: Frame size contains the frame border (i.e. insets)! */ final Insets frameInsets = cont.getInsets(); final int frameWidth = cont.getWidth(); final int frameHeight= cont.getHeight(); - final int frameWidthT = frameWidth + frameInsets.left + frameInsets.right; - final int frameHeightT = frameHeight + frameInsets.top + frameInsets.bottom; final double scaleGraphics = dpi / 72.0; - final int frameSWidthT = (int) ( frameWidthT * scaleGraphics ); - final int frameSHeightT = (int) ( frameHeightT * scaleGraphics ); + final int frameSWidth = (int) ( frameWidth * scaleGraphics ); + final int frameSHeight = (int) ( frameHeight * scaleGraphics ); final double scaleComp72; { - final double sx = pf.getImageableWidth() / (double)frameSWidthT; - final double sy = pf.getImageableHeight() / (double)frameSHeightT; + final double sx = pf.getImageableWidth() / (double)frameSWidth; + final double sy = pf.getImageableHeight() / (double)frameSHeight; scaleComp72 = Math.min(sx, sy); } System.err.println("PRINT.offscrn thread "+Thread.currentThread().getName()); System.err.println("PRINT.offscrn DPI: scaleGraphics "+scaleGraphics+", scaleComp72 "+scaleComp72); System.err.println("PRINT.offscrn DPI: frame: border "+frameInsets+", size "+frameWidth+"x"+frameHeight+ - " -> total "+frameWidthT+ "x" + frameHeightT+ - " -> scaled "+frameSWidthT+ "x" + frameSHeightT); + " -> scaled "+frameSWidth+ "x" + frameSHeight); - final BufferedImage image = DirectDataBufferInt.createBufferedImage(frameSWidthT, frameSHeightT, imageType, null /* location */, null /* properties */); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frameSWidth, frameSHeight, imageType, null /* location */, null /* properties */); { System.err.println("PRINT.offscrn image "+image); final Graphics2D g2d = (Graphics2D) image.getGraphics(); - g2d.setClip(0, 0, frameSWidthT, frameSHeightT); + g2d.setClip(0, 0, frameSWidth, frameSHeight); g2d.scale(scaleGraphics, scaleGraphics); // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { cont.printAll(g2d); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java index a23f7f8c3..7e8bac295 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java @@ -120,33 +120,31 @@ public class OnscreenPrintable extends PrintableBase implements Printable { /** * See: 'Scaling of Frame and GL content' in Class description! + * Note: Frame size contains the frame border (i.e. insets)! */ final Insets frameInsets = cont.getInsets(); final int frameWidth = cont.getWidth(); final int frameHeight= cont.getHeight(); - final int frameWidthT = frameWidth + frameInsets.left + frameInsets.right; - final int frameHeightT = frameHeight + frameInsets.top + frameInsets.bottom; final double scaleGraphics = dpi / 72.0; - final int frameSWidthT = (int) ( frameWidthT * scaleGraphics ); - final int frameSHeightT = (int) ( frameHeightT * scaleGraphics ); + final int frameSWidth = (int) ( frameWidth * scaleGraphics ); + final int frameSHeight = (int) ( frameHeight * scaleGraphics ); final double scaleComp72; { - final double sx = pf.getImageableWidth() / (double)frameWidthT; - final double sy = pf.getImageableHeight() / (double)frameHeightT; + final double sx = pf.getImageableWidth() / (double)frameWidth; + final double sy = pf.getImageableHeight() / (double)frameHeight; scaleComp72 = Math.min(sx, sy); } System.err.println("PRINT.onscrn thread "+Thread.currentThread().getName()); System.err.println("PRINT.onscrn DPI: scaleGraphics "+scaleGraphics+", scaleComp72 "+scaleComp72); System.err.println("PRINT.onscrn DPI: frame: border "+frameInsets+", size "+frameWidth+"x"+frameHeight+ - " -> total "+frameWidthT+ "x" + frameHeightT+ - " -> scaled "+frameSWidthT+ "x" + frameSHeightT); + " -> scaled "+frameSWidth+ "x" + frameSHeight); final Graphics2D g2d = (Graphics2D)g; System.err.println("PRINT at.pre: "+g2d.getTransform()); g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.scale(scaleComp72, scaleComp72); // WARNING: Produces rounding artifacts due to diff scale-factor of AWT/GL comps !!! // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java index 3198212b5..0fe08ebc2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java @@ -36,6 +36,7 @@ import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Label; +import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; @@ -105,11 +106,10 @@ public class TestTiledPrintingNIOImageSwingAWT extends UITestCase { final int imageWidth = image.getWidth(); final int imageHeight= image.getHeight(); final double scaleComp72; + // Note: Frame size contains the frame border (i.e. insets)! { - final double frameBorderW = frameInsets.left + frameInsets.right; - final double frameBorderH = frameInsets.top + frameInsets.bottom; - final double sx = (double)imageWidth / ( frameWidth + frameBorderW ); - final double sy = (double)imageHeight / ( frameHeight + frameBorderH ); + final double sx = (double)imageWidth / frameWidth; + final double sy = (double)imageHeight / frameHeight; scaleComp72 = Math.min(sx, sy); } System.err.println("PRINT DPI: scaleComp72 "+scaleComp72+", image-size "+imageWidth+"x"+imageHeight+", frame[border "+frameInsets+", size "+frameWidth+"x"+frameHeight+"]"); @@ -125,7 +125,7 @@ public class TestTiledPrintingNIOImageSwingAWT extends UITestCase { g2d.setClip(0, 0, image.getWidth(), image.getHeight()); g2d.scale(scaleComp72, scaleComp72); // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // frame.paintAll(g2d); final AWTPrintLifecycle.Context ctx = AWTPrintLifecycle.Context.setupPrint(frame, 1.0/scaleComp72, 1.0/scaleComp72, 0); |