Skip to content

implement underlineColor in Word2007, ODText, and HTML - #2862

Open
ger82 wants to merge 5 commits into
PHPOffice:masterfrom
ger82:master
Open

ger82 wants to merge 5 commits into
PHPOffice:masterfrom
ger82:master

Conversation

@ger82

@ger82 ger82 commented Mar 4, 2026 •

Copy link
Copy Markdown

Description

implement underlineColor in Word2007, ODText, and HTML

Checklist:

  • My CI is 🟢 , I think so
  • I have covered by unit tests my new code (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes
  • I have updated the changelog

Comment thread src/PhpWord/Style/Font.php Resolved
Comment thread src/PhpWord/Style/Font.php Outdated
*
* @return string
*/
public function getUnderlineColor()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getUnderlineColor()
public function getUnderlineColor(): string

Comment thread src/PhpWord/Style/Font.php Outdated
*
* @return self
*/
public function setUnderlineColor(?string $value = null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function setUnderlineColor(?string $value = null)
public function setUnderlineColor(string $value = ''): self

Comment on lines +536 to +539
*
* @param string|null $value
*
* @return self

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*
* @param string|null $value
*
* @return self

Comment on lines +526 to +527
*
* @return string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*
* @return string

Comment thread src/PhpWord/Style/Font.php Outdated
*/
private $underline = self::UNDERLINE_NONE;

private $underlineColor;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private $underlineColor;
/**
* Underline color.
*
* @var string
*/
private $underlineColor = '';

Comment thread src/PhpWord/Writer/HTML/Style/Font.php Outdated
$css['vertical-align'] .= $this->getValueIf($style->isSubScript(), 'sub');
$css['text-decoration'] = '';
$css['text-decoration'] .= $this->getValueIf($underline, 'underline ');
$css['text-decoration-color'] .= $this->getValueIf($underlineColor !== null, "#{$underlineColor}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$css['text-decoration-color'] .= $this->getValueIf($underlineColor !== null, "#{$underlineColor}");
$css['text-decoration-color'] .= $this->getValueIf($underlineColor !== '', '#' .$underlineColor);

$xmlWriter->writeElementIf($style->getUnderline() != 'none', 'w:u', 'w:val', $style->getUnderline());

// UnderlineColor
$xmlWriter->writeElementIf($style->getUnderlineColor() !== null, 'w:u', 'w:color', $style->getUnderlineColor());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$xmlWriter->writeElementIf($style->getUnderlineColor() !== null, 'w:u', 'w:color', $style->getUnderlineColor());
$xmlWriter->writeElementIf($style->getUnderlineColor() !== '', 'w:u', 'w:color', $style->getUnderlineColor());

Comment thread tests/PhpWordTests/Style/FontTest.php Outdated
'bold' => false,
'italic' => false,
'underline' => Font::UNDERLINE_NONE,
'underlineColor' => null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'underlineColor' => null,
'underlineColor' => '',

@Progi1984 Progi1984 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ger82 Great contribution. Could you add unit tests for each writer and check all my feedbacks, please ?

@ger82

ger82 commented Mar 4, 2026 •

Copy link
Copy Markdown
Author

@Progi1984 Hi, to check you feedback, should I use the Button "resolve conversation" if it's ok?

I think your code changes are OK. I based my changes on the existing code, especially color and underline.

oleibman added a commit to oleibman/PHPWord that referenced this pull request Mar 17, 2026
Adapted from PR PHPOffice#2862 by @ger82. Corrected some errors (Word2007 should not write 2 `w:u` entries when `underlineColor` is specified, Html needs to be more careful about when to prepend `#`). Added read support for Word2007 and Html. Add RTF Reader support for various underline styles. RTF Reader does not appear to support colors at all; that will have to be the subject of another PR. ODText Reader does not appear to support any styles; that will have to be the subject of at least one far more complicated PR.
@Progi1984

Progi1984 commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

@ger82 Hi Could you rebase your PR ? & Fix CI ?

@ger82

ger82 commented Sep 25, 2026

Copy link
Copy Markdown
Author

Yes, but I need some days.

Comment thread src/PhpWord/Writer/HTML/Style/Font.php Outdated
$css['vertical-align'] .= $this->getValueIf($style->isSubScript(), 'sub');
$css['text-decoration'] = '';
$css['text-decoration'] .= $this->getValueIf($underline, 'underline ');
$css['text-decoration-color'] .= $this->getValueIf($underlineColor !== null, "#{$underlineColor}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use concatenation. Just assign. Or define empty value as for 'text-decoration'

@ger82 ger82 Sep 28, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, sorry my misstake, I made this changes mouth ago.

@ger82

ger82 commented Sep 29, 2026 •

Copy link
Copy Markdown
Author

@Progi1984 done, I include your changes and fix the bugs that the CI sad and a few logical errors as well

I’ve just noticed that there’s also a request from oleibman that might cause conflicts; should I merge that with my code and make another pull request?

@Progi1984

Copy link
Copy Markdown
Member

@ger82 Rebase on your PR againt the master branch and that should resolve conflicts.

@ger82

ger82 commented Sep 30, 2026

Copy link
Copy Markdown
Author

@Progi1984 rebase is done, the phpunit Errors seems to be not from code ???

@Progi1984

Copy link
Copy Markdown
Member

@Progi1984 rebase is done, the phpunit Errors seems to be not from code ???

SOrry @ger82, but I think yes

image

@ger82

ger82 commented Oct 1, 2026 •

Copy link
Copy Markdown
Author

@Progi1984 thank you, when I open the error message I get only this:
can you give me the complett errors?
Screenshot 2026-10-01 104809

@ger82

ger82 commented Oct 19, 2026

Copy link
Copy Markdown
Author

@Progi1984 finally it looks good.

I have set up Unittest locally on my computer so that I can receive the error messages.
I still don’t see any error message here, just what you can see in the screenshot in the last post.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 96.587% (+0.005%) from 96.582% — ger82:master into PHPOffice:master

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants