Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace 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 specifed 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_CENTER = 'CH';
71
    const IMAGE_HEADER_RIGHT = 'RH';
72
    const IMAGE_FOOTER_LEFT = 'LF';
73
    const IMAGE_FOOTER_CENTER = 'CF';
74
    const IMAGE_FOOTER_RIGHT = 'RF';
75
 
76
    /**
77
     * OddHeader.
78
     */
79
    private string $oddHeader = '';
80
 
81
    /**
82
     * OddFooter.
83
     */
84
    private string $oddFooter = '';
85
 
86
    /**
87
     * EvenHeader.
88
     */
89
    private string $evenHeader = '';
90
 
91
    /**
92
     * EvenFooter.
93
     */
94
    private string $evenFooter = '';
95
 
96
    /**
97
     * FirstHeader.
98
     */
99
    private string $firstHeader = '';
100
 
101
    /**
102
     * FirstFooter.
103
     */
104
    private string $firstFooter = '';
105
 
106
    /**
107
     * Different header for Odd/Even, defaults to false.
108
     */
109
    private bool $differentOddEven = false;
110
 
111
    /**
112
     * Different header for first page, defaults to false.
113
     */
114
    private bool $differentFirst = false;
115
 
116
    /**
117
     * Scale with document, defaults to true.
118
     */
119
    private bool $scaleWithDocument = true;
120
 
121
    /**
122
     * Align with margins, defaults to true.
123
     */
124
    private bool $alignWithMargins = true;
125
 
126
    /**
127
     * Header/footer images.
128
     *
129
     * @var HeaderFooterDrawing[]
130
     */
131
    private array $headerFooterImages = [];
132
 
133
    /**
134
     * Create a new HeaderFooter.
135
     */
136
    public function __construct()
137
    {
138
    }
139
 
140
    /**
141
     * Get OddHeader.
142
     */
143
    public function getOddHeader(): string
144
    {
145
        return $this->oddHeader;
146
    }
147
 
148
    /**
149
     * Set OddHeader.
150
     *
151
     * @return $this
152
     */
153
    public function setOddHeader(string $oddHeader): static
154
    {
155
        $this->oddHeader = $oddHeader;
156
 
157
        return $this;
158
    }
159
 
160
    /**
161
     * Get OddFooter.
162
     */
163
    public function getOddFooter(): string
164
    {
165
        return $this->oddFooter;
166
    }
167
 
168
    /**
169
     * Set OddFooter.
170
     *
171
     * @return $this
172
     */
173
    public function setOddFooter(string $oddFooter): static
174
    {
175
        $this->oddFooter = $oddFooter;
176
 
177
        return $this;
178
    }
179
 
180
    /**
181
     * Get EvenHeader.
182
     */
183
    public function getEvenHeader(): string
184
    {
185
        return $this->evenHeader;
186
    }
187
 
188
    /**
189
     * Set EvenHeader.
190
     *
191
     * @return $this
192
     */
193
    public function setEvenHeader(string $eventHeader): static
194
    {
195
        $this->evenHeader = $eventHeader;
196
 
197
        return $this;
198
    }
199
 
200
    /**
201
     * Get EvenFooter.
202
     */
203
    public function getEvenFooter(): string
204
    {
205
        return $this->evenFooter;
206
    }
207
 
208
    /**
209
     * Set EvenFooter.
210
     *
211
     * @return $this
212
     */
213
    public function setEvenFooter(string $evenFooter): static
214
    {
215
        $this->evenFooter = $evenFooter;
216
 
217
        return $this;
218
    }
219
 
220
    /**
221
     * Get FirstHeader.
222
     */
223
    public function getFirstHeader(): string
224
    {
225
        return $this->firstHeader;
226
    }
227
 
228
    /**
229
     * Set FirstHeader.
230
     *
231
     * @return $this
232
     */
233
    public function setFirstHeader(string $firstHeader): static
234
    {
235
        $this->firstHeader = $firstHeader;
236
 
237
        return $this;
238
    }
239
 
240
    /**
241
     * Get FirstFooter.
242
     */
243
    public function getFirstFooter(): string
244
    {
245
        return $this->firstFooter;
246
    }
247
 
248
    /**
249
     * Set FirstFooter.
250
     *
251
     * @return $this
252
     */
253
    public function setFirstFooter(string $firstFooter): static
254
    {
255
        $this->firstFooter = $firstFooter;
256
 
257
        return $this;
258
    }
259
 
260
    /**
261
     * Get DifferentOddEven.
262
     */
263
    public function getDifferentOddEven(): bool
264
    {
265
        return $this->differentOddEven;
266
    }
267
 
268
    /**
269
     * Set DifferentOddEven.
270
     *
271
     * @return $this
272
     */
273
    public function setDifferentOddEven(bool $differentOddEvent): static
