Skip to content

Commit

Permalink
Resolve issue with conditional font size set to zero in PHP8 (#2073)
Browse files Browse the repository at this point in the history
* Let's see if the tests now pass against PHP8; output file looks to be good
* Font can't be both superscript and subscript at the same time, so we use if/else rather than if/if
  • Loading branch information
Mark Baker committed May 7, 2021
1 parent 115e39a commit 72a36a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/PhpSpreadsheet/Reader/Xlsx/Styles.php
Expand Up @@ -42,9 +42,12 @@ public function setStyleBaseData(?Theme $theme = null, $styles = [], $cellStyles

public static function readFontStyle(Font $fontStyle, SimpleXMLElement $fontStyleXml): void
{
$fontStyle->setName((string) $fontStyleXml->name['val']);
$fontStyle->setSize((float) $fontStyleXml->sz['val']);

if (isset($fontStyleXml->name, $fontStyleXml->name['val'])) {
$fontStyle->setName((string) $fontStyleXml->name['val']);
}
if (isset($fontStyleXml->sz, $fontStyleXml->sz['val'])) {
$fontStyle->setSize((float) $fontStyleXml->sz['val']);
}
if (isset($fontStyleXml->b)) {
$fontStyle->setBold(!isset($fontStyleXml->b['val']) || self::boolean((string) $fontStyleXml->b['val']));
}
Expand All @@ -68,8 +71,7 @@ public static function readFontStyle(Font $fontStyle, SimpleXMLElement $fontStyl
$verticalAlign = strtolower((string) $fontStyleXml->vertAlign['val']);
if ($verticalAlign === 'superscript') {
$fontStyle->setSuperscript(true);
}
if ($verticalAlign === 'subscript') {
} elseif ($verticalAlign === 'subscript') {
$fontStyle->setSubscript(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFillTest.php
@@ -1,6 +1,6 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;
Expand Down
22 changes: 22 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFontTest.php
@@ -0,0 +1,22 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;

class DefaultFontTest extends TestCase
{
public function testDefaultConditionalFont(): void
{
// default fill pattern for a conditional style where the filltype is not defined
$filename = 'tests/data/Reader/XLSX/pr2050cf-fill.xlsx';
$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename);

$style = $spreadsheet->getActiveSheet()->getConditionalStyles('A1')[0]->getStyle();
self::assertSame('9C0006', $style->getFont()->getColor()->getRGB());
self::assertNull($style->getFont()->getName());
self::assertNull($style->getFont()->getSize());
}
}

0 comments on commit 72a36a5

Please sign in to comment.