Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Paper | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setSize | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
getWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getHeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Style; |
19 | |
20 | use PhpOffice\PhpWord\Shared\Converter; |
21 | |
22 | /** |
23 | * Paper size from ISO/IEC 29500-1:2012 pg. 1656-1657. |
24 | * |
25 | * 1 = Letter paper (8.5 in. by 11 in.) |
26 | * 2 = Letter small paper (8.5 in. by 11 in.) |
27 | * 3 = Tabloid paper (11 in. by 17 in.) |
28 | * 4 = Ledger paper (17 in. by 11 in.) |
29 | * 5 = Legal paper (8.5 in. by 14 in.) |
30 | * 6 = Statement paper (5.5 in. by 8.5 in.) |
31 | * 7 = Executive paper (7.25 in. by 10.5 in.) |
32 | * 8 = A3 paper (297 mm by 420 mm) |
33 | * 9 = A4 paper (210 mm by 297 mm) |
34 | * 10 = A4 small paper (210 mm by 297 mm) |
35 | * 11 = A5 paper (148 mm by 210 mm) |
36 | * 12 = B4 paper (250 mm by 353 mm) |
37 | * 13 = B5 paper (176 mm by 250 mm) |
38 | * 14 = Folio paper (8.5 in. by 13 in.) |
39 | * 15 = Quarto paper (215 mm by 275 mm) |
40 | * 16 = Standard paper (10 in. by 14 in.) |
41 | * 17 = Standard paper (11 in. by 17 in.) |
42 | * 18 = Note paper (8.5 in. by 11 in.) |
43 | * 19 = #9 envelope (3.875 in. by 8.875 in.) |
44 | * 20 = #10 envelope (4.125 in. by 9.5 in.) |
45 | * 21 = #11 envelope (4.5 in. by 10.375 in.) |
46 | * 22 = #12 envelope (4.75 in. by 11 in.) |
47 | * 23 = #14 envelope (5 in. by 11.5 in.) |
48 | * 24 = C paper (17 in. by 22 in.) |
49 | * 25 = D paper (22 in. by 34 in.) |
50 | * 26 = E paper (34 in. by 44 in.) |
51 | * 27 = DL envelope (110 mm by 220 mm) |
52 | * 28 = C5 envelope (162 mm by 229 mm) |
53 | * 29 = C3 envelope (324 mm by 458 mm) |
54 | * 30 = C4 envelope (229 mm by 324 mm) |
55 | * 31 = C6 envelope (114 mm by 162 mm) |
56 | * 32 = C65 envelope (114 mm by 229 mm) |
57 | * 33 = B4 envelope (250 mm by 353 mm) |
58 | * 34 = B5 envelope (176 mm by 250 mm) |
59 | * 35 = B6 envelope (176 mm by 125 mm) |
60 | * 36 = Italy envelope (110 mm by 230 mm) |
61 | * 37 = Monarch envelope (3.875 in. by 7.5 in.). |
62 | * 38 = 6 3/4 envelope (3.625 in. by 6.5 in.) |
63 | * 39 = US standard fanfold (14.875 in. by 11 in.) |
64 | * 40 = German standard fanfold (8.5 in. by 12 in.) |
65 | * 41 = German legal fanfold (8.5 in. by 13 in.) |
66 | * 42 = ISO B4 (250 mm by 353 mm) |
67 | * 43 = Japanese double postcard (200 mm by 148 mm) |
68 | * 44 = Standard paper (9 in. by 11 in.) |
69 | * 45 = Standard paper (10 in. by 11 in.) |
70 | * 46 = Standard paper (15 in. by 11 in.) |
71 | * 47 = Invite envelope (220 mm by 220 mm) |
72 | * 50 = Letter extra paper (9.275 in. by 12 in.) |
73 | * 51 = Legal extra paper (9.275 in. by 15 in.) |
74 | * 52 = Tabloid extra paper (11.69 in. by 18 in.) |
75 | * 53 = A4 extra paper (236 mm by 322 mm) |
76 | * 54 = Letter transverse paper (8.275 in. by 11 in.) |
77 | * 55 = A4 transverse paper (210 mm by 297 mm) |
78 | * 56 = Letter extra transverse paper (9.275 in. by 12 in.) |
79 | * 57 = SuperA/SuperA/A4 paper (227 mm by 356 mm) |
80 | * 58 = SuperB/SuperB/A3 paper (305 mm by 487 mm) |
81 | * 59 = Letter plus paper (8.5 in. by 12.69 in.) |
82 | * 60 = A4 plus paper (210 mm by 330 mm) |
83 | * 61 = A5 transverse paper (148 mm by 210 mm) |
84 | * 62 = JIS B5 transverse paper (182 mm by 257 mm) |
85 | * 63 = A3 extra paper (322 mm by 445 mm) |
86 | * 64 = A5 extra paper (174 mm by 235 mm) |
87 | * 65 = ISO B5 extra paper (201 mm by 276 mm) |
88 | * 66 = A2 paper (420 mm by 594 mm) |
89 | * 67 = A3 transverse paper (297 mm by 420 mm) |
90 | * 68 = A3 extra transverse paper (322 mm by 445 mm) |
91 | * |
92 | * @since 0.12.0 |
93 | */ |
94 | class Paper extends AbstractStyle |
95 | { |
96 | /** |
97 | * Paper sizes. |
98 | * |
99 | * @var array |
100 | */ |
101 | private $sizes = [ |
102 | 'A3' => [297, 420, 'mm'], |
103 | 'A4' => [210, 297, 'mm'], |
104 | 'A5' => [148, 210, 'mm'], |
105 | 'B5' => [176, 250, 'mm'], |
106 | 'Folio' => [8.5, 13, 'in'], |
107 | 'Legal' => [8.5, 14, 'in'], |
108 | 'Letter' => [8.5, 11, 'in'], |
109 | ]; |
110 | |
111 | /** |
112 | * Paper size. |
113 | * |
114 | * @var string |
115 | */ |
116 | private $size = 'A4'; |
117 | |
118 | /** |
119 | * Width. |
120 | * |
121 | * @var float (twip) |
122 | */ |
123 | private $width; |
124 | |
125 | /** |
126 | * Height. |
127 | * |
128 | * @var float (twip) |
129 | */ |
130 | private $height; |
131 | |
132 | /** |
133 | * Create a new instance. |
134 | * |
135 | * @param string $size |
136 | */ |
137 | public function __construct($size = 'A4') |
138 | { |
139 | $this->setSize($size); |
140 | } |
141 | |
142 | /** |
143 | * Get size. |
144 | * |
145 | * @return string |
146 | */ |
147 | public function getSize() |
148 | { |
149 | return $this->size; |
150 | } |
151 | |
152 | /** |
153 | * Set size. |
154 | * |
155 | * @param string $size |
156 | * |
157 | * @return self |
158 | */ |
159 | public function setSize($size) |
160 | { |
161 | $this->size = $this->setEnumVal($size, array_keys($this->sizes), $this->size); |
162 | |
163 | [$width, $height, $unit] = $this->sizes[$this->size]; |
164 | |
165 | if ($unit == 'mm') { |
166 | $this->width = Converter::cmToTwip($width / 10); |
167 | $this->height = Converter::cmToTwip($height / 10); |
168 | } else { |
169 | $this->width = Converter::inchToTwip($width); |
170 | $this->height = Converter::inchToTwip($height); |
171 | } |
172 | |
173 | return $this; |
174 | } |
175 | |
176 | /** |
177 | * Get width. |
178 | * |
179 | * @return float |
180 | */ |
181 | public function getWidth() |
182 | { |
183 | return $this->width; |
184 | } |
185 | |
186 | /** |
187 | * Get height. |
188 | * |
189 | * @return float |
190 | */ |
191 | public function getHeight() |
192 | { |
193 | return $this->height; |
194 | } |
195 | } |