1 | /* | |
2 | * $Id: PageSize.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
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; | |
54 | import com.lowagie.text.error_messages.MessageLocalization; | |
55 | ||
56 | /** | |
57 | * The <CODE>PageSize</CODE>-object contains a number of rectangles representing the most common paper sizes. | |
58 | * | |
59 | * @see Rectangle | |
60 | */ | |
61 | ||
62 | public class PageSize { | |
63 | | |
64 | // membervariables | |
65 | | |
66 | /** This is the letter format */ | |
67 | public static final Rectangle LETTER = new RectangleReadOnly(612,792); | |
68 | | |
69 | /** This is the note format */ | |
70 | public static final Rectangle NOTE = new RectangleReadOnly(540,720); | |
71 | | |
72 | /** This is the legal format */ | |
73 | public static final Rectangle LEGAL = new RectangleReadOnly(612,1008); | |
74 | | |
75 | /** This is the tabloid format */ | |
76 | public static final Rectangle TABLOID = new RectangleReadOnly(792,1224); | |
77 | ||
78 | /** This is the executive format */ | |
79 | public static final Rectangle EXECUTIVE = new RectangleReadOnly(522,756); | |
80 | ||
81 | /** This is the postcard format */ | |
82 | public static final Rectangle POSTCARD = new RectangleReadOnly(283,416); | |
83 | | |
84 | /** This is the a0 format */ | |
85 | public static final Rectangle A0 = new RectangleReadOnly(2384,3370); | |
86 | | |
87 | /** This is the a1 format */ | |
88 | public static final Rectangle A1 = new RectangleReadOnly(1684,2384); | |
89 | | |
90 | /** This is the a2 format */ | |
91 | public static final Rectangle A2 = new RectangleReadOnly(1191,1684); | |
92 | | |
93 | /** This is the a3 format */ | |
94 | public static final Rectangle A3 = new RectangleReadOnly(842,1191); | |
95 | | |
96 | /** This is the a4 format */ | |
97 | public static final Rectangle A4 = new RectangleReadOnly(595,842); | |
98 | | |
99 | /** This is the a5 format */ | |
100 | public static final Rectangle A5 = new RectangleReadOnly(420,595); | |
101 | | |
102 | /** This is the a6 format */ | |
103 | public static final Rectangle A6 = new RectangleReadOnly(297,420); | |
104 | | |
105 | /** This is the a7 format */ | |
106 | public static final Rectangle A7 = new RectangleReadOnly(210,297); | |
107 | | |
108 | /** This is the a8 format */ | |
109 | public static final Rectangle A8 = new RectangleReadOnly(148,210); | |
110 | | |
111 | /** This is the a9 format */ | |
112 | public static final Rectangle A9 = new RectangleReadOnly(105,148); | |
113 | | |
114 | /** This is the a10 format */ | |
115 | public static final Rectangle A10 = new RectangleReadOnly(73,105); | |
116 | | |
117 | /** This is the b0 format */ | |
118 | public static final Rectangle B0 = new RectangleReadOnly(2834,4008); | |
119 | | |
120 | /** This is the b1 format */ | |
121 | public static final Rectangle B1 = new RectangleReadOnly(2004,2834); | |
122 | | |
123 | /** This is the b2 format */ | |
124 | public static final Rectangle B2 = new RectangleReadOnly(1417,2004); | |
125 | | |
126 | /** This is the b3 format */ | |
127 | public static final Rectangle B3 = new RectangleReadOnly(1000,1417); | |
128 | | |
129 | /** This is the b4 format */ | |
130 | public static final Rectangle B4 = new RectangleReadOnly(708,1000); | |
131 | | |
132 | /** This is the b5 format */ | |
133 | public static final Rectangle B5 = new RectangleReadOnly(498,708); | |
134 | ||
135 | /** This is the b6 format */ | |
136 | public static final Rectangle B6 = new RectangleReadOnly(354,498); | |
137 | | |
138 | /** This is the b7 format */ | |
139 | public static final Rectangle B7 = new RectangleReadOnly(249,354); | |
140 | | |
141 | /** This is the b8 format */ | |
142 | public static final Rectangle B8 = new RectangleReadOnly(175,249); | |
143 | ||
144 | /** This is the b9 format */ | |
145 | public static final Rectangle B9 = new RectangleReadOnly(124,175); | |
146 | ||
147 | /** This is the b10 format */ | |
148 | public static final Rectangle B10 = new RectangleReadOnly(87,124); | |
149 | | |
150 | /** This is the archE format */ | |
151 | public static final Rectangle ARCH_E = new RectangleReadOnly(2592,3456); | |
152 | | |
153 | /** This is the archD format */ | |
154 | public static final Rectangle ARCH_D = new RectangleReadOnly(1728,2592); | |
155 | | |
156 | /** This is the archC format */ | |
157 | public static final Rectangle ARCH_C = new RectangleReadOnly(1296,1728); | |
158 | | |
159 | /** This is the archB format */ | |
160 | public static final Rectangle ARCH_B = new RectangleReadOnly(864,1296); | |
161 | | |
162 | /** This is the archA format */ | |
163 | public static final Rectangle ARCH_A = new RectangleReadOnly(648,864); | |
164 | | |
165 | /** This is the American Foolscap format */ | |
166 | public static final Rectangle FLSA = new RectangleReadOnly(612,936); | |
167 | | |
168 | /** This is the European Foolscap format */ | |
169 | public static final Rectangle FLSE = new RectangleReadOnly(648,936); | |
170 | | |
171 | /** This is the halfletter format */ | |
172 | public static final Rectangle HALFLETTER = new RectangleReadOnly(396,612); | |
173 | | |
174 | /** This is the 11x17 format */ | |
175 | public static final Rectangle _11X17 = new RectangleReadOnly(792,1224); | |
176 | | |
177 | /** This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch) */ | |
178 | public static final Rectangle ID_1 = new RectangleReadOnly(242.65f,153); | |
179 | | |
180 | /** This is the ISO 7810 ID-2 format (A7 rotated) */ | |
181 | public static final Rectangle ID_2 = new RectangleReadOnly(297,210); | |
182 | | |
183 | /** This is the ISO 7810 ID-3 format (B7 rotated) */ | |
184 | public static final Rectangle ID_3 = new RectangleReadOnly(354,249); | |
185 | | |
186 | /** This is the ledger format */ | |
187 | public static final Rectangle LEDGER = new RectangleReadOnly(1224,792); | |
188 | | |
189 | /** This is the Crown Quarto format */ | |
190 | public static final Rectangle CROWN_QUARTO = new RectangleReadOnly(535,697); | |
191 | ||
192 | /** This is the Large Crown Quarto format */ | |
193 | public static final Rectangle LARGE_CROWN_QUARTO = new RectangleReadOnly(569,731); | |
194 | | |
195 | /** This is the Demy Quarto format. */ | |
196 | public static final Rectangle DEMY_QUARTO = new RectangleReadOnly(620,782); | |
197 | | |
198 | /** This is the Royal Quarto format. */ | |
199 | public static final Rectangle ROYAL_QUARTO = new RectangleReadOnly(671,884); | |
200 | | |
201 | /** This is the Crown Octavo format */ | |
202 | public static final Rectangle CROWN_OCTAVO = new RectangleReadOnly(348,527); | |
203 | | |
204 | /** This is the Large Crown Octavo format */ | |
205 | public static final Rectangle LARGE_CROWN_OCTAVO = new RectangleReadOnly(365,561); | |
206 | | |
207 | /** This is the Demy Octavo format */ | |
208 | public static final Rectangle DEMY_OCTAVO = new RectangleReadOnly(391,612); | |
209 | | |
210 | /** This is the Royal Octavo format. */ | |
211 | public static final Rectangle ROYAL_OCTAVO = new RectangleReadOnly(442,663); | |
212 | | |
213 | /** This is the small paperback format. */ | |
214 | public static final Rectangle SMALL_PAPERBACK = new RectangleReadOnly(314,504); | |
215 | | |
216 | /** This is the Pengiun small paperback format. */ | |
217 | public static final Rectangle PENGUIN_SMALL_PAPERBACK = new RectangleReadOnly(314,513); | |
218 | | |
219 | /** This is the Penguin large paperback format. */ | |
220 | public static final Rectangle PENGUIN_LARGE_PAPERBACK = new RectangleReadOnly(365,561); | |
221 | | |
222 | /** | |
223 | * This method returns a Rectangle based on a String. | |
224 | * Possible values are the the names of a constant in this class | |
225 | * (for instance "A4", "LETTER",...) or a value like "595 842" | |
226 | */ | |
227 | public static Rectangle getRectangle(String name) { | |
228 | name = name.trim().toUpperCase(); | |
229 | int pos = name.indexOf(' '); | |
230 |
1
1. getRectangle : negated conditional → NO_COVERAGE |
if (pos == -1) { |
231 | try { | |
232 | Field field = PageSize.class.getDeclaredField(name.toUpperCase()); | |
233 |
1
1. getRectangle : mutated return of Object value for com/lowagie/text/PageSize::getRectangle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (Rectangle) field.get(null); |
234 | } catch (Exception e) { | |
235 | throw new RuntimeException(MessageLocalization.getComposedMessage("can.t.find.page.size.1", name)); | |
236 | } | |
237 | } | |
238 | else { | |
239 | try { | |
240 | String width = name.substring(0, pos); | |
241 |
1
1. getRectangle : Replaced integer addition with subtraction → NO_COVERAGE |
String height = name.substring(pos + 1); |
242 |
1
1. getRectangle : mutated return of Object value for com/lowagie/text/PageSize::getRectangle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Rectangle(Float.parseFloat(width), Float.parseFloat(height)); |
243 | } catch(Exception e) { | |
244 | throw new RuntimeException(MessageLocalization.getComposedMessage("1.is.not.a.valid.page.size.format.2", name, e.getMessage())); | |
245 | } | |
246 | } | |
247 | } | |
248 | } | |
Mutations | ||
230 |
1.1 |
|
233 |
1.1 |
|
241 |
1.1 |
|
242 |
1.1 |