JDK-6784397 : Uneven spacing when printing Monospaced font
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6u10
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-12-12
  • Updated: 2018-09-05
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
tbdUnresolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

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



A DESCRIPTION OF THE PROBLEM :
Printing of Monospaced text no longer produces reliable monospaced spacing.  For example, documents with text arranged in two columns lined up using spaces will look correct when displayed but no longer result in an aligned second column when printed.  Trailing spaces on a line are sometimes the cause, whereas they shouldn't make a difference.  JTextArea and JTextPane both exhibit this problem.  This is a regression in 1.6.0_10, as 1.6.0_7 and prior releases worked correctly.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the source code provided.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Columns of text when printed should be aligned the same as when displayed, and the same as they were when printed under 1.6.0_7.
ACTUAL -
Examples of the problem in the test document:
1) "PO BOX" should be aligned with "LOGISTICS" and "LOS ANGELES", not shifted right one space
2) "MANAGEMENT" should be aligned under "FP", not shifted left a half space.
3) "APPROVAL" should be aligned under "SUPERVISOR", not shifted left a half space.
4) "NA" should be aligned under "03", not shifted right 7 spaces (removing trailing spaces fixes).
5) "ADDRESS" should be one space after "APP", not shifted right 15 spaces (removing trailing spaces fixes).
6) "RECIPIENT" should be aligned with "9", not shifted left a half space.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.print.*;
import javax.swing.*;

public class Test {

    static JTextArea textArea;
    static JFrame f;

    public static void main(String[] args) {
        textArea = new JTextArea();
        String txt = "           LOGISTICS BUREAU\n" +
                     "           PO BOX  30158 \n" +
                     "           LOS ANGELES CA 90030\n" +
                     "\n" +
                     "APP ORI:               CA0194200\n" +
                     "APP NAME:              FP REJECT PO\n" +
                     "APP TYPE:              MANAGEMENT/HEAD DEPARTMENT\n" +
                     "APP TITLE:             SUPERVISOR\n" +
                     "APP SERVICE:           APPROVAL/RESPONSE/COPY\n" +
                     "OCA:                   PO THREE\n" +
                     "DOB:                   03/03/1960\n" +
                     "CDL:                   NA      \n" +
                     "ATI:                   I285POF404\n" +
                     "DATE SUBMITTED:        10/16/2001\n" +
                      "\n" +
                     "APP ADDRESS:               \n" +
                     "\n" +
                     "Electronic Response:      91238\n" +
                     "Email Address:            ###@###.###\n" +
                     "Routing Number:           964464-332\n";

        textArea.setText(txt);
        textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));

        f = new JFrame("Test");
        f.getContentPane().add(textArea);
        f.setPreferredSize(new Dimension(600, 800));
        f.pack();
        f.setVisible(true);

        PrinterJob pj = PrinterJob.getPrinterJob();
        PageFormat pf = pj.defaultPage();
        pj.setPrintable(new Content(), pf);
        try { if (pj.printDialog()) pj.print(); }
        catch (Exception e) { e.printStackTrace(); }
        System.out.println("Hit <Enter> when done");
        try { System.in.read(); } catch (Exception e) {}
    }

    static class Content implements Printable {
        public int print(Graphics g, PageFormat pf, int pageIndex) {
            if (pageIndex > 0) return Printable.NO_SUCH_PAGE;
            Graphics2D g2d = (Graphics2D) g;
            g2d.translate(pf.getImageableX(), pf.getImageableY());
            textArea.print(g2d);
            return Printable.PAGE_EXISTS;
        }
    }
}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Removing trailing spaces fixes some but not all of the problems.

Release Regression From : 6u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

Converted "8-client-defer-candidate" label to "8-defer-request" by SQE' OK.
15-08-2013

*This is anti-deferral criteria list*: - P2 -------------- Engineering's Criteria ------------------------------------- - tck-red labeled - conformance labeled - P3 regressions reported/labeled against jdk8 - findbugs, parfait, eht labeled bugs - CAP <1 year reported - netbeans <1 year reported Victor ----------------- SQE's OK --------------------------------- Yes, we are ok with that thanks, Mikhail
15-08-2013

EVALUATION Started in 6u10 b26. May be caused by fix for 6488219.
17-12-2008

EVALUATION I do not see any visual misalignment in Font2DTest using monospaced font and text from the testcase. So, it seems to be printing specific problem. May be wrong font was used.
16-12-2008