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

getImageableWidth() and getImageableHeight() do not work on A0-A3 size paper

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 1.4.2
    • client-libs
    • 2d
    • b43
    • x86
    • windows_2000



      Name: jl125535 Date: 08/25/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
      Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode)

      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Version 5.1.2600

      A DESCRIPTION OF THE PROBLEM :
      Java Print to 2D Stream does not work as expected for paper sizes other than A4.

      If I print the imageableWidth and ImageableHeight of PageFormat, the numbers are the same for A3 and A4 pages, although the result is shifted, and the page dimensions only change for A2 and lower. What gets printed is far away from the range given by the numbers in PageFormat



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      Start with the example in:

      http://java.sun.com/j2se/1.5.0/docs/guide/jps/spec/appendix_2DtoStream.fm.html

      After
        ---- PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

      insert
         ---- aset.add(MediaSizeName.ISO_A2); // or A0, A3, etc.

      After
       --- public int print(Graphics g,PageFormat pf,int pageIndex) {

      insert:
        --- System.out.println("Page dimensions in points inch-width:" + pf.getImageableWidth()/72 + " inch-height:" + pf.getImageableHeight()/72);



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Print2DtoStream example is, I believe, supposed to produce a 200 x
      200 point = 2.7 x 2.7 inch black rectangle in the top left hand corner
      of the page (leaving a margin) in the postscript image for all sizes.
      This black square and example text to be visible in the postscript result no matter what the paper size.

      Furthermore, page dimensions to vary with the different page sizes (see http://www.cl.cam.ac.uk/~mgk25/iso-paper.html)

      The standard should be:

      A4: 210 Èù 297 mm = 8.26 x 11.69 inches
      A3: 297 x 420 mm = 11.69 x 16.53 inches
      A2: 420 x 594 mm = 16.53 x 23.38 inches

      The imageable area may be slightly smaller due to page margins.

      ACTUAL -
      For ISO_A4 I get
          inch-width=6.5 inch-height=9.0
      For ISO_A3 I get
         inch-width=6.5 inch-height=9.0
      For ISO_A2 I get
         inch-width=14.5... inch-height=21.3...

      And the Black Square does not appear in the A0-A3 cases.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
       *
       * This software is the proprietary information of Sun Microsystems, Inc.
       * Use is subject to license terms.
       *
       */

      import java.io.*;
      import java.awt.*;
      import java.awt.print.*;
      import javax.print.*;
      import javax.print.attribute.*;
      import javax.print.attribute.standard.*;

      /*
       * Use the Java(TM) Print Service API to locate a service which can export
       * 2D graphics to a stream as Postscript. This may be spooled to a
       * Postscript printer, or used in a postscript viewer.
       */
      public class Print2DtoStream implements Printable{

      public Print2DtoStream() {

      /* Use the pre-defined flavor for a Printable from an InputStream */
      DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

        /* Specify the type of the output stream */
      String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

      /* Locate factory which can export a GIF image stream as Postscript */
      StreamPrintServiceFactory[] factories =
      StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
      flavor, psMimeType);
      if (factories.length == 0) {
      System.err.println("No suitable factories");
      System.exit(0);
      }

      try {
      /* Create a file for the exported postscript */
      FileOutputStream fos = new FileOutputStream("out.ps");

      /* Create a Stream printer for Postscript */
      StreamPrintService sps = factories[0].getPrintService(fos);

      /* Create and call a Print Job */
      DocPrintJob pj = sps.createPrintJob();
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();


      // CHANGE THIS TO ISO_A4 OR ISO_A3 OR ISO_A1 OR ISO_A0
      // EACH OF THESE PAGE SIZES VARIES BY A FACTOR OF 2 IN AREA
      aset.add(MediaSizeName.ISO_A2);

      Doc doc = new SimpleDoc(this, flavor, null);

      pj.print(doc, aset);
      fos.close();

      } catch (PrintException pe) {
      System.err.println(pe);
      } catch (IOException ie) {
      System.err.println(ie);
      }
      }

      public int print(Graphics g,PageFormat pf,int pageIndex) {

      //System.out.println("Ix " + pf.getImageableX() + " Iy " + pf.getImageableY());
      System.out.println("Page dimensions in points inch-width:" + pf.getImageableWidth()/72 + " inch-height:" + pf.getImageableHeight()/72);
      if (pageIndex == 0) {
      Graphics2D g2d= (Graphics2D)g;
      g2d.setColor(Color.blue);
      double xc = pf.getImageableX() + pf.getImageableWidth() / 2;
      double yc = pf.getImageableY() + pf.getImageableHeight() / 2;
      g2d.drawString("example string", (int)xc, (int)yc);
      g2d.translate(pf.getImageableX(), pf.getImageableY());

      g2d.fillRect(0, 0, 200, 200);
      return Printable.PAGE_EXISTS;
      } else {
      return Printable.NO_SUCH_PAGE;
      }
      }

      public static void main(String args[]) {
          Print2DtoStream sp = new Print2DtoStream();
      }
      }



      ---------- END SOURCE ----------
      (Incident Review ID: 296633)
      ======================================================================

            prr Philip Race
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: