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

2nd instance of drawString fails to draw on Solaris only.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.2.2
    • client-libs
    • 2d
    • sparc
    • solaris_2.6, solaris_7

      Build : 'N'
      OS : Sol2.6, 2.7 (95/98/NT ok)

      The app below fails to draw the 2nd instance of the drawString call on Solaris but ok on Win32.

      However if the 2nd instance of drawString was placed immediately following another drawString but preceding a draw method the string will be painted.

      import java.awt.geom.*;
      import java.awt.font.*;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import java.awt.print.PrinterJob;
      import java.awt.event.*;
      import java.awt.*;
      import java.awt.print.*;

      public class ViewPrint extends Panel implements Printable, ActionListener {


         final static Color bg = Color.white;
         final static Color fg = Color.black;
         final static float scaleFactor = 72f/1000f;
         final static Font fnt = new Font("Times",Font.PLAIN, 12);
         final static Button button = new Button("Print");


         public ViewPrint() {
           setBackground(bg);
            button.addActionListener(this);
         }


         public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof Button) {
               PrinterJob printJob = PrinterJob.getPrinterJob();
               printJob.setPrintable(this);
               if (printJob.printDialog()) {
                  try {
                     printJob.print();
                  }
                  catch (Exception PrintException) {
                     PrintException.printStackTrace();
                  }
               }
           }
         }

         public void paint(Graphics g) {
           super.paint(g);
           Graphics2D g2 = (Graphics2D) g;
           drawShapes(g2);
         }

         public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {

            if (pi >= 1) {return Printable.NO_SUCH_PAGE;}

            Graphics2D g2 = (Graphics2D) g;
            //translate by margin width and height
            g2.translate(pf.getImageableX(), pf.getImageableY());

            drawShapes(g2);
            return Printable.PAGE_EXISTS;
         }

         public void drawShapes(Graphics2D g2){
            Rectangle r = new Rectangle();
            // scale 1" = 1000' with negative y to flip y axis to "normal"=increasing up
            AffineTransform atScale = AffineTransform.getScaleInstance(scaleFactor, -scaleFactor);
            // Use the font defined above
            g2.setFont(fnt);
            g2.setPaint(new Color(0,0,0));
            g2.setStroke(new BasicStroke(1f));

            //imageable area of this Panel. Not right for printed page, but it works.
            int iw = getWidth();
            int ih = getHeight();

            // put origin in center
            g2.translate(iw/2, ih/2);
            //draw axis
            g2.draw(new Line2D.Float(-iw/2,0f,iw/2,0f));
            g2.draw(new Line2D.Float(0f,-ih/2,0f,ih/2));

            //draw box centered at origin, 72 units square
            //it will be 1" on paper, 72 pixels on the screen
            r.x = -36; r.y = -36; r.width = 72; r.height = 72;
            g2.draw(r);
            g2.drawString("Unscaled", 36, -36);
            
            
            // scale 1" = 1000' with negative y to flip y axis to "normal"
            g2.transform(atScale);
            //reset font and line width
            BasicStroke bs = (BasicStroke)g2.getStroke();
            bs = new BasicStroke(bs.getLineWidth()/scaleFactor);
            g2.setStroke(bs);
            g2.setFont(g2.getFont().deriveFont(atScale));
          
            //draw box centered at origin, 4000' square
            //it will be 2" on paper, 144 pixels on the screen
            r.x = -2000; r.y = -2000; r.width = 4000; r.height = 4000;
            g2.draw(r);
            g2.drawString(".Scaled", 2000, 2000);
         }


         public static void main(String s[]){

            WindowListener l = new WindowAdapter() {
             public void windowClosing(WindowEvent e) {System.exit(0);}
             public void windowClosed(WindowEvent e) {System.exit(0);}

           };

            Frame f = new Frame();
            f.addWindowListener(l);
            Panel panel = new Panel();
            f.add(BorderLayout.SOUTH, panel);
            f.add(BorderLayout.CENTER, new ViewPrint());
            panel.add(button);
            f.add(BorderLayout.SOUTH, panel);
            f.setSize((int)(72*6.5), 72*9);
            f.show();
         }

      }

            prr Philip Race
            rckim Robert Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: