Documentation Contents |
Java 2D Enhancements in the Java™ SE 6.0 |
Text rendering
- Font enhancements
The following constants of the java.awt.Font
class were introduced for canonical family names of the logical fonts:Use the
DIALOG
DIALOG_INPUT
SANS_SERIF
SERIF
MONOSPACED
getFontRenderContext()
method added to theFontMetrics
class to create aFontRenderContext
object according to the current hints and to measure text through the application.
Java SE 6 introduced the newregisterFont(Font font)
method of theGraphicsEnvironment
class that enables you to register a font created by using theFont.createFont(int, java.io.InputStream)
method, or derived from a created font by using theFont.deriveFont(int, float)
method. If registration is successful, theregisterFont
method returnstrue
. The falsevalue
returned by the method means that the font you are trying to register is not a created font, or conflicts with a non-registered font already registered in thisGraphicsEnvironment
object.
A new constructor of thejava.awt.font.FontRenderContext
class was introduced to create aFontRenderContext
object with a specific antialiasing rendering hint or fractional rendering hint. The following methods were added to reflect the new functionality in Java SE 6.0:
isTransformed()
— To indicate that theFontRenderContext
object measures text in a transformed render context.getTransformType()
— To get the integer type of the affine transform.getAntiAliasingHint()
— To obtain the text anti-aliasing rendering mode hint that can be applied to theFontRenderContext
object.getFractionalMetricsHint()
— To obtain the text fractional metrics rendering mode hint that can be applied to theFontRenderContext
object.getPixelBounds()
— To get the pixel bounds of aTextLayout
object. This method returns aRectangle
object defining the pixel bounds that are affected.
- New text antialiasing mode
Text antialiasing is a technique used to smooth the edges of text on a screen. The Java 2D API provides means to specify whether this technique should be used and what algorithm to use by applying a text rendering hint to theGraphics
object. New text antialiasing methods optimized for LCD displays were added. They are enabled by default on some systems and can be controlled using corresponding keys and values defined in theRenderingHints
class.
See the Displaying Antialiased Text by Using Rendering Hints and Controlling Rendering Quality sections of the Java Tutorial for more information about antialiasing.
- Enhancements in graphic attributes
Along with thegetOutline(AffineTransform)
method of theTextLayout
class from earlier versions of JDK, the newgetOutline
method of theGraphicAttribute
class enables you to get aShape
object representing the region that theGraphicAttribute
object renders. ThegetOutline
method of theShapeGraphicAttribute
class overrides its counterpart method in theGraphicsAttribute
class to get the outline for the region that theShapeGraphicAttribute
object renders.
- Layout path.
The newLayoutPath
class provides mapping betweenPoint2D
locations relative to the baseline and points in user space. Two methods of this class enable bidirectional mapping: a location to a point in the user coordinates and, conversely, a point in the user coordinates to a location. ThegetLayoutPath()
method was added to theTextLayout
class to obtain the layout path of theTextLayout
object.
- Text attributes
New attributes were introduced in theTextAttribute
class to enhance font visualization. TheKERNING
attribute enables you to request the integer kerning value to make the visual appearance of characters more pleasing. TheKERNING_ON
constant requests that the text be rendered such that spacing between glyphs is adjusted according to kerning pairs specified by fonts. Using the constantLIGATURES_ON
value of theLIGATURES
attribute requests that optional ligatures specified by the font should be applied. TheTRACKING
attribute is used to control how closely or loosely the glyphs are spaced. For example, theTRACKING_LOOSE
constant allocates and distributes extra space between each glyph.Imaging
- A new method in the
BufferStrategy
class
Thedispose()
method was added to thejava.awt.image.BufferStrategy
class to improve system resources management. The new method releases system resources consumed by theBufferStrategy
object. Additionally, the method removes thisBufferStrategy
object from the associatedComponent
instance.Geometry
- Easy compositing
The following methods were added to theAlphaComposite
class to obtain anAlphaComposite
object that uses the specified compositing rule or thealpha
value:
public AlphaComposite derive(int rule)
public AlphaComposite derive(float alpha)
The two methods enable developers to code various compositing effects and avoid more complex usage of the
getInstance
method. Composite alpha0 = null, alpha1 = null; alpha0 = AlphaComposite.SrcOver.derive(alpha); alpha1 = AlphaComposite.SrcOver.derive(1-alpha)- Gradient painting capabilities
TheLinearGradientPaint
andRadialGradientPaint
classes that extend theMultipleGradientPaint
class fill aShape
object with the particular color gradient pattern. TheMultipleGradientPaint.CycleMethod
enum is used to handle painting outside gradient bounds by disabling (CycleMethod.NO_CYCLE
), reflecting (CycleMethod.REFLECT
), or repeating (CycleMethod.REPEAT
) painting.
Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(100, 100); float[] dist = {0.0f, 0.2f, 1.0f}; Color[] colors = {Color.BLACK, Color.WHITE, Color.GRAY}; LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors, CycleMethod.REFLECT);
- Rotation around an anchor point
In addition to the existing means of rotation using an anchor point, Java SE 6.0 enables a graphic object to be rotated according to a rotation vector or around an anchor point according to a rotation vector. The following methods were introduced in theAffineTransform
class to support the new functionality:
public static AffineTransform getRotateInstance(double vecx, double vecy)
public static AffineTransform getRotateInstance(double vecx, double vecy, double anchorx, double anchory)
public static AffineTransform getQuadrantRotateInstance(int numquadrants)
public static AffineTransform getQuadrantRotateInstance(int numquadrants, double anchorx, double anchory)
public void rotate(double vecx, double vecy)
public void rotate(double vecx, double vecy, double anchorx, double anchory)
public void quadrantRotate(int numquadrants)
public void quadrantRotate(int numquadrants, double anchorx, double anchory)
public void setToRotation(double vecx, double vecy)
public void setToRotation(double vecx, double vecy, double anchorx, double anchory
ThesetToQuadrantRotation(int numquadrants)
method enables rotation by the specified number of quadrants. Its counterpart rotates coordinates by the specified number of quadrants around the specified anchor point.- Easy way to get inverted transform
A new method in theAffineTransform
class improves inverse transformation capabilities. While thecreateInverse
method appeared in Java SE 1.2 and transformed a shape's coordinates back to their original locations, the newinvert()
method enables setting the current transform to the inverse state of itself.
- Double precision for the
GeneralPath
class
For a long time the Java 2D API lacked a double version of theGeneralPath
class. ThePath2D
class represents a path that can be iterated by thePathIterator
interface and has two subclasses:Path2D.Float
andPath2D.Double
. In the changed hierarchy, theGeneralPath
class became a subclass of thePath2D.Float
class. They both can be used for single point precision, while thePath2D.Double
class can be applied for double point precision. One reason to use thePath2D.Float
class over theGeneralPath
class is to make your code more consistence and explicit if both single and double precision types are employed in the application.- New
hashCode()
andequals()
methods in shape classes
Since JDK 1.2, theRectangle2D
class has contained thehashCode()
andequals()
methods, while the other subclasses of theRectangularShape
class lacked the same functionality. JDK 6.0 fills this gap by adding thehashCode()
andequals()
method to theArc2D
,Ellipse2D
, andRoundRectangle2D
classes.
Printing
- Enhancement in the
PrinterJob
class
ThegetPageFormat
method was added to the JDK 6.0 as a convenience method to more easily convert from a description of a page using attributes to aPageFormat
object.
6182443 Rotated antialiased text is too light gray:
This bug is essentially side effect of turning off hinting for non-quadrant transforms. The problem was resolved as a part of the fix for 4654540.4151279 Visual artifacts appear while rendering ovals, arcs, and rounded rectangles:
A separate pipeline was developed for drawing cubic and quad Bezier curves, where an adaptive forward differencing was applied. This approach noticeably improves quality and speeds up Bezier curve drawing.
4924220 Microsoft Sans Serif (True Type) font is not rendered properly:
The Microsoft Sans serif font glyph looked broken due to the current implementation of scan conversion algorithms. The smart dropout mechanism is added as part of the fix for the 6282527 bug.
6300721 Creating Animated GIF images repeatedly with different image frames crashes the VM:
The VM crash appeared as a stomp over memory in the Java heap as if code had gone off the end of an array. The fix checks the dimensions in the image representation code when the first portion of image is gotten. If the dimensions do not match, the internal buffered image is recreated.
6279846 Pixel values are different when source and destination
ColorSpace
supplied to aColorConvertOp
instance are the same:If the source and destination
ColorSpace
objects supplied to aColorConvertOp
instance were the same, pixel values were different between the color converted destination and the original source. This bug is fixed by updating the sRGB profile and creating fast track (without any color transforms).4654540 Need hinting support for text rendering with scaled and flipped matrices:
Truetype hinting was designed with the assumption that the orientation of glyphs regarding pixel grids would be fixed. That is why truetype hinting did not support complex affine transforms such as rotation, or shear, and scale transforms. As a fix the following approaches are implemented:
- Decompose the original transform to bitmap transform (combination of quadrant rotation and mirror) and remainder transform
- Further decompose the remainder transform to safe hinting transform and outline the compensation transform
- Perform hinting with safe transform
- Apply compensation transform to the hinted outline
- Perform scan conversion
- Apply bitmap transform
6397684 Setting a
If aPrintService
object without a name crashes the JVM:PrintService
object was set without a name (thegetName()
methods returnnull
) then the JVM crashed. The problem was caused by the specific user's implementation: thePrintService
interface had thegetName()
function that returned null and this null value was passed to the native functionsetNativePrintService
.6444688 Printing
IndexColorModel
images with a transparent pixel may fail on Windows:Printing an image with bitmask transparency was sometimes incorrect on the Windows platform. A problem existed with the bitmask transparency case. Printing code handled the bitmask transparency as multiple smaller sub images of the original image. The fix includes the simplest and least risky solution: always creating a copy of an image.
6320281
Type1
hinting support is missed :Before JDK 6 the java font rasterizer only supported hinting for Truetype fonts. However, Type1 fonts were commonplace on Solaris and Linux platforms and they often did not look very customary without hinting. To support the type1 hints the functionality is implemented:
- hstem and vstem
- dotsection
- BlueValues and OtherBlues
- type1 hint replacements
4912220 1.4 REGRESSION: Flipping with asymmetric scaling often distorts fonts :
Truetype hinting was designed without support for arbitrary transforms. To overcome this limitation, hints are applied with a "safe" identity matrix and then with a transform hinted outline when non-trival transform is requested. The problem was resolved as a part of the fix for 4654540.
5051527 Faster, more direct software transformation of images:
The code to transform images used an image processing library to perform the operation. This approach required at least one intermediate buffer to be created for each transform operation. The new code enables you to transform any of the internally handled formats and composite to any of the internally handled formats in one operation with only a minimal stack-allocated one-line pixel buffer.
On Windows Vista, the use of DirectDraw
for
hardware acceleration is currently disabled by default because of
incompatibilities with Vista's Desktop Window Manager.
The -Dsun.java2d.noddraw=false
property can be used
to re-enable the use of the DirectDraw
pipeline.
However, this is not recommended due to rendering artifacts and
performance problems. To also enable the Direct3D
pipeline, a combination of the aforementioned flag and
-Dsun.java2d.d3d=true
should be used.
Copyright © 1993, 2010, Oracle and/or its affiliates. All rights reserved. Please send comments using this Feedback page. |
Java Technology |