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\Style\ConditionalFormatting;
4
 
5
use PhpOffice\PhpSpreadsheet\Style\Border;
6
use PhpOffice\PhpSpreadsheet\Style\Borders;
7
use PhpOffice\PhpSpreadsheet\Style\Fill;
8
use PhpOffice\PhpSpreadsheet\Style\Font;
9
use PhpOffice\PhpSpreadsheet\Style\Style;
10
 
11
class StyleMerger
12
{
13
    protected Style $baseStyle;
14
 
15
    public function __construct(Style $baseStyle)
16
    {
17
        $this->baseStyle = $baseStyle;
18
    }
19
 
20
    public function getStyle(): Style
21
    {
22
        return $this->baseStyle;
23
    }
24
 
25
    public function mergeStyle(Style $style): void
26
    {
27
        if ($style->getNumberFormat()->getFormatCode() !== null) {
28
            $this->baseStyle->getNumberFormat()->setFormatCode($style->getNumberFormat()->getFormatCode());
29
        }
30
        $this->mergeFontStyle($this->baseStyle->getFont(), $style->getFont());
31
        $this->mergeFillStyle($this->baseStyle->getFill(), $style->getFill());
32
        $this->mergeBordersStyle($this->baseStyle->getBorders(), $style->getBorders());
33
    }
34
 
35
    protected function mergeFontStyle(Font $baseFontStyle, Font $fontStyle): void
36
    {
37
        if ($fontStyle->getBold() !== null) {
38
            $baseFontStyle->setBold($fontStyle->getBold());
39
        }
40
        if ($fontStyle->getItalic() !== null) {
41
            $baseFontStyle->setItalic($fontStyle->getItalic());
42
        }
43
        if ($fontStyle->getStrikethrough() !== null) {
44
            $baseFontStyle->setStrikethrough($fontStyle->getStrikethrough());
45
        }
46
        if ($fontStyle->getUnderline() !== null) {
47
            $baseFontStyle->setUnderline($fontStyle->getUnderline());
48
        }
49
        if ($fontStyle->getColor()->getARGB() !== null) {
50
            $baseFontStyle->setColor($fontStyle->getColor());
51
        }
52
    }
53
 
54
    protected function mergeFillStyle(Fill $baseFillStyle, Fill $fillStyle): void
55
    {
56
        if ($fillStyle->getFillType() !== null) {
57
            $baseFillStyle->setFillType($fillStyle->getFillType());
58
        }
59
        $baseFillStyle->setRotation($fillStyle->getRotation());
60
        if ($fillStyle->getStartColor()->getARGB() !== null) {
61
            $baseFillStyle->setStartColor($fillStyle->getStartColor());
62
        }
63
        if ($fillStyle->getEndColor()->getARGB() !== null) {
64
            $baseFillStyle->setEndColor($fillStyle->getEndColor());
65
        }
66
    }
67
 
68
    protected function mergeBordersStyle(Borders $baseBordersStyle, Borders $bordersStyle): void
69
    {
70
        $this->mergeBorderStyle($baseBordersStyle->getTop(), $bordersStyle->getTop());
71
        $this->mergeBorderStyle($baseBordersStyle->getBottom(), $bordersStyle->getBottom());
72
        $this->mergeBorderStyle($baseBordersStyle->getLeft(), $bordersStyle->getLeft());
73
        $this->mergeBorderStyle($baseBordersStyle->getRight(), $bordersStyle->getRight());
74
    }
75
 
76
    protected function mergeBorderStyle(Border $baseBorderStyle, Border $borderStyle): void
77
    {
78
        $baseBorderStyle->setBorderStyle($borderStyle->getBorderStyle());
79
        if ($borderStyle->getColor()->getARGB() !== null) {
80
            $baseBorderStyle->setColor($borderStyle->getColor());
81
        }
82
    }
83
}