Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace OpenSpout\Writer\XLSX\Helper;
6
 
7
use OpenSpout\Common\Entity\Style\Border;
8
use OpenSpout\Common\Entity\Style\BorderPart;
9
 
10
/**
11
 * @internal
12
 */
13
final class BorderHelper
14
{
15
    private const xlsxStyleMap = [
16
        Border::STYLE_SOLID => [
17
            Border::WIDTH_THIN => 'thin',
18
            Border::WIDTH_MEDIUM => 'medium',
19
            Border::WIDTH_THICK => 'thick',
20
        ],
21
        Border::STYLE_DOTTED => [
22
            Border::WIDTH_THIN => 'dotted',
23
            Border::WIDTH_MEDIUM => 'dotted',
24
            Border::WIDTH_THICK => 'dotted',
25
        ],
26
        Border::STYLE_DASHED => [
27
            Border::WIDTH_THIN => 'dashed',
28
            Border::WIDTH_MEDIUM => 'mediumDashed',
29
            Border::WIDTH_THICK => 'mediumDashed',
30
        ],
31
        Border::STYLE_DOUBLE => [
32
            Border::WIDTH_THIN => 'double',
33
            Border::WIDTH_MEDIUM => 'double',
34
            Border::WIDTH_THICK => 'double',
35
        ],
36
        Border::STYLE_NONE => [
37
            Border::WIDTH_THIN => 'none',
38
            Border::WIDTH_MEDIUM => 'none',
39
            Border::WIDTH_THICK => 'none',
40
        ],
41
    ];
42
 
43
    public static function serializeBorderPart(?BorderPart $borderPart): string
44
    {
45
        if (null === $borderPart) {
46
            return '';
47
        }
48
 
49
        $borderStyle = self::getBorderStyle($borderPart);
50
 
51
        $colorEl = sprintf('<color rgb="%s"/>', $borderPart->getColor());
52
        $partEl = sprintf(
53
            '<%s style="%s">%s</%s>',
54
            $borderPart->getName(),
55
            $borderStyle,
56
            $colorEl,
57
            $borderPart->getName()
58
        );
59
 
60
        return $partEl.PHP_EOL;
61
    }
62
 
63
    /**
64
     * Get the style definition from the style map.
65
     */
66
    private static function getBorderStyle(BorderPart $borderPart): string
67
    {
68
        return self::xlsxStyleMap[$borderPart->getStyle()][$borderPart->getWidth()];
69
    }
70
}