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\ODS\Helper;
6
 
7
use OpenSpout\Common\Entity\Style\Border;
8
use OpenSpout\Common\Entity\Style\BorderPart;
9
 
10
/**
11
 * The fo:border, fo:border-top, fo:border-bottom, fo:border-left and fo:border-right attributes
12
 * specify border properties
13
 * http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1419780_253892949.
14
 *
15
 * Example table-cell-properties
16
 *
17
 * <style:table-cell-properties
18
 * fo:border-bottom="0.74pt solid #ffc000" style:diagonal-bl-tr="none"
19
 * style:diagonal-tl-br="none" fo:border-left="none" fo:border-right="none"
20
 * style:rotation-align="none" fo:border-top="none"/>
21
 *
22
 * @internal
23
 */
24
final class BorderHelper
25
{
26
    /**
27
     * Width mappings.
28
     */
29
    public const widthMap = [
30
        Border::WIDTH_THIN => '0.75pt',
31
        Border::WIDTH_MEDIUM => '1.75pt',
32
        Border::WIDTH_THICK => '2.5pt',
33
    ];
34
 
35
    /**
36
     * Style mapping.
37
     */
38
    public const styleMap = [
39
        Border::STYLE_SOLID => 'solid',
40
        Border::STYLE_DASHED => 'dashed',
41
        Border::STYLE_DOTTED => 'dotted',
42
        Border::STYLE_DOUBLE => 'double',
43
    ];
44
 
45
    public static function serializeBorderPart(BorderPart $borderPart): string
46
    {
47
        $definition = 'fo:border-%s="%s"';
48
 
49
        if (Border::STYLE_NONE === $borderPart->getStyle()) {
50
            $borderPartDefinition = sprintf($definition, $borderPart->getName(), 'none');
51
        } else {
52
            $attributes = [
53
                self::widthMap[$borderPart->getWidth()],
54
                self::styleMap[$borderPart->getStyle()],
55
                '#'.$borderPart->getColor(),
56
            ];
57
            $borderPartDefinition = sprintf($definition, $borderPart->getName(), implode(' ', $attributes));
58
        }
59
 
60
        return $borderPartDefinition;
61
    }
62
}