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