Fix font index problem (#2642)

* Fix font index problem

* Update RichTextSizeTest.php

Eliminate Phpstan failure.

* Update RichTextSizeTest.php

Eliminate now-unused import.
This commit is contained in:
redforks 2022-04-17 23:27:28 +08:00 committed by GitHub
parent 9caa827f41
commit d593617287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -3759,8 +3759,13 @@ class Xls extends BaseReader
} else { } else {
$textRun = $richText->createTextRun($text); $textRun = $richText->createTextRun($text);
if (isset($fmtRuns[$i - 1])) { if (isset($fmtRuns[$i - 1])) {
if ($fmtRuns[$i - 1]['fontIndex'] < 4) {
$fontIndex = $fmtRuns[$i - 1]['fontIndex']; $fontIndex = $fmtRuns[$i - 1]['fontIndex'];
} else {
// this has to do with that index 4 is omitted in all BIFF versions for some stra nge reason
// check the OpenOffice documentation of the FONT record
$fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1;
}
if (array_key_exists($fontIndex, $this->objFonts) === false) { if (array_key_exists($fontIndex, $this->objFonts) === false) {
$fontIndex = count($this->objFonts) - 1; $fontIndex = count($this->objFonts) - 1;
} }

View File

@ -0,0 +1,22 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class RichTextSizeTest extends AbstractFunctional
{
public function testRichTextRunSize(): void
{
$filename = 'tests/data/Reader/XLS/RichTextFontSize.xls';
$reader = new Xls();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getSheetByName('橱柜门板');
self::assertNotNull($sheet);
$text = $sheet->getCell('L15')->getValue();
$elements = $text->getRichTextElements();
self::assertEquals(10, $elements[2]->getFont()->getSize());
$spreadsheet->disconnectWorksheets();
}
}

Binary file not shown.