Resolve issue with conditional font size set to zero in PHP8 (#2073)

* 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
This commit is contained in:
Mark Baker 2021-05-07 12:53:59 +02:00 committed by GitHub
parent 115e39ae0c
commit 72a36a5bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View File

@ -42,9 +42,12 @@ class Styles extends BaseParserClass
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']));
}
@ -68,8 +71,7 @@ class Styles extends BaseParserClass
$verticalAlign = strtolower((string) $fontStyleXml->vertAlign['val']);
if ($verticalAlign === 'superscript') {
$fontStyle->setSuperscript(true);
}
if ($verticalAlign === 'subscript') {
} elseif ($verticalAlign === 'subscript') {
$fontStyle->setSubscript(true);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;

View File

@ -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());
}
}