| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Reader\Xml\Style; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Style\Fill as FillStyles; |
| 6 |
use SimpleXMLElement; |
| 7 |
|
| 8 |
class Fill extends StyleBase |
| 9 |
{ |
| 10 |
public const FILL_MAPPINGS = [ |
| 11 |
'fillType' => [ |
| 12 |
'solid' => FillStyles::FILL_SOLID, |
| 13 |
'gray75' => FillStyles::FILL_PATTERN_DARKGRAY, |
| 14 |
'gray50' => FillStyles::FILL_PATTERN_MEDIUMGRAY, |
| 15 |
'gray25' => FillStyles::FILL_PATTERN_LIGHTGRAY, |
| 16 |
'gray125' => FillStyles::FILL_PATTERN_GRAY125, |
| 17 |
'gray0625' => FillStyles::FILL_PATTERN_GRAY0625, |
| 18 |
'horzstripe' => FillStyles::FILL_PATTERN_DARKHORIZONTAL, // horizontal stripe |
| 19 |
'vertstripe' => FillStyles::FILL_PATTERN_DARKVERTICAL, // vertical stripe |
| 20 |
'reversediagstripe' => FillStyles::FILL_PATTERN_DARKUP, // reverse diagonal stripe |
| 21 |
'diagstripe' => FillStyles::FILL_PATTERN_DARKDOWN, // diagonal stripe |
| 22 |
'diagcross' => FillStyles::FILL_PATTERN_DARKGRID, // diagoanl crosshatch |
| 23 |
'thickdiagcross' => FillStyles::FILL_PATTERN_DARKTRELLIS, // thick diagonal crosshatch |
| 24 |
'thinhorzstripe' => FillStyles::FILL_PATTERN_LIGHTHORIZONTAL, |
| 25 |
'thinvertstripe' => FillStyles::FILL_PATTERN_LIGHTVERTICAL, |
| 26 |
'thinreversediagstripe' => FillStyles::FILL_PATTERN_LIGHTUP, |
| 27 |
'thindiagstripe' => FillStyles::FILL_PATTERN_LIGHTDOWN, |
| 28 |
'thinhorzcross' => FillStyles::FILL_PATTERN_LIGHTGRID, // thin horizontal crosshatch |
| 29 |
'thindiagcross' => FillStyles::FILL_PATTERN_LIGHTTRELLIS, // thin diagonal crosshatch |
| 30 |
], |
| 31 |
]; |
| 32 |
|
| 33 |
/** @return array{ |
| 34 |
* fill?: array{ |
| 35 |
* endColor?: array{rgb:string}, |
| 36 |
* startColor?: array{rgb:string}, |
| 37 |
* fillType?: string, |
| 38 |
* } |
| 39 |
* } |
| 40 |
*/ |
| 41 |
public function parseStyle(SimpleXMLElement $styleAttributes): array |
| 42 |
{ |
| 43 |
/** @var array{ |
| 44 |
* fill?: array{ |
| 45 |
* endColor?: array{rgb:string}, |
| 46 |
* startColor?: array{rgb:string}, |
| 47 |
* fillType?: string, |
| 48 |
* } |
| 49 |
* } |
| 50 |
*/ |
| 51 |
$style = []; |
| 52 |
|
| 53 |
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValuex) { |
| 54 |
$styleAttributeValue = (string) $styleAttributeValuex; |
| 55 |
switch ($styleAttributeKey) { |
| 56 |
case 'Color': |
| 57 |
$style['fill']['endColor']['rgb'] = (string) substr($styleAttributeValue, 1); |
| 58 |
$style['fill']['startColor']['rgb'] = (string) substr($styleAttributeValue, 1); |
| 59 |
|
| 60 |
break; |
| 61 |
case 'PatternColor': |
| 62 |
$style['fill']['startColor']['rgb'] = (string) substr($styleAttributeValue, 1); |
| 63 |
|
| 64 |
break; |
| 65 |
case 'Pattern': |
| 66 |
$lcStyleAttributeValue = strtolower((string) $styleAttributeValue); |
| 67 |
$style['fill']['fillType'] |
| 68 |
= self::FILL_MAPPINGS['fillType'][$lcStyleAttributeValue] ?? FillStyles::FILL_NONE; |
| 69 |
|
| 70 |
break; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
return $style; |
| 75 |
} |
| 76 |
} |
| 77 |
|