< prev index next >

test/java/awt/print/PrinterJob/Margins.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,39 **** * questions. */ /** * @test ! * @bug 6543815 * @summary Image should be sent to printer, no exceptions thrown. ! * The 2 printouts should have a rectangle which is the minimum ! * possible margin. * @run main/manual Margins */ ! import java.awt.*; ! import java.awt.print.*; public class Margins implements Printable { public static void main(String args[]) { PrinterJob job = PrinterJob.getPrinterJob(); --- 21,46 ---- * questions. */ /** * @test ! * @bug 6543815 6601097 * @summary Image should be sent to printer, no exceptions thrown. ! * The 3 printouts should have a rectangle which is the minimum ! * possible margins ie, the margins should be hardware margins ! * and not java default 1 inch margins. * @run main/manual Margins */ ! import java.awt.print.PrinterJob; ! import java.awt.print.Printable; ! import java.awt.print.PageFormat; ! import java.awt.print.Paper; ! import java.awt.print.PrinterException; ! import java.awt.Graphics; ! import java.awt.Graphics2D; ! import java.awt.Color; public class Margins implements Printable { public static void main(String args[]) { PrinterJob job = PrinterJob.getPrinterJob();
*** 57,66 **** --- 64,88 ---- job.setPrintable(new Margins(), pageFormat); try { job.print(); } catch (PrinterException e) { } + + pageFormat = job.defaultPage(); + paper = pageFormat.getPaper(); + wid = paper.getWidth(); + hgt = paper.getHeight(); + + paper.setImageableArea(0, -10, -wid, hgt); + pageFormat = job.pageDialog(pageFormat); + pageFormat.setPaper(paper); + + job.setPrintable(new Margins(), pageFormat); + try { + job.print(); + } catch (PrinterException e) { + } } public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
*** 74,87 **** --- 96,117 ---- System.out.println("ix="+ix+" iy="+iy+" iw="+iw+" ih="+ih); if ((ix < 0) || (iy < 0)) { throw new RuntimeException("Imageable x or y is a negative value."); } + Paper paper = pf.getPaper(); double wid = paper.getWidth(); double hgt = paper.getHeight(); + // If imageable width/height is -ve, then print was done with 1" margin + // ie ix=72 iy=72 iw=451 ih=697 and wid=595 + // but with fix, we get print with hardware margin ie + // ix=12, iy=12, iw=571, ih=817 + if ((wid - iw > 72) || (hgt - ih > 72)) { + throw new RuntimeException("Imageable width or height is negative value"); + } if ((ix+iw > wid) || (iy+ih > hgt)) { throw new RuntimeException("Printable width or height exceeds paper width or height."); } Graphics2D g2d = (Graphics2D)g;
< prev index next >