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

Stroke width incorrect while printing with an AffineTransform

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 6
    • client-libs
    • 2d
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59g)
      Java HotSpot(TM) Client VM (build 1.6.0-beta-b59g, mixed mode, sharing)

      This bug was also confirmed for 1.4.2 and 1.5

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

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Confirmed this bug while using the following printers:
      hp LaserJet 1320 PCL 6
      Canon PS-IPU Color Laser Copier v52.3
      The Canon driver was only used to print to postscript files.

      A DESCRIPTION OF THE PROBLEM :
      When printing, stroke widths of lines do not draw correctly if an AffineTransform is set on the graphics object which rotates it. The lines draw correctly at 0, 90, 180, and 270 degrees. At 45, 135, etc., the lines appear very thin, close to 10% the expected width. Between 0 and 45 degrees, the problem gradually gets worse as the angle approaches 45.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program. The screen should show 64 lines, rotated around a center point with equal thickness to each line. Hit the print button and print the graphic.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The printed graphic should appear the same as what was on the screen.
      ACTUAL -
      The lines were printed with varying thicknesses. The thick lines appear 10x as thick as the thinnest lines. I can provide images of the expected and actual results if necesary.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no error messages

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package printbug;

      import java.awt.BasicStroke;
      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.geom.AffineTransform;
      import java.awt.print.PageFormat;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;

      import javax.swing.JButton;
      import javax.swing.JComponent;
      import javax.swing.JFrame;
      import javax.swing.JPanel;

      public class PrintBug extends JFrame implements ActionListener {
      JButton print;
      PrinterJob printerJob = PrinterJob.getPrinterJob();
      JWidget widget;

      public static void main(String[] args) {
      PrintBug bug = new PrintBug();
      bug.setSize(640, 640);
      bug.setVisible(true);
      bug.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }

      public PrintBug() {
      widget = new JWidget();
      print = new JButton("print");
      print.addActionListener(this);

      widget.setMinimumSize(new Dimension(320,240));

      JPanel panel = new JPanel(new BorderLayout());
      panel.add(widget, BorderLayout.CENTER);
      panel.add(print, BorderLayout.SOUTH);
      getContentPane().add(panel);
      }

      public void actionPerformed(ActionEvent e) {
      Printable printable;

      if (e.getSource() == print) {
      if (printerJob.printDialog()) {

      PageFormat format = printerJob.defaultPage();
      format = printerJob.pageDialog(format);
      // print!
      printable = new JWidgetPrinter(widget);
      printerJob.setPrintable(printable, format);

      //printerJob.setPrintable(wrapper.jsdml.getDrawing());
      try {
      printerJob.print();
      } catch (PrinterException e1) {
      e1.printStackTrace();
      }
      }
      }
      }
      }

      class JWidget extends JComponent {
      public void paint(Graphics g) {
      Graphics2D g2d = (Graphics2D) g;
      super.paint(g);
      g.setColor(Color.BLACK);
      g2d.setStroke(new BasicStroke(3));

      AffineTransform transform = g2d.getTransform();
      for(double i=0; i<=Math.PI*2; i+=Math.PI/64) {
      g2d.rotate(i, 300, 300);
      g.drawLine(300,300,500,300);
      g2d.setTransform(transform);
      }
      }
      }

      class JWidgetPrinter implements Printable {
      private final JWidget widget;

      JWidgetPrinter(JWidget widget) {
      this.widget = widget;
      }

      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
      if(pageIndex != 0) {
      return Printable.NO_SUCH_PAGE;
      }
      widget.print(graphics);
      return Printable.PAGE_EXISTS;
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      none found

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: