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

Text Quality problem printing with 1.1 printing API

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs
    • 2d
    • generic, x86
    • generic, windows_95, windows_nt



      Name: diC59631 Date: 12/01/98

      =20
      I have an application in which you can enter a text
      and view it in all fonts available on the system.
      You can view it on screen or on paper. On screen works well=20
      but when printing it, it take tremendously long time and the result=20
      is ugly and not what I expected.


      Code:
      -----------------------------------------------
      import java.awt.*;
      import javax.swing.*;
      import java.awt.event.*;


      public class Test1
      {
          static public void main (String [] args)
          {

             GraphicsEnvironment gre =3D GraphicsEnvironment.getLocalGraphicsEnvi=
      ronment();

             Font [] fonts =3D gre.getAllFonts();

             final JFrame f =3D new JFrame ();
             f.setSize (400, 400);
             f.setVisible(true);
             f.getContentPane().setLayout (new BorderLayout());

             final JTextField inputField =3D new JTextField("Input text!");
             f.getContentPane().add ("North", inputField);


             JPanel southPanel =3D new JPanel();
             f.getContentPane().add ("South", southPanel);


             JButton showMeButt =3D new JButton("Show me!");
             southPanel.add (showMeButt);

             JButton printMeButt =3D new JButton("Print me!");
             southPanel.add (printMeButt);



             ScrollPane sp =3D new ScrollPane ();
             f.getContentPane().add (sp);

             final FontViewer fontViewer =3D new FontViewer (args[0], fonts);
             sp.add (fontViewer);

             f.validate();



             showMeButt.addActionListener ( new ActionListener ()
                                            {
                                              public void actionPerformed (Action=
      Event e)
                                              {
                                                  fontViewer.setText (inputField.=
      getText());

                                              }

                                            });

             printMeButt.addActionListener ( new ActionListener ()
                                            {
                                              public void actionPerformed (Action=
      Event e)
                                              {

                                                  print ();
                                              }

                                              public void print ()
                                              {
                                                  PrintJob pjob =3D Toolkit.getDe=
      faultToolkit().getPrintJob(f,"Print test", null );

                                                  if (pjob !=3D null)
                                                  {
                                                      Graphics pg =3D pjob.getGra=
      phics();
                                                      if (pg !=3D null)
                                                      {
                                                          pg.setColor (Color.blac=
      k);

                                                          fontViewer.print (pg);

                                                          pg.dispose ();
                                                      }


                                                      pjob.end();
                                                  }

                                              }
                                            });


          }


      }






      class FontViewer extends Canvas
      {
          String text;
          Font[] fonts;

          public void setText (String txt)
          {
              text =3D txt;
              repaint();
          }

          public void print (Graphics g)
          {

              for (int i =3D 0; i < 10; i++) // We only print the ten first
              {
                  System.out.println (i);
                  g.setColor (Color.black);

                  g.setFont (new Font (fonts[i].getName(),Font.PLAIN, 18) );

                  g.drawString (fonts[i].getName(), 30, i * 40);

                  g.drawString (text, 30, i * 40 + 20);

              }

          }


          FontViewer (String text, Font[] fonts)
          {
              this.text =3D text;
              this.fonts =3D fonts;
              setSize (400, 20 * fonts.length);
          }

          public void paint (Graphics g)
          {
              int x =3D getSize().width / 2;

              for (int i =3D 0; i < fonts.length; i++)
              {
                  g.setColor (Color.black);

                  g.setFont (new Font (fonts[i].getName(),Font.PLAIN, 18) );




                  g.drawString (fonts[i].getName(), 10, i * 20);

                  g.drawString (text, x, i * 20);

              }
          }


      }
      (Review ID: 43393)
      ======================================================================

      The test case is using physical fonts which is not supported.
      The 1.1 printing API isn't written to use anything other than the logical
      fonts which were available in 1.1.
      They will happen to work with 1.2.2, but that is an implementation quirk.
      The other aspects of this bug (size of spool jobs) are covered by other
      bugs which this report duplicates.
      ====================================================================

            prr Philip Race
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: