Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 25 additions & 73 deletions src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,31 @@ private boolean jobSetup(Pageable doc) {

/**
* validate the paper size against the current printer.
* This method does not take into account an actual paper orientation,
* the portrait orientation is used.
*/
@Override
protected native void validatePaper(Paper origPaper, Paper newPaper );
protected void validatePaper(Paper origPaper, Paper newPaper ) {
validatePaper(origPaper, newPaper, PageFormat.PORTRAIT);
}


/**
* The passed in PageFormat is cloned and altered to be usable on
* the PrinterJob's current printer.
* This method takes into account the printing orientation.
*/
@Override
public PageFormat validatePage(PageFormat page) {
PageFormat newPage = (PageFormat)page.clone();
Paper newPaper = new Paper();
validatePaper(newPage.getPaper(), newPaper, page.getOrientation());
newPage.setPaper(newPaper);

return newPage;
}

private native void validatePaper(Paper origPaper, Paper newPaper, int orientation);

// The following methods are CPrinterJob specific.

Expand Down Expand Up @@ -692,7 +714,7 @@ private PageFormat getPageFormat(int pageIndex) {
return null;
}

return FlipPageFormat.flipPage(page);
return page;
}

private Printable getPrintable(int pageIndex) {
Expand Down Expand Up @@ -850,7 +872,7 @@ private void printToPathGraphics( final PeekGraphics graphics, // Always an a
if (monochrome) {
pathGraphics = new GrayscaleProxyGraphics2D(pathGraphics, printerJob);
}
painter.print(pathGraphics, FlipPageFormat.getOriginal(page), pageIndex);
painter.print(pathGraphics, page, pageIndex);
synchronized (sd) {
sd.invalidate();
delegate.dispose();
Expand Down Expand Up @@ -1001,74 +1023,4 @@ protected MediaPrintableArea getDefaultPrintableArea(PageFormat page, double w,
MediaPrintableArea.INCH);
}

// MacOS NSPrintInfo class has one to one correspondence
// between a paper size and its orientation.
// NSPrintInfo with paper width less than height
// has portrait orientation.
// NSPrintInfo with paper width greater than height
// has landscape orientation.
// (w < h) <-> portrait
// (w > h) <-> landscape
//
// Java PageFormat class has the following relation with NSPrintInfo:
// 1. PageFormat:
// page size: width < height
// orientation: portrait
// NSPrintInfo: width < height (portrait orientation)
// 2. PageFormat:
// page size: width < height
// orientation: landscape
// NSPrintInfo: width > height (landscape orientation)
//
// FlipPageFormat class establishes correspondence between
// Java PageFormat class which page width is greater than height
// with NSPrintInfo in the following way:
// 3. PageFormat:
// page size: width > height
// orientation: portrait
// FlipPageFormat
// page size: width < height
// orientation: landscape
// NSPrintInfo: width > height (landscape orientation)
// 4. PageFormat:
// page size: width > height
// orientation: landscape
// FlipPageFormat
// page size: width < height
// orientation: portrait
// NSPrintInfo: width < height (portrait orientation)
//
// FlipPageFormat preserves the original PageFormat class
// to pass it to Printable.print(Graphics, PageFormat, int)
// method overridden by a user.
private static final class FlipPageFormat extends PageFormat {

private final PageFormat original;

private FlipPageFormat(PageFormat original) {
this.original = original;
Paper paper = original.getPaper();
Paper copyPaper = this.getPaper();
copyPaper.setSize(paper.getHeight(), paper.getWidth());
copyPaper.setImageableArea(
paper.getImageableY(), paper.getImageableX(),
paper.getImageableHeight(), paper.getImageableWidth());
this.setPaper(copyPaper);
this.setOrientation((original.getOrientation() == PageFormat.PORTRAIT)
? PageFormat.LANDSCAPE
: PageFormat.PORTRAIT);
}

private static PageFormat getOriginal(PageFormat page) {
return (page instanceof FlipPageFormat) ? ((FlipPageFormat) page).original : page;
}

private static PageFormat flipPage(PageFormat page) {
if (page == null) {
return null;
}
Paper paper = page.getPaper();
return (paper.getWidth() > paper.getHeight()) ? new FlipPageFormat(page) : page;
}
}
}
Loading