Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 5... Línea 5...
5
namespace OpenSpout\Writer\XLSX\Manager\Style;
5
namespace OpenSpout\Writer\XLSX\Manager\Style;
Línea 6... Línea 6...
6
 
6
 
7
use OpenSpout\Common\Entity\Style\BorderPart;
7
use OpenSpout\Common\Entity\Style\BorderPart;
8
use OpenSpout\Common\Entity\Style\Color;
8
use OpenSpout\Common\Entity\Style\Color;
-
 
9
use OpenSpout\Common\Entity\Style\Style;
9
use OpenSpout\Common\Entity\Style\Style;
10
use OpenSpout\Common\Helper\Escaper\XLSX as XLSXEscaper;
10
use OpenSpout\Writer\Common\Manager\Style\AbstractStyleManager as CommonStyleManager;
11
use OpenSpout\Writer\Common\Manager\Style\AbstractStyleManager as CommonStyleManager;
Línea 11... Línea 12...
11
use OpenSpout\Writer\XLSX\Helper\BorderHelper;
12
use OpenSpout\Writer\XLSX\Helper\BorderHelper;
12
 
13
 
13
/**
14
/**
14
 * @internal
15
 * @internal
15
 *
16
 *
16
 * @property StyleRegistry $styleRegistry
17
 * @property StyleRegistry $styleRegistry
17
 */
18
 */
-
 
19
final class StyleManager extends CommonStyleManager
-
 
20
{
-
 
21
    /** @var XLSXEscaper Strings escaper */
18
final class StyleManager extends CommonStyleManager
22
    private readonly XLSXEscaper $stringsEscaper;
19
{
23
 
20
    public function __construct(StyleRegistry $styleRegistry)
24
    public function __construct(StyleRegistry $styleRegistry, XLSXEscaper $stringsEscaper)
-
 
25
    {
21
    {
26
        parent::__construct($styleRegistry);
Línea 22... Línea 27...
22
        parent::__construct($styleRegistry);
27
        $this->stringsEscaper = $stringsEscaper;
23
    }
28
    }
24
 
29
 
Línea 89... Línea 94...
89
            }
94
            }
Línea 90... Línea 95...
90
 
95
 
91
            /** @var Style $style */
96
            /** @var Style $style */
92
            $style = $this->styleRegistry->getStyleFromStyleId($styleId);
97
            $style = $this->styleRegistry->getStyleFromStyleId($styleId);
93
            $format = $style->getFormat();
98
            $format = $style->getFormat();
94
            $tags[] = '<numFmt numFmtId="'.$numFmtId.'" formatCode="'.$format.'"/>';
99
            $tags[] = '<numFmt numFmtId="'.$numFmtId.'" formatCode="'.$this->stringsEscaper->escape($format).'"/>';
95
        }
100
        }
96
        $content = '<numFmts count="'.\count($tags).'">';
101
        $content = '<numFmts count="'.\count($tags).'">';
97
        $content .= implode('', $tags);
102
        $content .= implode('', $tags);
Línea 145... Línea 150...
145
    {
150
    {
146
        $registeredFills = $this->styleRegistry->getRegisteredFills();
151
        $registeredFills = $this->styleRegistry->getRegisteredFills();
Línea 147... Línea 152...
147
 
152
 
148
        // Excel reserves two default fills
153
        // Excel reserves two default fills
149
        $fillsCount = \count($registeredFills) + 2;
154
        $fillsCount = \count($registeredFills) + 2;
Línea 150... Línea 155...
150
        $content = sprintf('<fills count="%d">', $fillsCount);
155
        $content = \sprintf('<fills count="%d">', $fillsCount);
151
 
156
 
Línea 152... Línea 157...
152
        $content .= '<fill><patternFill patternType="none"/></fill>';
157
        $content .= '<fill><patternFill patternType="none"/></fill>';
153
        $content .= '<fill><patternFill patternType="gray125"/></fill>';
158
        $content .= '<fill><patternFill patternType="gray125"/></fill>';
154
 
159
 
155
        // The other fills are actually registered by setting a background color
160
        // The other fills are actually registered by setting a background color
Línea 156... Línea 161...
156
        foreach ($registeredFills as $styleId) {
161
        foreach ($registeredFills as $styleId) {
157
            /** @var Style $style */
162
            /** @var Style $style */
158
            $style = $this->styleRegistry->getStyleFromStyleId($styleId);
163
            $style = $this->styleRegistry->getStyleFromStyleId($styleId);
159
 
164
 
160
            $backgroundColor = $style->getBackgroundColor();
165
            $backgroundColor = $style->getBackgroundColor();
161
            $content .= sprintf(
166
            $content .= \sprintf(
Línea 234... Línea 239...
234
 
239
 
235
            if ($style->shouldApplyFont()) {
240
            if ($style->shouldApplyFont()) {
236
                $content .= ' applyFont="1"';
241
                $content .= ' applyFont="1"';
Línea 237... Línea 242...
237
            }
242
            }
Línea 238... Línea 243...
238
 
243
 
239
            $content .= sprintf(' applyBorder="%d"', (bool) $style->getBorder());
244
            $content .= \sprintf(' applyBorder="%d"', (bool) $style->getBorder());
240
 
245
 
241
            if ($style->shouldApplyCellAlignment() || $style->shouldApplyCellVerticalAlignment() || $style->hasSetWrapText() || $style->shouldShrinkToFit()) {
246
            if ($style->shouldApplyCellAlignment() || $style->shouldApplyCellVerticalAlignment() || $style->hasSetWrapText() || $style->shouldShrinkToFit() || $style->hasSetTextRotation()) {
242
                $content .= ' applyAlignment="1">';
247
                $content .= ' applyAlignment="1">';
243
                $content .= '<alignment';
248
                $content .= '<alignment';
244
                if ($style->shouldApplyCellAlignment()) {
249
                if ($style->shouldApplyCellAlignment()) {
245
                    $content .= sprintf(' horizontal="%s"', $style->getCellAlignment());
250
                    $content .= \sprintf(' horizontal="%s"', $style->getCellAlignment());
246
                }
251
                }
247
                if ($style->shouldApplyCellVerticalAlignment()) {
252
                if ($style->shouldApplyCellVerticalAlignment()) {
248
                    $content .= sprintf(' vertical="%s"', $style->getCellVerticalAlignment());
253
                    $content .= \sprintf(' vertical="%s"', $style->getCellVerticalAlignment());
249
                }
254
                }
250
                if ($style->hasSetWrapText()) {
255
                if ($style->hasSetWrapText()) {
251
                    $content .= ' wrapText="'.($style->shouldWrapText() ? '1' : '0').'"';
256
                    $content .= ' wrapText="'.($style->shouldWrapText() ? '1' : '0').'"';
252
                }
257
                }
-
 
258
                if ($style->shouldShrinkToFit()) {
-
 
259
                    $content .= ' shrinkToFit="true"';
-
 
260
                }
Línea 253... Línea 261...
253
                if ($style->shouldShrinkToFit()) {
261
                if ($style->hasSetTextRotation()) {
254
                    $content .= ' shrinkToFit="true"';
262
                    $content .= \sprintf(' textRotation="%s"', $style->textRotation());
255
                }
263
                }
256
 
264