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

Swing text components using a physical font print text as filled shapes (bigger spool files).

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 5.0u7, 6
    • client-libs
    • 2d
    • 5.0
    • b03
    • x86
    • windows_2000, windows_xp
    • Verified

        FULL PRODUCT VERSION :
        1.5.0_07

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        HP Laser Jet 4000 PCL6

        A DESCRIPTION OF THE PROBLEM :
        Printer spool file created is much larger when running under 1.5.0_07 jre then what is created when running under 1.4.3_02 jre

        Example: Original text file of 11,430 bytes (sample.txt) when printed:
        1.4.2_03 file created is 74,367 bytes
        1.5.0_07 file created is 1,578,860 bytes
        21 Times larger.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        I have create a test program that reads in an ASCII text file
        (sample.txt) and launches our applications print screen.
        When the print button is clicked, I choose a typical printer (in my case
        - HP Laser Jet 4000 PCL6) that I have configured to print to a file.

        I created 2 bat files:

        run-spooltest14.bat - runs the test program under 1.4.2_03 and creates
        the 74,367 byte file.
        run-spooltest15.bat - runs the test program under 1.5.0_07 and creates
        the 1,578,860 byte file.


        I have also created bat files to compile TextReportScreen.java which has
        all the printer specific code.

        compile-spooltest14.bat - compiles TextReportScreen.java under 1.4
        compile-spooltest15.bat - compiles TextReportScreen.java under 1.5

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Generated same file size in 5.0_07
        ACTUAL -
        1.5.0_07 file created is 1,578,860 bytes
        21 Times larger.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        1.5.0_07 file created is 1,578,860 bytes
        21 Times larger.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        Attached Seperatly
        ---------- END SOURCE ----------
        That test case is too complex.
        Here's a simpler one that's more to the point.
        All that's needed is to print a Swing text component after setting a physical font
        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        import javax.swing.text.*;
        import java.awt.print.*;

        public class PrintTextPane implements Printable, ActionListener {

            JTextPane pane;

            public int print(Graphics g, PageFormat pf, int page) throws
                                                                PrinterException {
                if (page > 0) {
                    return NO_SUCH_PAGE;
                }
                Graphics2D g2d = (Graphics2D)g;
                System.out.println("BEFORE = " + g2d.getTransform());
                g2d.translate(pf.getImageableX(), pf.getImageableY());
                System.out.println("AFTER = " + g2d.getTransform());
                pane.printAll(g);
                return PAGE_EXISTS;
            }

            public void actionPerformed(ActionEvent e) {
        /*
                try {
                     pane.print();
                 } catch (PrinterException ex) {
                       throw new RuntimeException(ex);
                 }
        */
                 PrinterJob job = PrinterJob.getPrinterJob();
                 job.setPrintable(this);
                 boolean ok = job.printDialog();
                 if (ok) {
                     try {
                          job.print();
                     } catch (PrinterException ex) {
                           throw new RuntimeException(ex);
                     }
                 }

            }

            public PrintTextPane(JTextPane f) {
                pane = f;
            }
           static String text = "Twinkle twinkle little star, \n" +
                                "How I wonder what you are.";

            public static void main(String args[]) {
                JFrame f = new JFrame("Print Text Pane");
                f.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {System.exit(0);}
                });
                JTextPane pane = new JTextPane();
                SimpleAttributeSet aset = new SimpleAttributeSet();
                StyleConstants.setFontFamily(aset, "Courier New");
                //StyleConstants.setFontFamily(aset, "Monospaced");
                pane.setCharacterAttributes(aset, false);
                pane.setText(text);
                f.add("Center", pane);
                JButton printButton = new JButton("Print TextPane");
                printButton.addActionListener(new PrintTextPane(pane));
                f.add("South", printButton);
                f.pack();
                f.setVisible(true);
            }
        }

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: