| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Reader\Xml\Style; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Style\Font as FontUnderline; |
| 6 |
use SimpleXMLElement; |
| 7 |
|
| 8 |
class Font extends StyleBase |
| 9 |
{ |
| 10 |
protected const UNDERLINE_STYLES = [ |
| 11 |
FontUnderline::UNDERLINE_NONE, |
| 12 |
FontUnderline::UNDERLINE_DOUBLE, |
| 13 |
FontUnderline::UNDERLINE_DOUBLEACCOUNTING, |
| 14 |
FontUnderline::UNDERLINE_SINGLE, |
| 15 |
FontUnderline::UNDERLINE_SINGLEACCOUNTING, |
| 16 |
]; |
| 17 |
|
| 18 |
/** |
| 19 |
* @param mixed[][] $style |
| 20 |
* |
| 21 |
* @return mixed[][] |
| 22 |
*/ |
| 23 |
protected function parseUnderline(array $style, string $styleAttributeValue): array |
| 24 |
{ |
| 25 |
if (self::identifyFixedStyleValue(self::UNDERLINE_STYLES, $styleAttributeValue)) { |
| 26 |
$style['font']['underline'] = $styleAttributeValue; |
| 27 |
} |
| 28 |
|
| 29 |
return $style; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @param mixed[][] $style |
| 34 |
* |
| 35 |
* @return mixed[][] |
| 36 |
*/ |
| 37 |
protected function parseVerticalAlign(array $style, string $styleAttributeValue): array |
| 38 |
{ |
| 39 |
if ($styleAttributeValue == 'Superscript') { |
| 40 |
$style['font']['superscript'] = true; |
| 41 |
} |
| 42 |
if ($styleAttributeValue == 'Subscript') { |
| 43 |
$style['font']['subscript'] = true; |
| 44 |
} |
| 45 |
|
| 46 |
return $style; |
| 47 |
} |
| 48 |
|
| 49 |
/** @return mixed[] */ |
| 50 |
public function parseStyle(SimpleXMLElement $styleAttributes): array |
| 51 |
{ |
| 52 |
$style = []; |
| 53 |
|
| 54 |
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) { |
| 55 |
$styleAttributeValue = (string) $styleAttributeValue; |
| 56 |
switch ($styleAttributeKey) { |
| 57 |
case 'FontName': |
| 58 |
$style['font']['name'] = $styleAttributeValue; |
| 59 |
|
| 60 |
break; |
| 61 |
case 'Size': |
| 62 |
$style['font']['size'] = $styleAttributeValue; |
| 63 |
|
| 64 |
break; |
| 65 |
case 'Color': |
| 66 |
/** @var string[][][] $style */ |
| 67 |
$style['font']['color']['rgb'] = (string) substr($styleAttributeValue, 1); |
| 68 |
|
| 69 |
break; |
| 70 |
case 'Bold': |
| 71 |
$style['font']['bold'] = $styleAttributeValue === '1'; |
| 72 |
|
| 73 |
break; |
| 74 |
case 'Italic': |
| 75 |
$style['font']['italic'] = $styleAttributeValue === '1'; |
| 76 |
|
| 77 |
break; |
| 78 |
case 'Underline': |
| 79 |
$style = $this->parseUnderline($style, $styleAttributeValue); |
| 80 |
|
| 81 |
break; |
| 82 |
case 'VerticalAlign': |
| 83 |
$style = $this->parseVerticalAlign($style, $styleAttributeValue); |
| 84 |
|
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
return $style; |
| 90 |
} |
| 91 |
} |
| 92 |
|