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

Graphics.draw and drawPolygon do not print some thin lines on certain printers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 6
    • client-libs
    • 2d
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_07"
      Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
      Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

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

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Printer: Epson Stylus D88

      A DESCRIPTION OF THE PROBLEM :
      With BasicStroke ( 0f ), Graphics.draw and drawPolygon should print the thinnest possible lines for the target device. But if they are used with an Epson Stylus D88 there are lines that do not appear on the paper.
      Lines that have an angle of 45 degrees are not printed.
      The printer is able to print all lines, but this works only with drawLine.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the source code below. It creates 3 polygons and prints them with different methods.
      If you do not have an Epson Printer then you can download and install the printer driver. You can print to a file and use the preview feature of the driver.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Graphics.draw and drawPolygon should print all lines.
      ACTUAL -
      The lines with an angle of 45 degrees are not printed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.geom.GeneralPath;
      import java.awt.print.*;
      import javax.print.attribute.*;

      public class DrawHairStrokeTester implements Printable
      {
        static final Stroke hairStroke = new BasicStroke ( 0f ) ;

        public static void main ( String[] args )
        {
          PrinterJob printerJob = PrinterJob.getPrinterJob () ;

          if ( printerJob == null )
          {
            System.out.println ( "no PrinterJob available" ) ;
            return ;
          }

          PrintRequestAttributeSet printAttributeSet = new HashPrintRequestAttributeSet () ;

          if ( printerJob.printDialog ( printAttributeSet ) )
          {
            Printable printable = new DrawHairStrokeTester () ;
            printerJob.setPrintable ( printable ) ;
            try
            {
              printerJob.print ( printAttributeSet ) ;
            }
            catch ( PrinterException ex )
            {
              ex.printStackTrace () ;
            }
          }
        }

        public int print ( Graphics gra , PageFormat pageFormat , int pageIndex )
        {
          if ( ! ( pageIndex == 0 && gra instanceof Graphics2D ) )
          {
            return Printable.NO_SUCH_PAGE ;
          }
          Graphics2D gra2D = (Graphics2D) gra ;
          gra2D.setStroke ( hairStroke ) ; // thinnest possible line
          gra2D.translate ( pageFormat.getImageableX () , pageFormat.getImageableY () ) ;
          gra.setColor ( Color.black ) ;

          int nPoints = 12 ;
          double[] xCoords = new double [ nPoints ] ;
          double[] yCoords = new double [ nPoints ] ;

          double xm = 210 ;
          double ym = 210 ;
          double radius = 200 ;
          double angle = 2 * Math.PI / nPoints ;

          for ( int i = 0 ; i < nPoints ; i ++ )
          {
            xCoords [ i ] = xm + radius * Math.cos ( i * angle ) ;
            yCoords [ i ] = ym + radius * Math.sin ( i * angle ) ;
          }

          GeneralPath path = new GeneralPath ( GeneralPath.WIND_EVEN_ODD , nPoints ) ;
          path.moveTo ( xCoords [ 0 ] , yCoords [ 0 ] ) ;
          for ( int i = 1 ; i < nPoints ; i ++ )
          {
            path.lineTo ( xCoords [ i ] , yCoords [ i ] ) ;
          }
          path.closePath () ;

          gra2D.draw ( path ) ;

          int[] xPoints = new int [ nPoints ] ;
          int[] yPoints = new int [ nPoints ] ;
          int yTrans = 110 ;
          for ( int i = 0 ; i < nPoints ; i ++ )
          {
            xPoints [ i ] = (int) Math.round ( xCoords [ i ] ) ;
            yPoints [ i ] = (int) Math.round ( yCoords [ i ] ) + yTrans ;
          }

          gra.drawPolygon ( xPoints , yPoints , nPoints ) ;

          for ( int i = 0 ; i < nPoints ; i ++ )
          {
            int ip1 = ( i + 1 ) % nPoints ;
            gra.drawLine ( xPoints [ i ] , yPoints [ i ] + yTrans ,
              xPoints [ ip1 ] , yPoints [ ip1 ] + yTrans ) ;
          }

          return Printable.PAGE_EXISTS ;
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Scale the coordinates and Graphics2D and use drawLine.

            psadhukhan Prasanta Sadhukhan
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: