![]() | Documentation Contents |
Java 2D Enhancements in the Java™ SE 6.0 |
Text rendering
- Font enhancements
The following constants of the java.awt.Fontclass were introduced for canonical family names of the logical fonts:Use the
DIALOGDIALOG_INPUTSANS_SERIFSERIFMONOSPACEDgetFontRenderContext()method added to theFontMetricsclass to create aFontRenderContextobject according to the current hints and to measure text through the application.
Java SE 6 introduced the newregisterFont(Font font)method of theGraphicsEnvironmentclass 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, theregisterFontmethod returnstrue. The falsevaluereturned 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 thisGraphicsEnvironmentobject.
A new constructor of thejava.awt.font.FontRenderContextclass was introduced to create aFontRenderContextobject 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 theFontRenderContextobject 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 theFontRenderContextobject.getFractionalMetricsHint()— To obtain the text fractional metrics rendering mode hint that can be applied to theFontRenderContextobject.getPixelBounds()— To get the pixel bounds of aTextLayoutobject. This method returns aRectangleobject 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 theGraphicsobject. 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 theRenderingHintsclass.
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 theTextLayoutclass from earlier versions of JDK, the newgetOutlinemethod of theGraphicAttributeclass enables you to get aShapeobject representing the region that theGraphicAttributeobject renders. ThegetOutlinemethod of theShapeGraphicAttributeclass overrides its counterpart method in theGraphicsAttributeclass to get the outline for the region that theShapeGraphicAttributeobject renders.
- Layout path.
The newLayoutPathclass provides mapping betweenPoint2Dlocations 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 theTextLayoutclass to obtain the layout path of theTextLayoutobject.
- Text attributes
New attributes were introduced in theTextAttributeclass to enhance font visualization. TheKERNINGattribute enables you to request the integer kerning value to make the visual appearance of characters more pleasing. TheKERNING_ONconstant requests that the text be rendered such that spacing between glyphs is adjusted according to kerning pairs specified by fonts. Using the constantLIGATURES_ONvalue of theLIGATURESattribute requests that optional ligatures specified by the font should be applied. TheTRACKINGattribute is used to control how closely or loosely the glyphs are spaced. For example, theTRACKING_LOOSEconstant allocates and distributes extra space between each glyph.Imaging
- A new method in the
BufferStrategyclass
Thedispose()method was added to thejava.awt.image.BufferStrategyclass to improve system resources management. The new method releases system resources consumed by theBufferStrategyobject. Additionally, the method removes thisBufferStrategyobject from the associatedComponentinstance.Geometry
- Easy compositing
The following methods were added to theAlphaCompositeclass to obtain anAlphaCompositeobject that uses the specified compositing rule or thealphavalue:
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
getInstancemethod.Composite alpha0 = null, alpha1 = null; alpha0 = AlphaComposite.SrcOver.derive(alpha); alpha1 = AlphaComposite.SrcOver.derive(1-alpha)- Gradient painting capabilities
TheLinearGradientPaintandRadialGradientPaintclasses that extend theMultipleGradientPaintclass fill aShapeobject with the particular color gradient pattern. TheMultipleGradientPaint.CycleMethodenum 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 theAffineTransformclass 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 theAffineTransformclass improves inverse transformation capabilities. While thecreateInversemethod 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
GeneralPathclass
For a long time the Java 2D API lacked a double version of theGeneralPathclass. ThePath2Dclass represents a path that can be iterated by thePathIteratorinterface and has two subclasses:Path2D.FloatandPath2D.Double. In the changed hierarchy, theGeneralPathclass became a subclass of thePath2D.Floatclass. They both can be used for single point precision, while thePath2D.Doubleclass can be applied for double point precision. One reason to use thePath2D.Floatclass over theGeneralPathclass 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, theRectangle2Dclass has contained thehashCode()andequals()methods, while the other subclasses of theRectangularShapeclass lacked the same functionality. JDK 6.0 fills this gap by adding thehashCode()andequals()method to theArc2D,Ellipse2D, andRoundRectangle2Dclasses.
Printing
- Enhancement in the
PrinterJobclass
ThegetPageFormatmethod was added to the JDK 6.0 as a convenience method to more easily convert from a description of a page using attributes to aPageFormatobject.
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
ColorSpacesupplied to aColorConvertOpinstance are the same:If the source and destination
ColorSpaceobjects supplied to aColorConvertOpinstance 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 aPrintServiceobject without a name crashes the JVM:PrintServiceobject was set without a name (thegetName()methods returnnull) then the JVM crashed. The problem was caused by the specific user's implementation: thePrintServiceinterface had thegetName()function that returned null and this null value was passed to the native functionsetNativePrintService.6444688 Printing
IndexColorModelimages 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
Type1hinting 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 |