Skip to content

Commit 07150fc

Browse files
committed
Didn't Like My Approach In 2 Places
1 parent 8e4ebd9 commit 07150fc

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

src/PhpSpreadsheet/Helper/Dimension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Dimension
1414
public const UOM_PIXELS = 'px';
1515
public const UOM_POINTS = 'pt';
1616
public const UOM_PICA = 'pc';
17-
public const ABSOLUTE_DEFAULT_UNIT = 'px';
1817

1918
/**
2019
* Based on 96 dpi.
@@ -53,7 +52,7 @@ class Dimension
5352

5453
protected ?string $unit = null;
5554

56-
public function __construct(string $dimension, ?string $absoluteDefaultUnit = self::ABSOLUTE_DEFAULT_UNIT)
55+
public function __construct(string $dimension)
5756
{
5857
$size = 0.0;
5958
$unit = '';
@@ -66,7 +65,7 @@ public function __construct(string $dimension, ?string $absoluteDefaultUnit = se
6665
// If a UoM is specified, then convert the size to pixels for internal storage
6766
if (isset(self::ABSOLUTE_UNITS[$unit])) {
6867
$size *= self::ABSOLUTE_UNITS[$unit];
69-
$this->unit = $absoluteDefaultUnit;
68+
$this->unit = self::UOM_PIXELS;
7069
} elseif (isset(self::RELATIVE_UNITS[$unit])) {
7170
$size *= self::RELATIVE_UNITS[$unit];
7271
$size = round($size, 4);

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
11111111
if (!isset($attributes['src'])) {
11121112
return;
11131113
}
1114-
$styleArray = self::getStyleArray($attributes, null);
1114+
$styleArray = self::getStyleArray($attributes);
11151115

11161116
$src = $attributes['src'];
11171117
if (substr($src, 0, 5) !== 'data:') {
@@ -1169,7 +1169,7 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
11691169
*
11701170
* @return mixed[]
11711171
*/
1172-
private static function getStyleArray(array $attributes, ?string $defaultAbsoluteUnit = CssDimension::ABSOLUTE_DEFAULT_UNIT): array
1172+
private static function getStyleArray(array $attributes): array
11731173
{
11741174
$styleArray = [];
11751175
if (isset($attributes['style'])) {
@@ -1183,13 +1183,13 @@ private static function getStyleArray(array $attributes, ?string $defaultAbsolut
11831183
if (substr($arrayValue, -2) === 'px') {
11841184
$arrayValue = (string) (((float) substr($arrayValue, 0, -2)));
11851185
} else {
1186-
$arrayValue = (new CssDimension($arrayValue, $defaultAbsoluteUnit))->width();
1186+
$arrayValue = (new CssDimension($arrayValue))->toUnit(CssDimension::UOM_PIXELS);
11871187
}
11881188
} elseif ($arrayKey === 'height') {
11891189
if (substr($arrayValue, -2) === 'px') {
11901190
$arrayValue = substr($arrayValue, 0, -2);
11911191
} else {
1192-
$arrayValue = (new CssDimension($arrayValue, $defaultAbsoluteUnit))->height();
1192+
$arrayValue = (new CssDimension($arrayValue))->toUnit(CssDimension::UOM_PIXELS);
11931193
}
11941194
}
11951195
$styleArray[$arrayKey] = $arrayValue;

src/PhpSpreadsheet/Reader/XlsBase.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ class XlsBase extends BaseReader
133133
*/
134134
protected string $codepage = '';
135135

136-
/**
137-
* @deprecated 5.2.0 Serves no useful purpose. No replacement.
138-
*
139-
* @codeCoverageIgnore
140-
*/
141136
public function setCodepage(string $codepage): void
142137
{
143138
if (CodePage::validate($codepage) === false) {

tests/PhpSpreadsheetTests/Reader/Xls/InfoNamesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ public function testWorksheetInfoBiff5Mac(): void
117117
self::assertContains($reader->getCodepage(), self::MAC_CE);
118118
}
119119

120+
public function testWorksheetNamesBiff5Special(): void
121+
{
122+
// Sadly, no unit test was added for PR #1484,
123+
// so we have to invent a fake one now.
124+
$reader = new XlsSpecialCodePage();
125+
$reader->setCodePage('CP855'); // use Cyrillic rather than MACCENTRAL
126+
$names = $reader->listWorksheetNames(self::MAC_FILE5);
127+
$expected = ['ђrkusz1']; // first character interpreted as Cyrillic
128+
self::assertSame($expected, $names);
129+
}
130+
120131
public function testLoadMacCentralEuropeBiff5(): void
121132
{
122133
$reader = new Xls();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
6+
7+
use PhpOffice\PhpSpreadsheet\Shared\CodePage;
8+
9+
class XlsSpecialCodePage extends \PhpOffice\PhpSpreadsheet\Reader\Xls
10+
{
11+
protected function readCodepage(): void
12+
{
13+
$length = self::getUInt2d($this->data, $this->pos + 2);
14+
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
15+
16+
// move stream pointer to next record
17+
$this->pos += 4 + $length;
18+
19+
// offset: 0; size: 2; code page identifier
20+
$codepage = self::getUInt2d($recordData, 0);
21+
22+
if ($this->codepage === '') {
23+
$this->codepage = CodePage::numberToName($codepage);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)