Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
   4  
   5  use 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      protected function parseUnderline(array $style, string $styleAttributeValue): array
  19      {
  20          if (self::identifyFixedStyleValue(self::UNDERLINE_STYLES, $styleAttributeValue)) {
  21              $style['font']['underline'] = $styleAttributeValue;
  22          }
  23  
  24          return $style;
  25      }
  26  
  27      protected function parseVerticalAlign(array $style, string $styleAttributeValue): array
  28      {
  29          if ($styleAttributeValue == 'Superscript') {
  30              $style['font']['superscript'] = true;
  31          }
  32          if ($styleAttributeValue == 'Subscript') {
  33              $style['font']['subscript'] = true;
  34          }
  35  
  36          return $style;
  37      }
  38  
  39      public function parseStyle(SimpleXMLElement $styleAttributes): array
  40      {
  41          $style = [];
  42  
  43          foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
  44              $styleAttributeValue = (string) $styleAttributeValue;
  45              switch ($styleAttributeKey) {
  46                  case 'FontName':
  47                      $style['font']['name'] = $styleAttributeValue;
  48  
  49                      break;
  50                  case 'Size':
  51                      $style['font']['size'] = $styleAttributeValue;
  52  
  53                      break;
  54                  case 'Color':
  55                      $style['font']['color']['rgb'] = substr($styleAttributeValue, 1);
  56  
  57                      break;
  58                  case 'Bold':
  59                      $style['font']['bold'] = true;
  60  
  61                      break;
  62                  case 'Italic':
  63                      $style['font']['italic'] = true;
  64  
  65                      break;
  66                  case 'Underline':
  67                      $style = $this->parseUnderline($style, $styleAttributeValue);
  68  
  69                      break;
  70                  case 'VerticalAlign':
  71                      $style = $this->parseVerticalAlign($style, $styleAttributeValue);
  72  
  73                      break;
  74              }
  75          }
  76  
  77          return $style;
  78      }
  79  }