274
    {
275
        $this->differentOddEven = $differentOddEvent;
276
 
277
        return $this;
278
    }
279
 
280
    /**
281
     * Get DifferentFirst.
282
     */
283
    public function getDifferentFirst(): bool
284
    {
285
        return $this->differentFirst;
286
    }
287
 
288
    /**
289
     * Set DifferentFirst.
290
     *
291
     * @return $this
292
     */
293
    public function setDifferentFirst(bool $differentFirst): static
294
    {
295
        $this->differentFirst = $differentFirst;
296
 
297
        return $this;
298
    }
299
 
300
    /**
301
     * Get ScaleWithDocument.
302
     */
303
    public function getScaleWithDocument(): bool
304
    {
305
        return $this->scaleWithDocument;
306
    }
307
 
308
    /**
309
     * Set ScaleWithDocument.
310
     *
311
     * @return $this
312
     */
313
    public function setScaleWithDocument(bool $scaleWithDocument): static
314
    {
315
        $this->scaleWithDocument = $scaleWithDocument;
316
 
317
        return $this;
318
    }
319
 
320
    /**
321
     * Get AlignWithMargins.
322
     */
323
    public function getAlignWithMargins(): bool
324
    {
325
        return $this->alignWithMargins;
326
    }
327
 
328
    /**
329
     * Set AlignWithMargins.
330
     *
331
     * @return $this
332
     */
333
    public function setAlignWithMargins(bool $alignWithMargins): static
334
    {
335
        $this->alignWithMargins = $alignWithMargins;
336
 
337
        return $this;
338
    }
339
 
340
    /**
341
     * Add header/footer image.
342
     *
343
     * @return $this
344
     */
345
    public function addImage(HeaderFooterDrawing $image, string $location = self::IMAGE_HEADER_LEFT): static
346
    {
347
        $this->headerFooterImages[$location] = $image;
348
 
349
        return $this;
350
    }
351
 
352
    /**
353
     * Remove header/footer image.
354
     *
355
     * @return $this
356
     */
357
    public function removeImage(string $location = self::IMAGE_HEADER_LEFT): static
358
    {
359
        if (isset($this->headerFooterImages[$location])) {
360
            unset($this->headerFooterImages[$location]);
361
        }
362
 
363
        return $this;
364
    }
365
 
366
    /**
367
     * Set header/footer images.
368
     *
369
     * @param HeaderFooterDrawing[] $images
370
     *
371
     * @return $this
372
     */
373
    public function setImages(array $images): static
374
    {
375
        $this->headerFooterImages = $images;
376
 
377
        return $this;
378
    }
379
 
380
    /**
381
     * Get header/footer images.
382
     *
383
     * @return HeaderFooterDrawing[]
384
     */
385
    public function getImages(): array
386
    {
387
        // Sort array
388
        $images = [];
389
        if (isset($this->headerFooterImages[self::IMAGE_HEADER_LEFT])) {
390
            $images[self::IMAGE_HEADER_LEFT] = $this->headerFooterImages[self::IMAGE_HEADER_LEFT];
391
        }
392
        if (isset($this->headerFooterImages[self::IMAGE_HEADER_CENTER])) {
393
            $images[self::IMAGE_HEADER_CENTER] = $this->headerFooterImages[self::IMAGE_HEADER_CENTER];
394
        }
395
        if (isset($this->headerFooterImages[self::IMAGE_HEADER_RIGHT])) {
396
            $images[self::IMAGE_HEADER_RIGHT] = $this->headerFooterImages[self::IMAGE_HEADER_RIGHT];
397
        }
398
        if (isset($this->headerFooterImages[self::IMAGE_FOOTER_LEFT])) {
399
            $images[self::IMAGE_FOOTER_LEFT] = $this->headerFooterImages[self::IMAGE_FOOTER_LEFT];
400
        }
401
        if (isset($this->headerFooterImages[self::IMAGE_FOOTER_CENTER])) {
402
            $images[self::IMAGE_FOOTER_CENTER] = $this->headerFooterImages[self::IMAGE_FOOTER_CENTER];
403
        }
404
        if (isset($this->headerFooterImages[self::IMAGE_FOOTER_RIGHT])) {
405
            $images[self::IMAGE_FOOTER_RIGHT] = $this->headerFooterImages[self::IMAGE_FOOTER_RIGHT];
406
        }
407
        $this->headerFooterImages = $images;
408
 
409
        return $this->headerFooterImages;
410
    }
411
 
412
    /**
413
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
414
     */
415
    public function __clone()
416
    {
417
        $vars = get_object_vars($this);
418
        foreach ($vars as $key => $value) {
419
            if (is_object($value)) {
420
                $this->$key = clone $value;
421
            } else {
422
                $this->$key = $value;
423
            }
424
        }
425
    }
426
}