PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Worksheet / HeaderFooter.php

HeaderFooter.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Worksheet/HeaderFooter.php

453 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Worksheet;
4
5 /**
6 * <code>
7 * Header/Footer Formatting Syntax taken from Office Open XML Part 4 - Markup Language Reference, page 1970:.
8 *
9 * There are a number of formatting codes that can be written inline with the actual header / footer text, which
10 * affect the formatting in the header or footer.
11 *
12 * Example: This example shows the text "Center Bold Header" on the first line (center section), and the date on
13 * the second line (center section).
14 * &CCenter &"-,Bold"Bold&"-,Regular"Header_x000A_&D
15 *
16 * General Rules:
17 * There is no required order in which these codes must appear.
18 *
19 * The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again:
20 * - strikethrough
21 * - superscript
22 * - subscript
23 * Superscript and subscript cannot both be ON at same time. Whichever comes first wins and the other is ignored,
24 * while the first is ON.
25 * &L - code for "left section" (there are three header / footer locations, "left", "center", and "right"). When
26 * two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the
27 * order of appearance, and placed into the left section.
28 * &P - code for "current page #"
29 * &N - code for "total pages"
30 * &font size - code for "text font size", where font size is a font size in points.
31 * &K - code for "text font color"
32 * RGB Color is specified as RRGGBB
33 * Theme Color is specified as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade
34 * value, NN is the tint/shade value.
35 * &S - code for "text strikethrough" on / off
36 * &X - code for "text super script" on / off
37 * &Y - code for "text subscript" on / off
38 * &C - code for "center section". When two or more occurrences of this section marker exist, the contents
39 * from all markers are concatenated, in the order of appearance, and placed into the center section.
40 *
41 * &D - code for "date"
42 * &T - code for "time"
43 * &G - code for "picture as background"
44 * &U - code for "text single underline"
45 * &E - code for "double underline"
46 * &R - code for "right section". When two or more occurrences of this section marker exist, the contents
47 * from all markers are concatenated, in the order of appearance, and placed into the right section.
48 * &Z - code for "this workbook's file path"
49 * &F - code for "this workbook's file name"
50 * &A - code for "sheet tab name"
51 * &+ - code for add to page #.
52 * &- - code for subtract from page #.
53 * &"font name,font type" - code for "text font name" and "text font type", where font name and font type
54 * are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font
55 * name, it means "none specified". Both of font name and font type can be localized values.
56 * &"-,Bold" - code for "bold font style"
57 * &B - also means "bold font style".
58 * &"-,Regular" - code for "regular font style"
59 * &"-,Italic" - code for "italic font style"
60 * &I - also means "italic font style"
61 * &"-,Bold Italic" code for "bold italic font style"
62 * &O - code for "outline style"
63 * &H - code for "shadow style"
64 * </code>
65 */
66 class HeaderFooter
67 {
68 // Header/footer image location
69 const IMAGE_HEADER_LEFT = 'LH';
70 const IMAGE_HEADER_LEFT_ODD = 'LH';
71 const IMAGE_HEADER_LEFT_FIRST = 'LHFIRST';
72 const IMAGE_HEADER_LEFT_EVEN = 'LHEVEN';
73 const IMAGE_HEADER_CENTER = 'CH';
74 const IMAGE_HEADER_CENTER_ODD = 'CH';
75 const IMAGE_HEADER_CENTER_FIRST = 'CHFIRST';
76 const IMAGE_HEADER_CENTER_EVEN = 'CHEVEN';
77 const IMAGE_HEADER_RIGHT = 'RH';
78 const IMAGE_HEADER_RIGHT_ODD = 'RH';
79 const IMAGE_HEADER_RIGHT_FIRST = 'RHFIRST';
80 const IMAGE_HEADER_RIGHT_EVEN = 'RHEVEN';
81 const IMAGE_FOOTER_LEFT = 'LF';
82 const IMAGE_FOOTER_LEFT_ODD = 'LF';
83 const IMAGE_FOOTER_LEFT_FIRST = 'LFFIRST';
84 const IMAGE_FOOTER_LEFT_EVEN = 'LFEVEN';
85 const IMAGE_FOOTER_CENTER = 'CF';
86 const IMAGE_FOOTER_CENTER_ODD = 'CF';
87 const IMAGE_FOOTER_CENTER_FIRST = 'CFFIRST';
88 const IMAGE_FOOTER_CENTER_EVEN = 'CFEVEN';
89 const IMAGE_FOOTER_RIGHT = 'RF';
90 const IMAGE_FOOTER_RIGHT_ODD = 'RF';
91 const IMAGE_FOOTER_RIGHT_FIRST = 'RFFIRST';
92 const IMAGE_FOOTER_RIGHT_EVEN = 'RFEVEN';
93
94 /**
95 * OddHeader.
96 */
97 private string $oddHeader = '';
98
99 /**
100 * OddFooter.
101 */
102 private string $oddFooter = '';
103
104 /**
105 * EvenHeader.
106 */
107 private string $evenHeader = '';
108
109 /**
110 * EvenFooter.
111 */
112 private string $evenFooter = '';
113
114 /**
115 * FirstHeader.
116 */
117 private string $firstHeader = '';
118
119 /**
120 * FirstFooter.
121 */
122 private string $firstFooter = '';
123
124 /**
125 * Different header for Odd/Even, defaults to false.
126 */
127 private bool $differentOddEven = false;
128
129 /**
130 * Different header for first page, defaults to false.
131 */
132 private bool $differentFirst = false;
133
134 /**
135 * Scale with document, defaults to true.
136 */
137 private bool $scaleWithDocument = true;
138
139 /**
140 * Align with margins, defaults to true.
141 */
142 private bool $alignWithMargins = true;
143
144 /**
145 * Header/footer images.
146 *
147 * @var HeaderFooterDrawing[]
148 */
149 private array $headerFooterImages = [];
150
151 /**
152 * Create a new HeaderFooter.
153 */
154 public function __construct()
155 {
156 }
157
158 /**
159 * Get OddHeader.
160 */
161 public function getOddHeader(): string
162 {
163 return $this->oddHeader;
164 }
165
166 /**
167 * Set OddHeader.
168 *
169 * @return $this
170 */
171 public function setOddHeader(string $oddHeader)
172 {
173 $this->oddHeader = $oddHeader;
174
175 return $this;
176 }
177
178 /**
179 * Get OddFooter.
180 */
181 public function getOddFooter(): string
182 {
183 return $this->oddFooter;
184 }
185
186 /**
187 * Set OddFooter.
188 *
189 * @return $this
190 */
191 public function setOddFooter(string $oddFooter)
192 {
193 $this->oddFooter = $oddFooter;
194
195 return $this;
196 }
197
198 /**
199 * Get EvenHeader.
200 */
201 public function getEvenHeader(): string
202 {
203 return $this->evenHeader;
204 }
205
206 /**
207 * Set EvenHeader.
208 *
209 * @return $this
210 */
211 public function setEvenHeader(string $eventHeader)
212 {
213 $this->evenHeader = $eventHeader;
214
215 return $this;
216 }
217
218 /**
219 * Get EvenFooter.
220 */
221 public function getEvenFooter(): string
222 {
223 return $this->evenFooter;
224 }
225
226 /**
227 * Set EvenFooter.
228 *
229 * @return $this
230 */
231 public function setEvenFooter(string $evenFooter)
232 {
233 $this->evenFooter = $evenFooter;
234
235 return $this;
236 }
237
238 /**
239 * Get FirstHeader.
240 */
241 public function getFirstHeader(): string
242 {
243 return $this->firstHeader;
244 }
245
246 /**
247 * Set FirstHeader.
248 *
249 * @return $this
250 */
251 public function setFirstHeader(string $firstHeader)
252 {
253 $this->firstHeader = $firstHeader;
254
255 return $this;
256 }
257
258 /**
259 * Get FirstFooter.
260 */
261 public function getFirstFooter(): string
262 {
263 return $this->firstFooter;
264 }
265
266 /**
267 * Set FirstFooter.
268 *
269 * @return $this
270 */
271 public function setFirstFooter(string $firstFooter)
272 {
273 $this->firstFooter = $firstFooter;
274
275 return $this;
276 }
277
278 /**
279 * Get DifferentOddEven.
280 */
281 public function getDifferentOddEven(): bool
282 {
283 return $this->differentOddEven;
284 }
285
286 /**
287 * Set DifferentOddEven.
288 *
289 * @return $this
290 */
291 public function setDifferentOddEven(bool $differentOddEvent)
292 {
293 $this->differentOddEven = $differentOddEvent;
294
295 return $this;
296 }
297
298 /**
299 * Get DifferentFirst.
300 */
301 public function getDifferentFirst(): bool
302 {
303 return $this->differentFirst;
304 }
305
306 /**
307 * Set DifferentFirst.
308 *
309 * @return $this
310 */
311 public function setDifferentFirst(bool $differentFirst)
312 {
313 $this->differentFirst = $differentFirst;
314
315 return $this;
316 }
317
318 /**
319 * Get ScaleWithDocument.
320 */
321 public function getScaleWithDocument(): bool
322 {
323 return $this->scaleWithDocument;
324 }
325
326 /**
327 * Set ScaleWithDocument.
328 *
329 * @return $this
330 */
331 public function setScaleWithDocument(bool $scaleWithDocument)
332 {
333 $this->scaleWithDocument = $scaleWithDocument;
334
335 return $this;
336 }
337
338 /**
339 * Get AlignWithMargins.
340 */
341 public function getAlignWithMargins(): bool
342 {
343 return $this->alignWithMargins;
344 }
345
346 /**
347 * Set AlignWithMargins.
348 *
349 * @return $this
350 */
351 public function setAlignWithMargins(bool $alignWithMargins)
352 {
353 $this->alignWithMargins = $alignWithMargins;
354
355 return $this;
356 }
357
358 /**
359 * Add header/footer image.
360 *
361 * @return $this
362 */
363 public function addImage(HeaderFooterDrawing $image, string $location = self::IMAGE_HEADER_LEFT)
364 {
365 $this->headerFooterImages[$location] = $image;
366
367 return $this;
368 }
369
370 /**
371 * Remove header/footer image.
372 *
373 * @return $this
374 */
375 public function removeImage(string $location = self::IMAGE_HEADER_LEFT)
376 {
377 if (isset($this->headerFooterImages[$location])) {
378 unset($this->headerFooterImages[$location]);
379 }
380
381 return $this;
382 }
383
384 /**
385 * Set header/footer images.
386 *
387 * @param HeaderFooterDrawing[] $images
388 *
389 * @return $this
390 */
391 public function setImages(array $images)
392 {
393 $this->headerFooterImages = $images;
394
395 return $this;
396 }
397
398 private const IMAGE_SORT_ORDER = [
399 self::IMAGE_HEADER_LEFT,
400 self::IMAGE_HEADER_LEFT_FIRST,
401 self::IMAGE_HEADER_LEFT_EVEN,
402 self::IMAGE_HEADER_CENTER,
403 self::IMAGE_HEADER_CENTER_FIRST,
404 self::IMAGE_HEADER_CENTER_EVEN,
405 self::IMAGE_HEADER_RIGHT,
406 self::IMAGE_HEADER_RIGHT_FIRST,
407 self::IMAGE_HEADER_RIGHT_EVEN,
408 self::IMAGE_FOOTER_LEFT,
409 self::IMAGE_FOOTER_LEFT_FIRST,
410 self::IMAGE_FOOTER_LEFT_EVEN,
411 self::IMAGE_FOOTER_CENTER,
412 self::IMAGE_FOOTER_CENTER_FIRST,
413 self::IMAGE_FOOTER_CENTER_EVEN,
414 self::IMAGE_FOOTER_RIGHT,
415 self::IMAGE_FOOTER_RIGHT_FIRST,
416 self::IMAGE_FOOTER_RIGHT_EVEN,
417 ];
418
419 /**
420 * Get header/footer images.
421 *
422 * @return HeaderFooterDrawing[]
423 */
424 public function getImages(): array
425 {
426 // Sort array - not sure why needed
427 $images = [];
428 foreach (self::IMAGE_SORT_ORDER as $key) {
429 if (isset($this->headerFooterImages[$key])) {
430 $images[$key] = $this->headerFooterImages[$key];
431 }
432 }
433 $this->headerFooterImages = $images;
434
435 return $this->headerFooterImages;
436 }
437
438 /**
439 * Implement PHP __clone to create a deep clone, not just a shallow copy.
440 */
441 public function __clone()
442 {
443 $vars = get_object_vars($this);
444 foreach ($vars as $key => $value) {
445 if (is_object($value)) {
446 $this->$key = clone $value;
447 } else {
448 $this->$key = $value;
449 }
450 }
451 }
452 }
453