You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by me...@apache.org on 2012/07/06 17:03:17 UTC
svn commit: r1358252 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/java2d/
src/java/org/apache/xmlgraphics/java2d/color/
src/java/org/apache/xmlgraphics/java2d/ps/
test/java/org/apache/xmlgraphics/java2d/
Author: mehdi
Date: Fri Jul 6 15:03:16 2012
New Revision: 1358252
URL: http://svn.apache.org/viewvc?rev=1358252&view=rev
Log:
Consolidated and tested the GraphicsConfiguration class
Added:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphicsConfiguration.java (with props)
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GenericGraphicsDevice.java (with props)
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java (with props)
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java (with props)
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparencyTestCase.java (with props)
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparencyTestCase.java (with props)
Removed:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphicsConfiguration.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphicsDevice.java
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/color/ColorConverter.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphicsConfiguration.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphicsConfiguration.java?rev=1358252&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphicsConfiguration.java (added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphicsConfiguration.java Fri Jul 6 15:03:16 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.image.VolatileImage;
+
+/**
+ * Adapter to allow subclassing java.awt.GraphicsConfiguration without
+ * compilation errors.
+ * The version for JDK 1.4 needs to add an override for the abstract
+ * createCompatibleVolatileImage() method. It can't be overidden
+ * for JDK 1.3 because there is no VolatileImage there.
+ *
+ */
+public abstract class AbstractGraphicsConfiguration extends java.awt.GraphicsConfiguration {
+
+ /**
+ * @see java.awt.GraphicsConfiguration#createCompatibleVolatileImage(int, int)
+ * @since JDK 1.4
+ */
+ public VolatileImage createCompatibleVolatileImage(int width, int height) {
+ return null;
+ }
+
+ /**
+ * @see java.awt.GraphicsConfiguration#createCompatibleVolatileImage(int, int, int)
+ * @since JDK 1.5
+ */
+ public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) {
+ return null;
+ }
+
+}
Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphicsConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GenericGraphicsDevice.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GenericGraphicsDevice.java?rev=1358252&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GenericGraphicsDevice.java (added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GenericGraphicsDevice.java Fri Jul 6 15:03:16 2012
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.GraphicsConfigTemplate;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+
+/**
+ * This implements the {@link GraphicsDevice} interface as appropriate for the various output
+ * configurations.
+ */
+public class GenericGraphicsDevice extends GraphicsDevice {
+
+ /**
+ * The Graphics Config that created us...
+ */
+ private final GraphicsConfiguration gc;
+
+ /**
+ * Create a new graphics2D device.
+ *
+ * @param The gc we should reference
+ */
+ public GenericGraphicsDevice(GraphicsConfiguration gc) {
+ this.gc = gc;
+ }
+
+ /**
+ * Ignore template and return the only config we have
+ *
+ * @param gct the template configuration
+ * @return the best configuration which is the only one
+ */
+ public GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate gct) {
+ return gc;
+ }
+
+ /**
+ * Return an array of our one GraphicsConfig
+ *
+ * @return an array containing the one graphics configuration
+ */
+ public GraphicsConfiguration[] getConfigurations() {
+ return new GraphicsConfiguration[] {gc};
+ }
+
+ /**
+ * Return out sole GraphicsConfig.
+ *
+ * @return the graphics configuration that created this object
+ */
+ public GraphicsConfiguration getDefaultConfiguration() {
+ return gc;
+ }
+
+ /**
+ * Generate an IdString..
+ *
+ * @return the ID string for this device, uses toString
+ */
+ public String getIDstring() {
+ return toString();
+ }
+
+ /**
+ * Let the caller know that we are "a printer"
+ *
+ * @return the type which is always printer
+ */
+ public int getType() {
+ return GraphicsDevice.TYPE_PRINTER;
+ }
+}
Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GenericGraphicsDevice.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java?rev=1358252&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java (added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java Fri Jul 6 15:03:16 2012
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.GraphicsDevice;
+import java.awt.Rectangle;
+import java.awt.Transparency;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+
+/**
+ * An implementation of {@link java.awt.GraphicsConfiguration} that supports transparencies (alpha
+ * channels).
+ */
+public class GraphicsConfigurationWithTransparency extends AbstractGraphicsConfiguration {
+ // We use this to get a good colormodel..
+ private static final BufferedImage BI_WITH_ALPHA =
+ new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+ // We use this to get a good colormodel..
+ private static final BufferedImage BI_WITHOUT_ALPHA =
+ new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
+
+ /**
+ * Construct a buffered image with an alpha channel, unless transparency is OPAQUE (no alpha
+ * at all).
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param transparency the alpha value of the image
+ * @return the new buffered image
+ */
+ public BufferedImage createCompatibleImage(int width, int height, int transparency) {
+ if (transparency == Transparency.OPAQUE) {
+ return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ } else {
+ return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ }
+ }
+
+ /**
+ * Construct a buffered image with an alpha channel.
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @return the new buffered image
+ */
+ public BufferedImage createCompatibleImage(int width, int height) {
+ return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ }
+
+ /**
+ * TODO: This should return the page bounds in Pts, I couldn't figure out how to get this for
+ * the current page (this still works for now, but it should be fixed...).
+ *
+ * @return the bounds of the document page
+ */
+ public Rectangle getBounds() {
+ return null;
+ }
+
+ /**
+ * Return a good default color model for this 'device'.
+ * @return the colour model for the configuration
+ */
+ public ColorModel getColorModel() {
+ return BI_WITH_ALPHA.getColorModel();
+ }
+
+ /**
+ * Return a good color model given <code>transparency</code>
+ *
+ * @param transparency the alpha value for the colour model
+ * @return the colour model for the configuration
+ */
+ public ColorModel getColorModel(int transparency) {
+ if (transparency == Transparency.OPAQUE) {
+ return BI_WITHOUT_ALPHA.getColorModel();
+ } else {
+ return BI_WITH_ALPHA.getColorModel();
+ }
+ }
+
+ /**
+ * The default transform (1:1).
+ *
+ * @return the default transform for the configuration
+ */
+ public AffineTransform getDefaultTransform() {
+ return new AffineTransform();
+ }
+
+ /**
+ * The normalizing transform (1:1) (since we currently
+ * render images at 72dpi, which we might want to change
+ * in the future).
+ *
+ * @return the normalizing transform for the configuration
+ */
+ public AffineTransform getNormalizingTransform() {
+ return new AffineTransform(2, 0, 0, 2, 0, 0);
+ }
+
+ /**
+ * Return our dummy instance of GraphicsDevice
+ *
+ * @return the graphics device
+ */
+ public GraphicsDevice getDevice() {
+ return new GenericGraphicsDevice(this);
+ }
+}
Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java?rev=1358252&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java (added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java Fri Jul 6 15:03:16 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.GraphicsDevice;
+import java.awt.Rectangle;
+import java.awt.Transparency;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * An implementation of {@link java.awt.GraphicsConfiguration} that does not support transparencies
+ * (alpha channels).
+ */
+public class GraphicsConfigurationWithoutTransparency extends AbstractGraphicsConfiguration {
+
+ private static final Log LOG = LogFactory.getLog(GraphicsConfigurationWithoutTransparency.class);
+
+ // We use this to get a good colormodel..
+ private static final BufferedImage BI_WITHOUT_ALPHA =
+ new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
+
+ private final GraphicsConfigurationWithTransparency defaultDelegate = new GraphicsConfigurationWithTransparency();
+
+ @Override
+ public GraphicsDevice getDevice() {
+ return new GenericGraphicsDevice(this);
+ }
+
+ @Override
+ public BufferedImage createCompatibleImage(int width, int height) {
+ return defaultDelegate.createCompatibleImage(width, height, Transparency.OPAQUE);
+ }
+
+ @Override
+ public BufferedImage createCompatibleImage(int width, int height, int transparency) {
+ if (transparency != Transparency.OPAQUE) {
+ LOG.warn("Does not support transparencies (alpha channels) in images");
+ }
+ return defaultDelegate.createCompatibleImage(width, height, Transparency.OPAQUE);
+ }
+
+ @Override
+ public ColorModel getColorModel() {
+ return BI_WITHOUT_ALPHA.getColorModel();
+ }
+
+ @Override
+ public ColorModel getColorModel(int transparency) {
+ if (transparency == Transparency.OPAQUE) {
+ LOG.warn("Does not support transparencies (alpha channels) in images");
+ }
+ return getColorModel();
+ }
+
+ @Override
+ public AffineTransform getDefaultTransform() {
+ return defaultDelegate.getDefaultTransform();
+ }
+
+ @Override
+ public AffineTransform getNormalizingTransform() {
+ return defaultDelegate.getNormalizingTransform();
+ }
+
+ @Override
+ public Rectangle getBounds() {
+ return null;
+ }
+}
Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/color/ColorConverter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/color/ColorConverter.java?rev=1358252&r1=1358251&r2=1358252&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/color/ColorConverter.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/color/ColorConverter.java Fri Jul 6 15:03:16 2012
@@ -28,9 +28,7 @@ public interface ColorConverter {
/**
* @param color to convert
- * @return converted color
- */
-
+ * @return converted color
+ */
Color convert(Color color);
-
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java?rev=1358252&r1=1358251&r2=1358252&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java Fri Jul 6 15:03:16 2012
@@ -46,6 +46,7 @@ import java.io.IOException;
import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.GraphicsConfigurationWithoutTransparency;
import org.apache.xmlgraphics.java2d.StrokingTextHandler;
import org.apache.xmlgraphics.java2d.TextHandler;
import org.apache.xmlgraphics.ps.PSGenerator;
@@ -822,7 +823,7 @@ public class PSGraphics2D extends Abstra
* @return the device configuration
*/
public GraphicsConfiguration getDeviceConfiguration() {
- return new PSGraphicsConfiguration();
+ return new GraphicsConfigurationWithoutTransparency();
}
/**
Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparencyTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparencyTestCase.java?rev=1358252&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparencyTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparencyTestCase.java Fri Jul 6 15:03:16 2012
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.Transparency;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test case for {@link GraphicsConfigurationWithTransparency}.
+ */
+public class GraphicsConfigurationWithTransparencyTestCase {
+
+ private ColorModel transparencyColorModel;
+ private ColorModel nonTransparencyColorModel;
+ private GraphicsConfiguration sut;
+
+ @Before
+ public void setUp() {
+ sut = new GraphicsConfigurationWithTransparency();
+ transparencyColorModel = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getColorModel();
+ nonTransparencyColorModel = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getColorModel();
+ }
+
+ @Test
+ public void testGetNormalizationTransformation() {
+ AffineTransform transform = new AffineTransform(2, 0, 0, 2, 0, 0);
+ assertEquals(transform, sut.getNormalizingTransform());
+ }
+
+ void testImage(int width, int height, boolean hasTransparency, BufferedImage image) {
+ assertEquals(width, image.getWidth());
+ assertEquals(height, image.getHeight());
+ assertEquals(hasTransparency, image.getColorModel().hasAlpha());
+ }
+
+ @Test
+ public void testCreateCompatibleImage() {
+ testImage(1, 2, true, sut.createCompatibleImage(1, 2, Transparency.TRANSLUCENT));
+ testImage(100, 90, true, sut.createCompatibleImage(100, 90, Transparency.TRANSLUCENT));
+ testImage(1, 2, false, sut.createCompatibleImage(1, 2, Transparency.OPAQUE));
+ testImage(1010, 2020, false, sut.createCompatibleImage(1010, 2020, Transparency.OPAQUE));
+
+ // test the 2 argument overriden method
+ testImage(1, 2, true, sut.createCompatibleImage(1, 2));
+ testImage(1010, 2020, true, sut.createCompatibleImage(1010, 2020));
+ }
+
+ @Test
+ public void testGetColorModel() {
+ assertEquals(transparencyColorModel, sut.getColorModel());
+
+ assertEquals(transparencyColorModel, sut.getColorModel(Transparency.TRANSLUCENT));
+ assertEquals(nonTransparencyColorModel, sut.getColorModel(Transparency.OPAQUE));
+ }
+}
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparencyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparencyTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparencyTestCase.java?rev=1358252&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparencyTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparencyTestCase.java Fri Jul 6 15:03:16 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.Transparency;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class GraphicsConfigurationWithoutTransparencyTestCase {
+
+ private ColorModel nonTransparencyColorModel;
+ private GraphicsConfiguration sut;
+
+ @Before
+ public void setUp() {
+ sut = new GraphicsConfigurationWithoutTransparency();
+ nonTransparencyColorModel = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getColorModel();
+ }
+
+ @Test
+ public void testGetNormalizationTransformation() {
+ AffineTransform transform = new AffineTransform(2, 0, 0, 2, 0, 0);
+ assertEquals(transform, sut.getNormalizingTransform());
+ }
+
+ void testImage(int width, int height, boolean hasTransparency, BufferedImage image) {
+ assertEquals(width, image.getWidth());
+ assertEquals(height, image.getHeight());
+ assertEquals(hasTransparency, image.getColorModel().hasAlpha());
+ }
+
+ @Test
+ public void testCreateCompatibleImage() {
+ testImage(1, 2, false, sut.createCompatibleImage(1, 2, Transparency.TRANSLUCENT));
+ testImage(100, 90, false, sut.createCompatibleImage(100, 90, Transparency.TRANSLUCENT));
+ testImage(1, 2, false, sut.createCompatibleImage(1, 2, Transparency.OPAQUE));
+ testImage(1010, 2020, false, sut.createCompatibleImage(1010, 2020, Transparency.OPAQUE));
+
+ // test the 2 argument overriden method
+ testImage(1, 2, false, sut.createCompatibleImage(1, 2));
+ testImage(1010, 2020, false, sut.createCompatibleImage(1010, 2020));
+ }
+
+ @Test
+ public void testGetColorModel() {
+ assertEquals(nonTransparencyColorModel, sut.getColorModel());
+
+ assertEquals(nonTransparencyColorModel, sut.getColorModel(Transparency.TRANSLUCENT));
+ assertEquals(nonTransparencyColorModel, sut.getColorModel(Transparency.OPAQUE));
+ }
+}
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparencyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org