Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6784397

Uneven spacing when printing Monospaced font

XMLWordPrintable

    • 2d
    • x86
    • windows_xp

      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.

            prr Philip Race
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: