1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * @test 25 * @bug 6789262 26 * @summary Verifies if getPageFormat returns correct mediaprintable value 27 * @run main TestPgfmtSetMPA 28 */ 29 import java.awt.print.PageFormat; 30 import java.awt.print.PrinterJob; 31 import javax.print.attribute.HashPrintRequestAttributeSet; 32 import javax.print.attribute.PrintRequestAttributeSet; 33 import javax.print.attribute.standard.MediaPrintableArea; 34 35 public class TestPgfmtSetMPA { 36 37 public static void main(String args[]) { 38 PrinterJob job; 39 40 job = PrinterJob.getPrinterJob(); 41 42 PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); 43 44 // Here you could see the PageFormat with an empty PrintRequestAttributeSet 45 PageFormat pf2 = job.getPageFormat(pras); 46 System.out.println((pf2.getImageableX() / 72f) + " " 47 + (pf2.getImageableY() / 72f) + " " 48 + (pf2.getImageableWidth() / 72f) + " " 49 + (pf2.getImageableHeight() / 72f) 50 ); 51 52 // Set left margin to 2.0 53 pras.add(new MediaPrintableArea(2.0f, 54 (float)(pf2.getImageableY() / 72f), 55 (float) ((pf2.getImageableWidth() / 72f) - 1.0f), 56 (float) (pf2.getImageableHeight() / 72f), 57 MediaPrintableArea.INCH)); 58 59 pf2 = job.getPageFormat(pras); 60 System.out.println((pf2.getImageableX() / 72f) + " " 61 + (pf2.getImageableY() / 72f) + " " 62 + (pf2.getImageableWidth() / 72f) + " " 63 + (pf2.getImageableHeight() / 72f) 64 ); 65 66 // check if returned left margin of imageable area is 2.0 as set earlier 67 if (pf2.getImageableX() / 72f != 2.0f) { 68 throw new RuntimeException("getPageFormat doesn't apply specified " 69 + "MediaPrintableArea attribute"); 70 } 71 } 72 }