Skip to content

Commit bf9e2b0

Browse files
committed
Correct Font Size Calculated by MsDoc Reader
Fix #2526. Most of that issue has already been fixed. The one remaining problem was a deprecation message handling font size. The code used `dechex($operand / 2)`, and issued the deprecation message whenever `$operand` was odd because `dechex` is designed only for integer conversion. `$operand` is actually 2 times the point size, so it will be odd only when the point size is some integer plus half a point (no other fractions are allowed). At any rate, it seems that `dechex` should not be used here in the first place; font size is a numeric value, not a hex string. There are many problems with MsDoc Reader at the moment. This PR is narrowly focused on the problem at hand. Its test is, at least, more detailed than the existing MsDoc Reader test, which does nothing more than confirm that read successfully creates a PhpWord object. The new test verifies that the font size is as expected, but does not validate any other aspect of the read.
1 parent 11a7aaa commit bf9e2b0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/PhpWord/Reader/MsDoc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ private function readPrl($data, $pos, $cbNum)
18711871
break;
18721872
// sprmCHps
18731873
case 0x43:
1874-
$oStylePrl->styleFont['size'] = dechex($operand / 2);
1874+
$oStylePrl->styleFont['size'] = $operand / 2;
18751875

18761876
break;
18771877
// sprmCIss

tests/PhpWordTests/Reader/MsDocTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ public function testLoad(): void
6060
self::assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord);
6161
}
6262

63+
public function testLoadHalfPointFont(): void
64+
{
65+
$filename = __DIR__ . '/../_files/documents/word.2526.doc';
66+
$phpWord = IOFactory::load($filename, 'MsDoc');
67+
$sections = $phpWord->getSections();
68+
self::assertCount(1, $sections);
69+
$elements = $sections[0]->getElements();
70+
self::assertArrayHasKey(0, $elements);
71+
$element0 = $elements[0];
72+
if (method_exists($element0, 'getFontStyle')) {
73+
self::assertSame(19.5, $element0->getFontStyle()->getSize());
74+
} else {
75+
self::fail('Unexpected no font style for first element');
76+
}
77+
}
78+
6379
/**
6480
* Test exception on not existing file.
6581
*/
Binary file not shown.

0 commit comments

Comments
 (0)