1 /*
2  * Copyright (c) 2007, 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 /**
25  * @bug 4186119: setting orientation does not affect printer
26  * @summary Confirm that the clip and transform of the Graphics2D is
27  *          affected by the landscape orientation of the PageFormat.
28  * @run applet/manual=yesno SetOrient.html
29  */
30 
31 import java.awt.*;
32 import java.awt.geom.*;
33 import java.awt.print.*;
34 import java.applet.Applet;
35 
36 public class SetOrient extends Applet implements Printable {
37     PrinterJob pjob;
38 
init()39     public void init() {
40         pjob = PrinterJob.getPrinterJob();
41 
42         Book book = new Book();
43         PageFormat pf = pjob.defaultPage();
44         pf.setOrientation(PageFormat.PORTRAIT);
45         book.append(this, pf);
46         pf = pjob.defaultPage();
47         pf.setOrientation(PageFormat.LANDSCAPE);
48         book.append(this, pf);
49         pjob.setPageable(book);
50 
51         try {
52             pjob.print();
53         } catch (PrinterException e) {
54             throw new RuntimeException(e.getMessage());
55         }
56     }
57 
print(Graphics g, PageFormat pf, int pageIndex)58     public int print(Graphics g, PageFormat pf, int pageIndex) {
59         Graphics2D g2d = (Graphics2D)g;
60         drawGraphics(g2d, pf);
61         return Printable.PAGE_EXISTS;
62     }
63 
drawGraphics(Graphics2D g, PageFormat pf)64     void drawGraphics(Graphics2D g, PageFormat pf) {
65         double ix = pf.getImageableX();
66         double iy = pf.getImageableY();
67         double iw = pf.getImageableWidth();
68         double ih = pf.getImageableHeight();
69 
70         g.setColor(Color.black);
71         g.drawString(((pf.getOrientation() == PageFormat.PORTRAIT)
72                       ? "Portrait" : "Landscape"),
73                      (int) (ix+iw/2), (int) (iy+ih/2));
74         g.draw(new Ellipse2D.Double(ix, iy, iw, ih));
75     }
76 }
77