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

2D Print engine rounds coordinates to integers causing dropouts

    Details

    • Subcomponent:
      2d
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: tb29552 Date: 10/30/98


      !/*
      The awt print engine accepts coordinates in
      double values through the graphics 2d context.
      Clearly, the rasterizer has access to the full
      resolution of the printer, since it can render
      a smooth ellipse. However, coordinates that
      are not multiples of 1/24 inch are apparently
      either rounded or otherwise forced into 24 dpi
      increments. This is simply not acceptable
      for engineering applications.

      One would expect (looking at the API documents)
      that at least 72 dpi should be achievable.
      One would also expect that by using graphics
      2d contexts to render graphics, virtually
      any resolution should be addressable.

      The following code demonstrates the problem.
      Note that the grid produced has only 24 lines
      per inch even though as written, it should
      produce 72. You might also play around with
      the increment values in the two loops. You'll
      see that it is impossible to get anything lower
      than 24 dpi to be drawn.

      ----- TestPrint.java --------
      */
      import java.io.*;
      import java.awt.*;
      import java.awt.geom.*;
      import java.awt.print.*;

      public class TestPrint {
          public static void main(String[] argv)
          {
              Report report = new Report();

              report.print();
          }
      }

      class Report {
          public void print()
          {
              PrinterJob pj = PrinterJob.getPrinterJob();

              pj.setJobName("Test Report");

              PageFormat pf = pj.defaultPage();

              Book book = createBook(pf);

              pj.setPageable(book);

              if (pj.printDialog())
              {
                  try
                  {
                      pj.print();
                  }
                  catch(Exception e)
                  {
                      System.out.println(e);
                  }
              }
          }

          private Book createBook(PageFormat format)
          {
              Book retval = new Book();

              Printable printable = new Printable()
              {
                  public int print(Graphics g, PageFormat pf, int pi)
                  {
                      g.setColor(Color.black);

                      Graphics2D g2d = (Graphics2D) g;

                      g2d.setStroke(new BasicStroke(0.01 f)); // Use skinny lines

                      double x = pf.getImageableX();
                      double y = pf.getImageableY();
                      double width = pf.getImageableWidth();
                      double height = pf.getImageableHeight();

                      Line2D.Double line = new Line2D.Double();

                      for (double i = x; i <= x + width; i += 1.0)
                      {
                          line.setLine(i, y, i, y + height);
                          g2d.draw(line);
                      }

                      for (double i = y; i <= y + height; i += 1.0)
                      {
                          line.setLine(x, i, x + width, i);
                          g2d.draw(line);
                      }

                       return Printable.PAGE_EXISTS;
                  }
              };

              retval.append(printable, format);

              return retval;
          }
      }

      (Review ID: 41700)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              prr Philip Race
              Reporter:
              tbell Tim Bell
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: