JDK-6186840 : GlyphVector.setGlyphPosition has no effect when printing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-10-29
  • Updated: 2010-04-02
  • Resolved: 2005-09-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u7Fixed 6 b51Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When you want to adjust glyphs positions, you must call setGlyphPosition. This statement works fine when drawing in screen but is ignored when printing.

'Graphics.DrawGlyphVector' seems to be mapped to 'drawString' when printing.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Running the executable test case.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Numbers from 0 to 9 separated by 10 millimeters aproximately.
ACTUAL -
Numbers from 0 to 9 writen without separation.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.print.*;
import javax.print.attribute.*;

public class Print implements Printable
{
    public static void main(String args[])
    {
        try
        {
            HashPrintRequestAttributeSet aSet;
            aSet = new HashPrintRequestAttributeSet();
            PrinterJob pj = PrinterJob.getPrinterJob();

            if(pj.printDialog(aSet))
            {
                pj.setPrintable(new Print());
                pj.print(aSet);
            }
        }
        catch(PrinterException ex)
        {
            ex.printStackTrace();
        }

        System.exit(0);
    }

    public int print(Graphics g, PageFormat pageFormat, int pageIndex)
        throws PrinterException
    {
        if(pageIndex > 0)
            return NO_SUCH_PAGE;

        float x = (float)pageFormat.getImageableX() + 20f,
              y = (float)pageFormat.getImageableY() + 30f;

        Graphics2D g2 = (Graphics2D)g;
        Font font = new Font("SansSerif", Font.PLAIN, 20);
        FontRenderContext frc = g2.getFontRenderContext();
        GlyphVector v = font.createGlyphVector(frc, "0123456789");

        for(int i = 0; i <= v.getNumGlyphs(); i++)
        {
            Point2D.Float p = new Point2D.Float();
            p.x = i * 40f;
            p.y = 0;
            v.setGlyphPosition(i, p);
        }

        g2.drawGlyphVector(v, x, y);
        return PAGE_EXISTS;
    }
}

---------- END SOURCE ----------
###@###.### 10/29/04 19:51 GMT

Comments
EVALUATION Printing a Glyphvector is now optimised to use printer fonts if possible. That code checks to see if the GlyphVector has position adjustments, as if so it will need to copy these to specify the per glyph positions. The code to do that is there and in place Unfortunately if the string has a compatible FRC we don't test against that value, unlike in some other cases in the glyph vector printing code, so before we reach the code that handles that case, we print the GV using drawString. ###@###.### 10/29/04 19:57 GMT
29-10-2004

WORK AROUND -Dsun.java2d.print.shapetext=true will force the old behaviour but this should be used with GREAT caution as it affects all text printing and you may see quality degradations and massive printer spool files. ie the bug is in the very limited case of a GV with position adjustments and this workaround affects a lot more than just that. ###@###.### 10/29/04 19:57 GMT
29-10-2004

SUGGESTED FIX *** 770,776 **** return false; } ! if (compatibleFRC) { drawString(str, x, y, font, gvFrc, 0f); return true; } --- 770,777 ---- return false; } ! if (compatibleFRC && ! (flags & GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) == 0) { drawString(str, x, y, font, gvFrc, 0f); return true; } ###@###.### 10/29/04 19:57 GMT
29-10-2004