Class GraphicsUtils
- java.lang.Object
-
- de.erichseifert.vectorgraphics2d.util.GraphicsUtils
-
public abstract class GraphicsUtils extends java.lang.Object
Abstract class that contains utility functions for working with graphics. For example, this includes font handling.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
GraphicsUtils.FontExpressivenessComparator
-
Field Summary
Fields Modifier and Type Field Description private static GraphicsUtils.FontExpressivenessComparator
FONT_EXPRESSIVENESS_COMPARATOR
private static java.awt.font.FontRenderContext
FONT_RENDER_CONTEXT
private static java.lang.String
FONT_TEST_STRING
-
Constructor Summary
Constructors Constructor Description GraphicsUtils()
Default constructor that prevents creation of class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.Shape
clone(java.awt.Shape shape)
static boolean
equals(java.awt.Shape shapeA, java.awt.Shape shapeB)
static java.awt.image.BufferedImage
getAlphaImage(java.awt.image.BufferedImage image)
static java.awt.Font
getPhysicalFont(java.awt.Font logicalFont)
static java.awt.Font
getPhysicalFont(java.awt.Font logicalFont, java.lang.String testText)
Try to guess physical font from the properties of a logical font, like "Dialog", "Serif", "Monospaced" etc.static boolean
hasAlpha(java.awt.Image image)
This method returnstrue
if the specified image has the possibility to store transparent pixels.private static boolean
isLogicalFontFamily(java.lang.String family)
static java.awt.image.BufferedImage
toBufferedImage(java.awt.Image image)
This method returns a buffered image with the contents of an image.static java.awt.image.BufferedImage
toBufferedImage(java.awt.image.RenderedImage image)
Converts a rendered image instance to aBufferedImage
.static boolean
usesAlpha(java.awt.Image image)
This method returnstrue
if the specified image has at least one pixel that is not fully opaque.
-
-
-
Field Detail
-
FONT_RENDER_CONTEXT
private static final java.awt.font.FontRenderContext FONT_RENDER_CONTEXT
-
FONT_TEST_STRING
private static final java.lang.String FONT_TEST_STRING
- See Also:
- Constant Field Values
-
FONT_EXPRESSIVENESS_COMPARATOR
private static final GraphicsUtils.FontExpressivenessComparator FONT_EXPRESSIVENESS_COMPARATOR
-
-
Method Detail
-
hasAlpha
public static boolean hasAlpha(java.awt.Image image)
This method returnstrue
if the specified image has the possibility to store transparent pixels. Inspired by http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html- Parameters:
image
- Image that should be checked for alpha channel.- Returns:
true
if the specified image can have transparent pixels,false
otherwise
-
usesAlpha
public static boolean usesAlpha(java.awt.Image image)
This method returnstrue
if the specified image has at least one pixel that is not fully opaque.- Parameters:
image
- Image that should be checked for non-opaque pixels.- Returns:
true
if the specified image has transparent pixels,false
otherwise
-
toBufferedImage
public static java.awt.image.BufferedImage toBufferedImage(java.awt.image.RenderedImage image)
Converts a rendered image instance to aBufferedImage
.- Parameters:
image
- Rendered image that should be converted.- Returns:
- a buffered image containing the image pixels, or the original
instance if the image already was of type
BufferedImage
.
-
toBufferedImage
public static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image)
This method returns a buffered image with the contents of an image. Taken from http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html- Parameters:
image
- Image to be converted- Returns:
- a buffered image with the contents of the specified image
-
clone
public static java.awt.Shape clone(java.awt.Shape shape)
-
isLogicalFontFamily
private static boolean isLogicalFontFamily(java.lang.String family)
-
getPhysicalFont
public static java.awt.Font getPhysicalFont(java.awt.Font logicalFont, java.lang.String testText)
Try to guess physical font from the properties of a logical font, like "Dialog", "Serif", "Monospaced" etc.- Parameters:
logicalFont
- Logical font object.testText
- Text used to determine font properties.- Returns:
- An object of the first matching physical font. The original font object is returned if it was a physical font or no font matched.
-
getPhysicalFont
public static java.awt.Font getPhysicalFont(java.awt.Font logicalFont)
-
getAlphaImage
public static java.awt.image.BufferedImage getAlphaImage(java.awt.image.BufferedImage image)
-
equals
public static boolean equals(java.awt.Shape shapeA, java.awt.Shape shapeB)
-
-