JDK-6543815 : Imageable area of PageFormat is ignored if values of imageable X/Y are negative.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0u12
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-04-09
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
5.0u14Fixed 6u4Fixed 7 b14Fixed
Related Reports
Relates :  
The printing result in 5.0 is different from that in 1.4.2.

Reproduce : 
1. Open VDS system(provided by the customer)
   You will see the login view.
2. Click "login" button, leaving username and password box blank
  You will see the sttached vds1.jpg
3. Click the link "All Primitives of VDS HMI Graphic4
  You will see the attached vds2.jpg
4.  Click "small" in Continuous/Royality row of Trend Primitive area
      in Control Primitive Area(Please see the vds2.jpg)
 A new IE windows is cretaed and you will see the attached vds3.jpg
5. Click the printer icon at the top-right position. 

When the above proceduce is done in 1.4.2_14 and 
 the result will be the attached result_142.jpg and result_50ux.jpg respectively.

EVALUATION Here is a small program which demonstrates the same issue import java.awt.*; import java.awt.print.*; public class Margins implements Printable { public static void main(String args[]) { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pageFormat = job.defaultPage(); Paper paper = pageFormat.getPaper(); double wid = paper.getWidth(); double hgt = paper.getHeight(); paper.setImageableArea(0, -10, wid, hgt); pageFormat = job.pageDialog(pageFormat); pageFormat.setPaper(paper); job.setPrintable(new Margins(), pageFormat); if (job.printDialog()) { try { job.print(); } catch (PrinterException e) { } } } public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { return NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); int ix = (int)pf.getImageableX(); int iy = (int)pf.getImageableY(); int iw = (int)pf.getImageableWidth(); int ih = (int)pf.getImageableHeight(); System.out.println("ix="+ix+" iy="+iy+" iw="+iw+" ih="+ih); g2d.setColor(Color.black); g2d.drawRect(1, 1, iw-2, ih-2); return PAGE_EXISTS; } }

EVALUATION It looks to me as if the complaint is that the print out uses default (1 inch) margins in 1.5.0 and later, whereas it uses small (approximately hardware margins) in 1.4.2 The reason for this appears to be a bug in the application such that it sets the imageable X and Y for a Paper to be negative values paper.setImageableArea(28.0, -147.0, 630.0, 920.0); In the application they are calculated with logic like this: dXpoint = Double.parseDouble(..) dYpoint = Double.parseDouble(..) dWidth = objectToPrint.getWidth() Height = objectToPrint.getHeight() if (landscape) { dXpoint = paper.getHeight() - (dWidth + dXpoint); paper.setImageableArea(dYpoint, dXpoint, dHeight, dWidth); } clearly there's a bug since there is no attempt to ensure that dXpoint will be a positive value. Perhaps Paper.setImageableArea() should have always thrown IllegalArgumentException in this case .. also a bit oddly the code that uses this displays the pagedialog. lets the user set margins and *after* that pops down overwrites what the user specified. That's bad UI. The actual change in the JDK that exposed this application bug was this fix in early 1.5 builds in June 2003 (!) 4869575:Setting orientation in the page format does not have any effect on the printout the webrev can be seen here: http://javaweb.sfbay/jcg/1.5.0-tiger/2D/4869575/index.html 508 float ix = (float)(page.getPaper().getImageableX()/DPI); 509 float iw = (float)(page.getPaper().getImageableWidth()/DPI); 510 float iy = (float)(page.getPaper().getImageableY()/DPI); 511 float ih =(float)(page.getPaper().getImageableHeight()/DPI); 512 try { 513 attributes.add(new MediaPrintableArea(ix, iy, iw, ih, 514 MediaPrintableArea.INCH)); 515 } catch (IllegalArgumentException iae) { 516 } this converts the imageable area into a MediaPrintableArea. However MediaPrintableArea does what Paper always should have done and throws an exception on such illegal values. Therefore the values set by the app are completely ignored. This leaves alone the MediaPrintableArea that was in the attribute set as a result of displaying the page dialog. This therefore constitutes a workaround: the user simply sets the margins to all zeros and windows will replace these with the minimum possible margins. The simplest JDK fix to this, is that after lines 508-511 above, the values should be clamped to be legal values. In particular : if (ix<0) ix=0f; if (iy<0) iy=0f; that would work around this appliation bug.

EVALUATION Description is not clear and without test case, cannot be analyzed. Need a standalone small test case to reproduce the problem. Also need information: Which 5.0 update release did the bug start to appear? Is this still reproducible with 6.0?