| <test title="RenderingHints Testing"> |
| <description> |
| This test validates the convertion of Java 2D RenderingHints |
| into SVG attributes. |
| </description> |
| <description> |
| The test validates that antialiasing and interpolation hints are |
| properly mapped. |
| </description> |
| <javaCode> |
| <![CDATA[ |
| RenderingHints.Key antialiasKey = RenderingHints.KEY_ANTIALIASING; |
| Object antialiasOn= RenderingHints.VALUE_ANTIALIAS_ON; |
| Object antialiasOff= RenderingHints.VALUE_ANTIALIAS_OFF; |
| RenderingHints.Key textAntialiasKey = RenderingHints.KEY_TEXT_ANTIALIASING; |
| Object textAntialiasOn = RenderingHints.VALUE_TEXT_ANTIALIAS_ON; |
| Object textAntialiasOff = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; |
| RenderingHints.Key interpolationKey = RenderingHints.KEY_INTERPOLATION; |
| Object interpolationBicubic = RenderingHints.VALUE_INTERPOLATION_BICUBIC; |
| Object interpolationNeighbor = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; |
| |
| Font defaultFont = g.getFont(); |
| AffineTransform defaultTransform = g.getTransform(); |
| Font textFont = new Font("Impact", Font.PLAIN, 25); |
| |
| // |
| // First, test text antialiasing |
| // |
| g.setPaint(Color.black); |
| g.setRenderingHint(antialiasKey, antialiasOn); |
| g.drawString("Text antialiasing", 10, 20); |
| |
| g.setRenderingHint(antialiasKey, antialiasOff); |
| g.setRenderingHint(textAntialiasKey, textAntialiasOn); |
| g.setFont(textFont); |
| g.drawString("HELLO antialiased", 30, 60); |
| g.setRenderingHint(textAntialiasKey, textAntialiasOff); |
| g.drawString("HELLO aliased", 30, 90); |
| |
| // |
| // Now, test shape antialiasing |
| // |
| g.translate(0, 100); |
| g.setRenderingHint(antialiasKey, antialiasOn); |
| g.setFont(defaultFont); |
| g.drawString("Shape antialiasing", 10, 20); |
| |
| g.translate(30, 0); |
| g.setRenderingHint(antialiasKey, antialiasOff); |
| g.setRenderingHint(textAntialiasKey, textAntialiasOff); |
| Ellipse2D ellipse = new Ellipse2D.Float(10, 30, 100, 30); |
| g.fill(ellipse); |
| g.translate(0, 40); |
| g.setRenderingHint(antialiasKey, antialiasOn); |
| g.fill(ellipse); |
| |
| g.setTransform(defaultTransform); |
| g.translate(0, 200); |
| |
| // |
| // Now, test interpolation hint |
| // |
| BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB); |
| Graphics2D ig = image.createGraphics(); |
| ig.setPaint(Color.red); |
| ig.fillRect(0, 0, 2, 2); |
| ig.setPaint(Color.yellow); |
| ig.fillRect(0, 0, 1, 1); |
| ig.fillRect(1, 1, 2, 2); |
| ig.dispose(); |
| |
| g.setRenderingHint(interpolationKey, interpolationNeighbor); |
| g.drawString("Interpolation Nearest Neighbor / Bicubic", 10, 30); |
| g.drawImage(image, 10, 50, 40, 40, null); |
| |
| g.setRenderingHint(interpolationKey, interpolationBicubic); |
| g.drawImage(image, 60, 50, 40, 40, null); |
| |
| ]]> |
| </javaCode> |
| </test> |