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
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
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?
|
|
|
|