1 /*
2 * $Id: PageSize.java 3373 2008-05-12 16:21:24Z xlv $
3 *
4 * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * (the "License"); you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the License.
13 *
14 * The Original Code is 'iText, a free JAVA-PDF library'.
15 *
16 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18 * All Rights Reserved.
19 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21 *
22 * Contributor(s): all the names of the contributors are added in the source code
23 * where applicable.
24 *
25 * Alternatively, the contents of this file may be used under the terms of the
26 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27 * provisions of LGPL are applicable instead of those above. If you wish to
28 * allow use of your version of this file only under the terms of the LGPL
29 * License and not to allow others to use your version of this file under
30 * the MPL, indicate your decision by deleting the provisions above and
31 * replace them with the notice and other provisions required by the LGPL.
32 * If you do not delete the provisions above, a recipient may use your version
33 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34 *
35 * This library is free software; you can redistribute it and/or modify it
36 * under the terms of the MPL as stated above or under the terms of the GNU
37 * Library General Public License as published by the Free Software Foundation;
38 * either version 2 of the License, or any later version.
39 *
40 * This library is distributed in the hope that it will be useful, but WITHOUT
41 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43 * details.
44 *
45 * If you didn't download this code from the following link, you should check if
46 * you aren't using an obsolete version:
47 * http://www.lowagie.com/iText/
48 */
49
50 package com.lowagie.text;
51
52 import java.lang.reflect.Field;
53
54 /**
55 * The <CODE>PageSize</CODE>-object contains a number of rectangles representing the most common paper sizes.
56 *
57 * @see Rectangle
58 */
59
60 public class PageSize {
61
62 // membervariables
63
64 /** This is the letter format */
65 public static final Rectangle LETTER = new RectangleReadOnly(612,792);
66
67 /** This is the note format */
68 public static final Rectangle NOTE = new RectangleReadOnly(540,720);
69
70 /** This is the legal format */
71 public static final Rectangle LEGAL = new RectangleReadOnly(612,1008);
72
73 /** This is the tabloid format */
74 public static final Rectangle TABLOID = new RectangleReadOnly(792,1224);
75
76 /** This is the executive format */
77 public static final Rectangle EXECUTIVE = new RectangleReadOnly(522,756);
78
79 /** This is the postcard format */
80 public static final Rectangle POSTCARD = new RectangleReadOnly(283,416);
81
82 /** This is the a0 format */
83 public static final Rectangle A0 = new RectangleReadOnly(2384,3370);
84
85 /** This is the a1 format */
86 public static final Rectangle A1 = new RectangleReadOnly(1684,2384);
87
88 /** This is the a2 format */
89 public static final Rectangle A2 = new RectangleReadOnly(1191,1684);
90
91 /** This is the a3 format */
92 public static final Rectangle A3 = new RectangleReadOnly(842,1191);
93
94 /** This is the a4 format */
95 public static final Rectangle A4 = new RectangleReadOnly(595,842);
96
97 /** This is the a5 format */
98 public static final Rectangle A5 = new RectangleReadOnly(420,595);
99
100 /** This is the a6 format */
101 public static final Rectangle A6 = new RectangleReadOnly(297,420);
102
103 /** This is the a7 format */
104 public static final Rectangle A7 = new RectangleReadOnly(210,297);
105
106 /** This is the a8 format */
107 public static final Rectangle A8 = new RectangleReadOnly(148,210);
108
109 /** This is the a9 format */
110 public static final Rectangle A9 = new RectangleReadOnly(105,148);
111
112 /** This is the a10 format */
113 public static final Rectangle A10 = new RectangleReadOnly(73,105);
114
115 /** This is the b0 format */
116 public static final Rectangle B0 = new RectangleReadOnly(2834,4008);
117
118 /** This is the b1 format */
119 public static final Rectangle B1 = new RectangleReadOnly(2004,2834);
120
121 /** This is the b2 format */
122 public static final Rectangle B2 = new RectangleReadOnly(1417,2004);
123
124 /** This is the b3 format */
125 public static final Rectangle B3 = new RectangleReadOnly(1000,1417);
126
127 /** This is the b4 format */
128 public static final Rectangle B4 = new RectangleReadOnly(708,1000);
129
130 /** This is the b5 format */
131 public static final Rectangle B5 = new RectangleReadOnly(498,708);
132
133 /** This is the b6 format */
134 public static final Rectangle B6 = new RectangleReadOnly(354,498);
135
136 /** This is the b7 format */
137 public static final Rectangle B7 = new RectangleReadOnly(249,354);
138
139 /** This is the b8 format */
140 public static final Rectangle B8 = new RectangleReadOnly(175,249);
141
142 /** This is the b9 format */
143 public static final Rectangle B9 = new RectangleReadOnly(124,175);
144
145 /** This is the b10 format */
146 public static final Rectangle B10 = new RectangleReadOnly(87,124);
147
148 /** This is the archE format */
149 public static final Rectangle ARCH_E = new RectangleReadOnly(2592,3456);
150
151 /** This is the archD format */
152 public static final Rectangle ARCH_D = new RectangleReadOnly(1728,2592);
153
154 /** This is the archC format */
155 public static final Rectangle ARCH_C = new RectangleReadOnly(1296,1728);
156
157 /** This is the archB format */
158 public static final Rectangle ARCH_B = new RectangleReadOnly(864,1296);
159
160 /** This is the archA format */
161 public static final Rectangle ARCH_A = new RectangleReadOnly(648,864);
162
163 /** This is the American Foolscap format */
164 public static final Rectangle FLSA = new RectangleReadOnly(612,936);
165
166 /** This is the European Foolscap format */
167 public static final Rectangle FLSE = new RectangleReadOnly(648,936);
168
169 /** This is the halfletter format */
170 public static final Rectangle HALFLETTER = new RectangleReadOnly(396,612);
171
172 /** This is the 11x17 format */
173 public static final Rectangle _11X17 = new RectangleReadOnly(792,1224);
174
175 /** This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch) */
176 public static final Rectangle ID_1 = new RectangleReadOnly(242.65f,153);
177
178 /** This is the ISO 7810 ID-2 format (A7 rotated) */
179 public static final Rectangle ID_2 = new RectangleReadOnly(297,210);
180
181 /** This is the ISO 7810 ID-3 format (B7 rotated) */
182 public static final Rectangle ID_3 = new RectangleReadOnly(354,249);
183
184 /** This is the ledger format */
185 public static final Rectangle LEDGER = new RectangleReadOnly(1224,792);
186
187 /** This is the Crown Quarto format */
188 public static final Rectangle CROWN_QUARTO = new RectangleReadOnly(535,697);
189
190 /** This is the Large Crown Quarto format */
191 public static final Rectangle LARGE_CROWN_QUARTO = new RectangleReadOnly(569,731);
192
193 /** This is the Demy Quarto format. */
194 public static final Rectangle DEMY_QUARTO = new RectangleReadOnly(620,782);
195
196 /** This is the Royal Quarto format. */
197 public static final Rectangle ROYAL_QUARTO = new RectangleReadOnly(671,884);
198
199 /** This is the Crown Octavo format */
200 public static final Rectangle CROWN_OCTAVO = new RectangleReadOnly(348,527);
201
202 /** This is the Large Crown Octavo format */
203 public static final Rectangle LARGE_CROWN_OCTAVO = new RectangleReadOnly(365,561);
204
205 /** This is the Demy Octavo format */
206 public static final Rectangle DEMY_OCTAVO = new RectangleReadOnly(391,612);
207
208 /** This is the Royal Octavo format. */
209 public static final Rectangle ROYAL_OCTAVO = new RectangleReadOnly(442,663);
210
211 /** This is the small paperback format. */
212 public static final Rectangle SMALL_PAPERBACK = new RectangleReadOnly(314,504);
213
214 /** This is the Pengiun small paperback format. */
215 public static final Rectangle PENGUIN_SMALL_PAPERBACK = new RectangleReadOnly(314,513);
216
217 /** This is the Penguin large paperback format. */
218 public static final Rectangle PENGUIN_LARGE_PAPERBACK = new RectangleReadOnly(365,561);
219
220 /**
221 * This method returns a Rectangle based on a String.
222 * Possible values are the the names of a constant in this class
223 * (for instance "A4", "LETTER",...) or a value like "595 842"
224 */
225 public static Rectangle getRectangle(String name) {
226 name = name.trim().toUpperCase();
227 int pos = name.indexOf(' ');
228 if (pos == -1) {
229 try {
230 Field field = PageSize.class.getDeclaredField(name.toUpperCase());
231 return (Rectangle) field.get(null);
232 } catch (Exception e) {
233 throw new RuntimeException("Can't find page size " + name);
234 }
235 }
236 else {
237 try {
238 String width = name.substring(0, pos);
239 String height = name.substring(pos + 1);
240 return new Rectangle(Float.parseFloat(width), Float.parseFloat(height));
241 } catch(Exception e) {
242 throw new RuntimeException(name + " is not a valid page size format; " + e.getMessage());
243 }
244 }
245 }
246 }