Skip to content

Commit 6445176

Browse files
committed
Sample Warning in Php8.5
Sample_11_ReadWord2007 reads a file with color=auto, and RTF Writer doesn't handle it properly. Change to treat it as black.
1 parent 5b6e415 commit 6445176

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/PhpWord/Writer/RTF/Part/Header.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ private function writeColorTable()
157157
$content .= '{';
158158
$content .= '\colortbl;';
159159
foreach ($this->colorTable as $color) {
160-
[$red, $green, $blue] = Converter::htmlToRgb($color);
160+
$temp = Converter::htmlToRgb($color);
161+
$red = $green = $blue = 0;
162+
if (is_array($temp)) {
163+
[$red, $green, $blue] = $temp;
164+
}
161165
$content .= "\\red{$red}\\green{$green}\\blue{$blue};";
162166
}
163167
$content .= '}';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* This file is part of PHPWord - A pure PHP library for reading and writing
5+
* word processing documents.
6+
*
7+
* PHPWord is free software distributed under the terms of the GNU Lesser
8+
* General Public License version 3 as published by the Free Software Foundation.
9+
*
10+
* For the full copyright and license information, please read the LICENSE
11+
* file that was distributed with this source code. For the full list of
12+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13+
*
14+
* @see https://github.com/PHPOffice/PHPWord
15+
*
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
namespace PhpOffice\PhpWordTests\Writer\RTF;
20+
21+
use PhpOffice\PhpWord\IOFactory;
22+
use PhpOffice\PhpWord\Writer\RTF;
23+
24+
/**
25+
* Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace.
26+
*/
27+
class Sample11Test extends \PHPUnit\Framework\TestCase
28+
{
29+
public function testSample11(): void
30+
{
31+
$source = 'samples/resources/Sample_11_ReadWord2007.docx';
32+
$phpWord = IOFactory::load($source);
33+
$writer = new RTF($phpWord);
34+
$content = $writer->getContent();
35+
$expected = '{\colortbl;\red255\green0\blue0;\red0\green0\blue0;\red0\green0\blue255;}';
36+
self::assertStringContainsString($expected, $content);
37+
}
38+
}

0 commit comments

Comments
 (0)