use of java.awt.print.Paper in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method validatePage.
/**
* The passed in PageFormat is cloned and altered to be usable on
* the PrinterJob's current printer.
*/
public PageFormat validatePage(PageFormat page) {
PageFormat newPage = (PageFormat) page.clone();
Paper newPaper = new Paper();
validatePaper(newPage.getPaper(), newPaper);
newPage.setPaper(newPaper);
return newPage;
}
use of java.awt.print.Paper in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method defaultPage.
/**
* The passed in PageFormat will be copied and altered to describe
* the default page size and orientation of the PrinterJob's
* current printer.
* Platform subclasses which can access the actual default paper size
* for a printer may override this method.
*/
public PageFormat defaultPage(PageFormat page) {
PageFormat newPage = (PageFormat) page.clone();
newPage.setOrientation(PageFormat.PORTRAIT);
Paper newPaper = new Paper();
double ptsPerInch = 72.0;
double w, h;
Media media = null;
PrintService service = getPrintService();
if (service != null) {
MediaSize size;
media = (Media) service.getDefaultAttributeValue(Media.class);
if (media instanceof MediaSizeName && ((size = MediaSize.getMediaSizeForName((MediaSizeName) media)) != null)) {
w = size.getX(MediaSize.INCH) * ptsPerInch;
h = size.getY(MediaSize.INCH) * ptsPerInch;
newPaper.setSize(w, h);
newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
newPage.setPaper(newPaper);
return newPage;
}
}
/* Default to A4 paper outside North America.
*/
String defaultCountry = Locale.getDefault().getCountry();
if (// ie "C"
!Locale.getDefault().equals(Locale.ENGLISH) && defaultCountry != null && !defaultCountry.equals(Locale.US.getCountry()) && !defaultCountry.equals(Locale.CANADA.getCountry())) {
double mmPerInch = 25.4;
w = Math.rint((210.0 * ptsPerInch) / mmPerInch);
h = Math.rint((297.0 * ptsPerInch) / mmPerInch);
newPaper.setSize(w, h);
newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
}
newPage.setPaper(newPaper);
return newPage;
}
use of java.awt.print.Paper in project jgnash by ccavanaugh.
the class ReportPrintFactory method getPageFormat.
static PageFormat getPageFormat(final BaseDynamicJasperReport report) {
Preferences p = report.getPreferences();
double height = p.getDouble(HEIGHT, 0);
double width = p.getDouble(WIDTH, 0);
int orientation = p.getInt(ORIENTATION, 0);
double imageableHeight = p.getDouble(IMAGEABLE_HEIGHT, 0);
double imageableWidth = p.getDouble(IMAGEABLE_WIDTH, 0);
double imageableX = p.getDouble(IMAGEABLE_X, 0);
double imageableY = p.getDouble(IMAGEABLE_Y, 0);
if (height == 0 || width == 0 || imageableHeight == 0 || imageableWidth == 0) {
return getDefaultPage();
}
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
pf.setOrientation(orientation);
Paper paper = pf.getPaper();
paper.setSize(width, height);
paper.setImageableArea(imageableX, imageableY, imageableWidth, imageableHeight);
pf.setPaper(paper);
return pf;
}
use of java.awt.print.Paper in project jgnash by ccavanaugh.
the class ReportPrintFactory method savePageFormat.
/**
* Save a {@code PageFormat} to preferences
*
* @param report report
* @param format {@code PageFormat} to save
*/
static void savePageFormat(final BaseDynamicJasperReport report, final PageFormat format) {
Preferences p = report.getPreferences();
p.putInt(ORIENTATION, format.getOrientation());
Paper paper = format.getPaper();
p.putDouble(HEIGHT, paper.getHeight());
p.putDouble(WIDTH, paper.getWidth());
p.putDouble(IMAGEABLE_HEIGHT, paper.getImageableHeight());
p.putDouble(IMAGEABLE_WIDTH, paper.getImageableWidth());
p.putDouble(IMAGEABLE_X, paper.getImageableX());
p.putDouble(IMAGEABLE_Y, paper.getImageableY());
}
use of java.awt.print.Paper in project jgnash by ccavanaugh.
the class ReportPrintFactory method getDefaultPage.
/**
* Returns the default paper size for a report
*
* @return page format
*/
private static PageFormat getDefaultPage() {
/* A4 is the assumed default */
MediaSize defaultMediaSize = MediaSize.ISO.A4;
/* US and Canada use letter size as the default */
Locale[] letterLocales = new Locale[] { Locale.US, Locale.CANADA, Locale.CANADA_FRENCH };
if (Arrays.asList(letterLocales).contains(Locale.getDefault())) {
defaultMediaSize = MediaSize.NA.LETTER;
}
/* Create the default paper size with a default margin */
Paper paper = new Paper();
int width = (int) (defaultMediaSize.getX(MediaSize.INCH) / (1f / 72f));
int height = (int) (defaultMediaSize.getY(MediaSize.INCH) / (1f / 72f));
paper.setSize(width, height);
paper.setImageableArea(DEFAULT_MARGIN, DEFAULT_MARGIN, width - (2 * DEFAULT_MARGIN), height - (2 * DEFAULT_MARGIN));
PageFormat format = new PageFormat();
format.setPaper(paper);
/* if a default printer is found, validate the page */
PrintService[] services = PrinterJob.lookupPrintServices();
if (services.length != 0) {
// no printers found on the system.
format = PrinterJob.getPrinterJob().validatePage(format);
}
return format;
}
Aggregations