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

Using custom paper sizes results in incorrect scaling of printed images

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.3.1
    • 1.4.0
    • client-libs
    • 2d
    • rc1
    • x86
    • windows_2000


        ingrid.yao@Eng 2000-11-01
        ---------------------------

        Reported by a Merlin Cap Member:

        J2SE Version (please include all output from java -version flag):
          java version "1.4.0beta"
          Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b38)
          Java HotSpot(TM) Client VM (build B38, mixed mode)

        Does this problem occur on J2SE 1.3? Yes / No (pick one)
          No, Custom paper sizes were not available due to bug # 4355514.

        Operating System Configuration Information (be specific):
          Windows 2000 Pro.

        Hardware Configuration Information (be specific):
          Pentium II 450MHZ 384MB RAM
          Printer: HP DesignJet 2500 CP

        Bug Description:
        Using custom paper sizes results in incorrect scaling of printed images.
        The scaling error is proportional to requested paper size. I believe that
        it is scaling the default paper size into the requested paper size.

        Steps to Reproduce (be specific):
        The attached program(PlotterTester.java) attempts to print a 1 inch x 1
        inch square in the upper left corner of a large piece of paper. The print
        is distorted unless PrinterJob.validatePage(PageFormat) is called.
        Unfortunately, this also resets the paper size to the default.

        Work around:
        Strangely, the problem is fixed by concatenating an identity transform to
        the graphics object using (Graphics2D.transform(new AffineTransform());

        Test program:
        --------- PlotterTester.java-----------------------
        import java.awt.*;
        import java.awt.print.*;
        import java.awt.geom.*;
        import javax.swing.*;

        public class PlotterTester implements Pageable, Printable{

          private static double PIXELS_PER_INCH = 72.0;
          private static double WIDTH = 17.0; //width of paper in inches
          private static double LENGTH = 22.0; //length of paper in inches
          private static boolean VALIDATE = false;

          private PrinterJob printerJob;
          private PageFormat pageFormat;

          PlotterTester(){
            printerJob = PrinterJob.getPrinterJob();
            createPageFormat();
          }
          
          private void createPageFormat(){
            pageFormat = new PageFormat();
            Paper p = new Paper();
            double width = WIDTH*PIXELS_PER_INCH;
            double height = LENGTH*PIXELS_PER_INCH;
            double ix = PIXELS_PER_INCH;
            double iy = PIXELS_PER_INCH;
            double iwidth = width - 2.0*PIXELS_PER_INCH;
            double iheight = height - 2.0*PIXELS_PER_INCH;
            p.setSize(width, height);
            p.setImageableArea(ix, iy, iwidth, iheight);
            pageFormat.setPaper(p);
          }
          
          public Printable getPrintable(int index){
            return this;
          }
          
          public PageFormat getPageFormat(int index){
            return pageFormat;
          }
          
          public int getNumberOfPages(){
            return 1;
          }
          
          private void printPaperSize(PageFormat pf){
            Paper p = pf.getPaper();
            System.out.println("paper size = ("+p.getWidth()+", "+p.getHeight()+")");
          }
          
          private void printRectangle(Rectangle r){
            System.out.println("("+r.x+", "+r.y+", "+r.width+", "+r.height+")");
          }
          
          public void print(){
            if(printerJob.printDialog()){
              System.out.println("start printing");
              try{
                //pageFormat = printerJob.pageDialog(pageFormat);
                printPaperSize(pageFormat);
                if(VALIDATE){
                    this.pageFormat = printerJob.validatePage(this.pageFormat);
                }
                printPaperSize(pageFormat);
                printerJob.setPageable(this);
                //printerJob.setPrintable(this, pageFormat);
                printerJob.print();
              }catch(Exception e){e.printStackTrace();}
            }
            System.out.println("done printing");
          }
         
          public int print(Graphics g, PageFormat pf, int pageIndex){
            printRectangle(g.getClipBounds());
            if(pageIndex == 0){
              Graphics2D g2 = (Graphics2D)g;
              g2.translate(pf.getImageableX(), pf.getImageableY());
              //g2.transform(new AffineTransform());//this line corrects the transform in the graphics object! why?
              Rectangle2D r = new Rectangle2D.Double(0, 0, PIXELS_PER_INCH, PIXELS_PER_INCH);
              g2.setStroke(new BasicStroke(1.0f));
              g2.draw(r);
              return PAGE_EXISTS;
            }else{
              return NO_SUCH_PAGE;
            }
          }
          
          public static void main(String[] args){
            System.out.println(System.getProperty("java.version"));
            PlotterTester pt = new PlotterTester();
            pt.print();
            try{
              System.in.read();
            }catch(Exception e){}
            System.exit(0);
          }
          
        }


        ingrid.yao@Eng 2000-12-01
        =============================

        More information from customer:

        The file plottertest_2k.hpg prints the square correctly, but it only cuts
        10" of paper. This is different than customer's result (running the test
        propgram), which is a distorted square on 24" of paper.

        The suggested work around(setting the paper size in printing preferences)
        isn't really a good solution for their application because there
        is no way to predict what size will be needed by the application. The
        content of the print job is chosen by the user. For example, the user might
        ask for 200' of data printed at 1/10 scale which should result in a print
        which is approximately 245 inches allowing room for margins as well as
        header and footer information.
        ========================================

        answers to information requested:
        > 1. Please attach the PRN file produced for Win 2K output.

        I have attached the prn file along with the exact source used to produce
        it. The printer is the HP DesignJet 2500 CP

        > 2. Verify if Graphics2D.translate() call corrects the problem rather than
        > Graphics2D.transform().

        I cannot seem to reproduce what I previously thought was a work around. All
        prints I've made recently exhibit the bug regardless of calling translate()
        or transform(), unless the requested size corresponds to a standard size.

        > 3. Does the problem occur when printing text or image?

        Both.

        jennifer.godinez@Eng 2001-02-02
        =======================================

        The solution is that DocumentProperties needs to be called to update the
        devmode as well as calling ResetDC.


        phil.race@eng 2001-02-09
        =======================================

              jgodinez Jennifer Godinez (Inactive)
              tyao Ting-Yun Ingrid Yao (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: