KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > PageSize


1 /*
2  * $Id: PageSize.java 2748 2007-05-12 15:11:48Z blowagie $
3  * $Name$
4  *
5  * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text;
52
53 import java.lang.reflect.Field JavaDoc;
54
55 /**
56  * The <CODE>PageSize</CODE>-object contains a number of rectangles representing the most common papersizes.
57  *
58  * @see Rectangle
59  */

60
61 public class PageSize {
62     
63     // membervariables
64

65     /** This is the letter format */
66     public static final Rectangle LETTER = new Rectangle(612,792);
67     
68     /** This is the note format */
69     public static final Rectangle NOTE = new Rectangle(540,720);
70     
71     /** This is the legal format */
72     public static final Rectangle LEGAL = new Rectangle(612,1008);
73     
74     /** This is the tabloid format */
75     public static final Rectangle TABLOID = new Rectangle(792,1224);
76
77     /** This is the executive format */
78     public static final Rectangle EXECUTIVE = new Rectangle(522,756);
79
80     /** This is the postcard format */
81     public static final Rectangle POSTCARD = new Rectangle(283,416);
82     
83     /** This is the a0 format */
84     public static final Rectangle A0 = new Rectangle(2384,3370);
85     
86     /** This is the a1 format */
87     public static final Rectangle A1 = new Rectangle(1684,2384);
88     
89     /** This is the a2 format */
90     public static final Rectangle A2 = new Rectangle(1191,1684);
91     
92     /** This is the a3 format */
93     public static final Rectangle A3 = new Rectangle(842,1191);
94     
95     /** This is the a4 format */
96     public static final Rectangle A4 = new Rectangle(595,842);
97     
98     /** This is the a5 format */
99     public static final Rectangle A5 = new Rectangle(420,595);
100     
101     /** This is the a6 format */
102     public static final Rectangle A6 = new Rectangle(297,420);
103     
104     /** This is the a7 format */
105     public static final Rectangle A7 = new Rectangle(210,297);
106     
107     /** This is the a8 format */
108     public static final Rectangle A8 = new Rectangle(148,210);
109     
110     /** This is the a9 format */
111     public static final Rectangle A9 = new Rectangle(105,148);
112     
113     /** This is the a10 format */
114     public static final Rectangle A10 = new Rectangle(73,105);
115     
116     /** This is the b0 format */
117     public static final Rectangle B0 = new Rectangle(2834,4008);
118     
119     /** This is the b1 format */
120     public static final Rectangle B1 = new Rectangle(2004,2834);
121     
122     /** This is the b2 format */
123     public static final Rectangle B2 = new Rectangle(1417,2004);
124     
125     /** This is the b3 format */
126     public static final Rectangle B3 = new Rectangle(1000,1417);
127     
128     /** This is the b4 format */
129     public static final Rectangle B4 = new Rectangle(708,1000);
130     
131     /** This is the b5 format */
132     public static final Rectangle B5 = new Rectangle(498,708);
133
134     /** This is the b6 format */
135     public static final Rectangle B6 = new Rectangle(354,498);
136     
137     /** This is the b7 format */
138     public static final Rectangle B7 = new Rectangle(249,354);
139     
140     /** This is the b8 format */
141     public static final Rectangle B8 = new Rectangle(175,249);
142
143     /** This is the b9 format */
144     public static final Rectangle B9 = new Rectangle(124,175);
145
146     /** This is the b10 format */
147     public static final Rectangle B10 = new Rectangle(87,124);
148     
149     /** This is the archE format */
150     public static final Rectangle ARCH_E = new Rectangle(2592,3456);
151     
152     /** This is the archD format */
153     public static final Rectangle ARCH_D = new Rectangle(1728,2592);
154     
155     /** This is the archC format */
156     public static final Rectangle ARCH_C = new Rectangle(1296,1728);
157     
158     /** This is the archB format */
159     public static final Rectangle ARCH_B = new Rectangle(864,1296);
160     
161     /** This is the archA format */
162     public static final Rectangle ARCH_A = new Rectangle(648,864);
163     
164     /** This is the American Foolscap format */
165     public static final Rectangle FLSA = new Rectangle(612,936);
166     
167     /** This is the European Foolscap format */
168     public static final Rectangle FLSE = new Rectangle(648,936);
169     
170     /** This is the halfletter format */
171     public static final Rectangle HALFLETTER = new Rectangle(396,612);
172     
173     /** This is the 11x17 format */
174     public static final Rectangle _11X17 = new Rectangle(792,1224);
175     
176     /** This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch) */
177     public static final Rectangle ID_1 = new Rectangle(242.65f,153);
178     
179     /** This is the ISO 7810 ID-2 format (A7 rotated) */
180     public static final Rectangle ID_2 = new Rectangle(297,210);
181     
182     /** This is the ISO 7810 ID-3 format (B7 rotated) */
183     public static final Rectangle ID_3 = new Rectangle(354,249);
184     
185     /** This is the ledger format */
186     public static final Rectangle LEDGER = new Rectangle(1224,792);
187     
188     /** This is the Crown Quarto format */
189     public static final Rectangle CROWN_QUARTO = new Rectangle(535,697);
190
191     /** This is the Large Crown Quarto format */
192     public static final Rectangle LARGE_CROWN_QUARTO = new Rectangle(569,731);
193     
194     /** This is the Demy Quarto format. */
195     public static final Rectangle DEMY_QUARTO = new Rectangle(620,782);
196     
197     /** This is the Royal Quarto format. */
198     public static final Rectangle ROYAL_QUARTO = new Rectangle(671,884);
199     
200     /** This is the Crown Octavo format */
201     public static final Rectangle CROWN_OCTAVO = new Rectangle(348,527);
202     
203     /** This is the Large Crown Octavo format */
204     public static final Rectangle LARGE_CROWN_OCTAVO = new Rectangle(365,561);
205     
206     /** This is the Demy Octavo format */
207     public static final Rectangle DEMY_OCTAVO = new Rectangle(391,612);
208     
209     /** This is the Royal Octavo format. */
210     public static final Rectangle ROYAL_OCTAVO = new Rectangle(442,663);
211     
212     /** This is the small paperback format. */
213     public static final Rectangle SMALL_PAPERBACK = new Rectangle(314,504);
214     
215     /** This is the Pengiun small paperback format. */
216     public static final Rectangle PENGUIN_SMALL_PAPERBACK = new Rectangle(314,513);
217     
218     /** This is the Penguin large paparback format. */
219     public static final Rectangle PENGUIN_LARGE_PAPERBACK = new Rectangle(365,561);
220       
221     /**
222      * This method returns a Rectangle based on a String.
223      * Possible values are the the names of a constant in this class
224      * (for instance "A4", "LETTER",...) or a value like "595 842"
225      */

226     public static Rectangle getRectangle(String JavaDoc name) {
227         name = name.trim().toUpperCase();
228         int pos = name.indexOf(' ');
229         if (pos == -1) {
230             try {
231                 Field JavaDoc field = PageSize.class.getDeclaredField(name.toUpperCase());
232                 return (Rectangle) field.get(null);
233             } catch (Exception JavaDoc e) {
234                 throw new RuntimeException JavaDoc("Can't find page size " + name);
235             }
236         }
237         else {
238             try {
239                 String JavaDoc width = name.substring(0, pos);
240                 String JavaDoc height = name.substring(pos + 1);
241                 return new Rectangle(Float.parseFloat(width), Float.parseFloat(height));
242             } catch(Exception JavaDoc e) {
243                 throw new RuntimeException JavaDoc(name + " is not a valid page size format; " + e.getMessage());
244             }
245         }
246     }
247 }
Popular Tags