8044444: The output's 'Page-n' footer does not show completely

Reviewed-by: prr, serb
This commit is contained in:
Alexander Scherbatiy 2015-04-28 19:32:50 +04:00
parent aca583b3e9
commit 6dd76600b3
3 changed files with 349 additions and 43 deletions

View file

@ -559,18 +559,8 @@ public abstract class RasterPrinterJob extends PrinterJob {
}
Media media = (Media)attSet.get(Media.class);
if (media == null) {
media =
(Media)service.getDefaultAttributeValue(Media.class);
}
if (!(media instanceof MediaSizeName)) {
media = MediaSizeName.NA_LETTER;
}
MediaSize size =
MediaSize.getMediaSizeForName((MediaSizeName)media);
if (size == null) {
size = MediaSize.NA.LETTER;
}
MediaSize size = getMediaSize(media, service, page);
Paper paper = new Paper();
float dim[] = size.getSize(1); //units == 1 to avoid FP error
double w = Math.rint((dim[0]*72.0)/Size2DSyntax.INCH);
@ -579,40 +569,58 @@ public abstract class RasterPrinterJob extends PrinterJob {
MediaPrintableArea area =
(MediaPrintableArea)
attSet.get(MediaPrintableArea.class);
double ix, iw, iy, ih;
if (area == null) {
area = getDefaultPrintableArea(page, w, h);
}
if (area != null) {
// Should pass in same unit as updatePageAttributes
// to avoid rounding off errors.
ix = Math.rint(
area.getX(MediaPrintableArea.INCH) * DPI);
iy = Math.rint(
area.getY(MediaPrintableArea.INCH) * DPI);
iw = Math.rint(
area.getWidth(MediaPrintableArea.INCH) * DPI);
ih = Math.rint(
area.getHeight(MediaPrintableArea.INCH) * DPI);
}
else {
if (w >= 72.0 * 6.0) {
ix = 72.0;
iw = w - 2 * 72.0;
} else {
ix = w / 6.0;
iw = w * 0.75;
}
if (h >= 72.0 * 6.0) {
iy = 72.0;
ih = h - 2 * 72.0;
} else {
iy = h / 6.0;
ih = h * 0.75;
}
}
double ix, iw, iy, ih;
// Should pass in same unit as updatePageAttributes
// to avoid rounding off errors.
ix = Math.rint(
area.getX(MediaPrintableArea.INCH) * DPI);
iy = Math.rint(
area.getY(MediaPrintableArea.INCH) * DPI);
iw = Math.rint(
area.getWidth(MediaPrintableArea.INCH) * DPI);
ih = Math.rint(
area.getHeight(MediaPrintableArea.INCH) * DPI);
paper.setImageableArea(ix, iy, iw, ih);
page.setPaper(paper);
return page;
}
protected MediaSize getMediaSize(Media media, PrintService service,
PageFormat page) {
if (media == null) {
media = (Media)service.getDefaultAttributeValue(Media.class);
}
if (!(media instanceof MediaSizeName)) {
media = MediaSizeName.NA_LETTER;
}
MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media);
return size != null ? size : MediaSize.NA.LETTER;
}
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
double w, double h) {
double ix, iw, iy, ih;
if (w >= 72.0 * 6.0) {
ix = 72.0;
iw = w - 2 * 72.0;
} else {
ix = w / 6.0;
iw = w * 0.75;
}
if (h >= 72.0 * 6.0) {
iy = 72.0;
ih = h - 2 * 72.0;
} else {
iy = h / 6.0;
ih = h * 0.75;
}
return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
(float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
protected void updatePageAttributes(PrintService service,
PageFormat page) {
@ -809,7 +817,7 @@ public abstract class RasterPrinterJob extends PrinterJob {
}
protected PageFormat getPageFormatFromAttributes() {
if (attributes == null) {
if (attributes == null || attributes.isEmpty()) {
return null;
}
return attributeToPageFormat(getPrintService(), this.attributes);