Java 2D Enhancements in the Java SE 6.0

Major Features:
Fixed Bugs
Known Bugs and Issues

Major Features

Text rendering

  • Font enhancements
    The following constants of the java.awt.Font class were introduced for canonical family names of the logical fonts:
    • DIALOG
    • DIALOG_INPUT
    • SANS_SERIF
    • SERIF
    • MONOSPACED
    Use the getFontRenderContext() method added to the FontMetrics class to create a FontRenderContext object according to the current hints and to measure text through the application.
    Java SE 6 introduced the new registerFont(Font font) method of the GraphicsEnvironment class that enables you to register a font created by using the Font.createFont(int, java.io.InputStream) method, or derived from a created font by using the Font.deriveFont(int, float) method. If registration is successful, the registerFont method returns true. The false value 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 this GraphicsEnvironment object.
    A new constructor of the java.awt.font.FontRenderContext class was introduced to create a FontRenderContext 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 the FontRenderContext 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 the FontRenderContext object.
    • getFractionalMetricsHint() — To obtain the text fractional metrics rendering mode hint that can be applied to the FontRenderContext object.
    • getPixelBounds() — To get the pixel bounds of a TextLayout object. This method returns a Rectangle 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 the Graphics 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 the RenderingHints 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 the getOutline(AffineTransform) method of the TextLayout class from earlier versions of JDK, the new getOutline method of the GraphicAttribute class enables you to get a Shape object representing the region that the GraphicAttribute object renders. The getOutline method of the ShapeGraphicAttribute class overrides its counterpart method in the GraphicsAttribute class to get the outline for the region that the ShapeGraphicAttribute object renders.

  • Layout path.
    The new LayoutPath class provides mapping between Point2D 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. The getLayoutPath() method was added to the TextLayout class to obtain the layout path of the TextLayout object.

  • Text attributes
    New attributes were introduced in the TextAttribute class to enhance font visualization. The KERNING attribute enables you to request the integer kerning value to make the visual appearance of characters more pleasing. The KERNING_ON constant requests that the text be rendered such that spacing between glyphs is adjusted according to kerning pairs specified by fonts. Using the constant LIGATURES_ON value of the LIGATURES attribute requests that optional ligatures specified by the font should be applied. The TRACKING attribute is used to control how closely or loosely the glyphs are spaced. For example, the TRACKING_LOOSE constant allocates and distributes extra space between each glyph.

Imaging

  • A new method in the BufferStrategy class
    The dispose() method was added to the java.awt.image.BufferStrategy class to improve system resources management. The new method releases system resources consumed by the BufferStrategy object. Additionally, the method removes this BufferStrategy object from the associated Component instance.

Geometry

  • Easy compositing
    The following methods were added to the AlphaComposite class to obtain an AlphaComposite object that uses the specified compositing rule or the alpha value:

    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
    The LinearGradientPaint and RadialGradientPaint classes that extend the MultipleGradientPaint class fill a Shape object with the particular color gradient pattern. The MultipleGradientPaint.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 the AffineTransform 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

    The setToQuadrantRotation(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 the AffineTransform class improves inverse transformation capabilities. While the createInverse method appeared in Java SE 1.2 and transformed a shape's coordinates back to their original locations, the new invert() 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 the GeneralPath class. The Path2D class represents a path that can be iterated by the PathIterator interface and has two subclasses: Path2D.Float and Path2D.Double. In the changed hierarchy, the GeneralPath class became a subclass of the Path2D.Float class. They both can be used for single point precision, while the Path2D.Double class can be applied for double point precision. One reason to use the Path2D.Float class over the GeneralPath class is to make your code more consistence and explicit if both single and double precision types are employed in the application.

  • New hashCode() and equals() methods in shape classes
    Since JDK 1.2, the Rectangle2D class has contained the hashCode() and equals() methods, while the other subclasses of the RectangularShape class lacked the same functionality. JDK 6.0 fills this gap by adding the hashCode() and equals() method to the Arc2D, Ellipse2D, and RoundRectangle2D classes.

 

Printing

  • Enhancement in the PrinterJob class
    The getPageFormat 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 a PageFormat object.

Fixed Bugs

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 a ColorConvertOp instance are the same:

If the source and destination ColorSpace objects supplied to a ColorConvertOp 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 PrintService object without a name crashes the JVM:

If a PrintService object was set without a name (the getName() methods return null) then the JVM crashed. The problem was caused by the specific user's implementation: the PrintService interface had the getName() function that returned null and this null value was passed to the native function setNativePrintService.

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.

6320281Type1 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.

Known Bugs and Issues

6343853

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.

 


Oracle and/or its affiliatesCopyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved.