| <test title="Color Testing"> |
| <description> |
| This test validates the convertion of Java 2D Colors |
| into SVG fill, stroke and opacity attributes. |
| </description> |
| <description> |
| The test validates that color constants (such as Color.red) |
| are converted to their equivalent SVG constants. It also |
| tests that opacity is translated properly by painting |
| half transparent shapes. |
| </description> |
| <javaCode> |
| <![CDATA[ |
| g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
| RenderingHints.VALUE_ANTIALIAS_ON); |
| |
| AffineTransform defaultTransform = g.getTransform(); |
| |
| // Colors used for labels and test output |
| Color labelColor = Color.black; |
| |
| Color colorConstants[] = { Color.black, |
| Color.blue, |
| Color.cyan, |
| Color.darkGray, |
| Color.gray, |
| Color.green, |
| Color.lightGray, |
| Color.magenta, |
| Color.orange, |
| Color.pink, |
| Color.red, |
| Color.white, |
| Color.yellow }; |
| |
| String colorConstantStrings[] = { "black", |
| "blue", |
| "cyan", |
| "darkGray", |
| "gray", |
| "green", |
| "lightGray", |
| "magenta", |
| "orange", |
| "pink", |
| "red", |
| "white", |
| "yellow" }; |
| |
| |
| g.translate(20, 20); |
| g.setPaint(labelColor); |
| g.drawString("Color Constants", -5, 0); |
| g.translate(0, 20); |
| |
| for(int i=0; i<colorConstants.length; i++){ |
| g.setPaint(labelColor); |
| g.drawString(colorConstantStrings[i], 10, 3); |
| g.setPaint(colorConstants[i]); |
| g.fillRect(-5, -5, 10, 10); |
| g.setPaint(labelColor); |
| g.drawRect(-5, -5, 10, 10); |
| g.translate(0, 20); |
| } |
| |
| g.setTransform(defaultTransform); |
| g.translate(150, 20); |
| g.setColor(labelColor); |
| g.drawString("Various opacities", 0, 0); |
| g.translate(0, 10); |
| |
| // |
| // Now, test opacities |
| // |
| int opacitySteps = 20; |
| g.setPaint(new Color(80, 255, 80)); |
| g.fillRect(0, 0, 40, 260); |
| int stepHeight = 260/opacitySteps; |
| Font defaultFont = g.getFont(); |
| Font opacityFont = new Font(defaultFont.getFamily(), |
| defaultFont.getStyle(), |
| (int)(defaultFont.getSize()*0.8)); |
| g.setFont(opacityFont); |
| |
| for(int i=0; i<opacitySteps; i++){ |
| int opacity = ((i + 1)*255)/opacitySteps; |
| Color color = new Color(0, 0, 0, opacity); |
| g.setPaint(color); |
| g.fillRect(0, 0, 40, stepHeight); |
| |
| g.setPaint(labelColor); |
| g.drawString("" + opacity, 50, stepHeight/2); |
| g.translate(0, stepHeight); |
| } |
| |
| ]]> |
| </javaCode> |
| </test> |