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\RichText;
4
 
5
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
6
use PhpOffice\PhpSpreadsheet\Style\Font;
7
 
8
class Run extends TextElement implements ITextElement
9
{
10
    /**
11
     * Font.
12
     */
13
    private ?Font $font;
14
 
15
    /**
16
     * Create a new Run instance.
17
     *
18
     * @param string $text Text
19
     */
20
    public function __construct(string $text = '')
21
    {
22
        parent::__construct($text);
23
        // Initialise variables
24
        $this->font = new Font();
25
    }
26
 
27
    /**
28
     * Get font.
29
     */
30
    public function getFont(): ?Font
31
    {
32
        return $this->font;
33
    }
34
 
35
    public function getFontOrThrow(): Font
36
    {
37
        if ($this->font === null) {
38
            throw new SpreadsheetException('unexpected null font');
39
        }
40
 
41
        return $this->font;
42
    }
43
 
44
    /**
45
     * Set font.
46
     *
47
     * @param ?Font $font Font
48
     *
49
     * @return $this
50
     */
51
    public function setFont(?Font $font = null): static
52
    {
53
        $this->font = $font;
54
 
55
        return $this;
56
    }
57
 
58
    /**
59
     * Get hash code.
60
     *
61
     * @return string Hash code
62
     */
63
    public function getHashCode(): string
64
    {
65
        return md5(
66
            $this->getText()
67
            . (($this->font === null) ? '' : $this->font->getHashCode())
68
            . __CLASS__
69
        );
70
    }
71
}