Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word2007 Writer : Fixed StrikeThrough property #2661

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/1.x/1.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Word2007 Writer : Fix first footnote appearing as separator [#2634](https://github.com/PHPOffice/PHPWord/issues/2634) by [@jacksleight](https://github.com/jacksleight) in [#2635](https://github.com/PHPOffice/PHPWord/pull/2635)
- Template Processor : Fixed images with transparent backgrounds displaying a white background by [@ElwynVdb](https://github.com/ElwynVdb) in [#2638](https://github.com/PHPOffice/PHPWord/pull/2638)
- HTML Writer : Fixed rowspan for tables by [@andomiell](https://github.com/andomiell) in [#2659](https://github.com/PHPOffice/PHPWord/pull/2659)
- Word2007 Writer : Fixed StrikeThrough property by [@noec764](https://github.com/noec764) fixing [#1722](https://github.com/PHPOffice/PHPWord/issues/1722) & [#1693](https://github.com/PHPOffice/PHPWord/issues/1693) in [#2661](https://github.com/PHPOffice/PHPWord/pull/2661)

### Miscellaneous

Expand Down
16 changes: 4 additions & 12 deletions src/PhpWord/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,8 @@ public function setSubScript($value = true)

/**
* Get strikethrough.
*
* @return bool
*/
public function isStrikethrough()
public function isStrikethrough(): ?bool
{
return $this->strikethrough;
}
Expand All @@ -577,20 +575,16 @@ public function isStrikethrough()
* Set strikethrough.
*
* @param bool $value
*
* @return self
*/
public function setStrikethrough($value = true)
public function setStrikethrough($value = true): self
{
return $this->setPairedVal($this->strikethrough, $this->doubleStrikethrough, $value);
}

/**
* Get double strikethrough.
*
* @return bool
*/
public function isDoubleStrikethrough()
public function isDoubleStrikethrough(): ?bool
{
return $this->doubleStrikethrough;
}
Expand All @@ -599,10 +593,8 @@ public function isDoubleStrikethrough()
* Set double strikethrough.
*
* @param bool $value
*
* @return self
*/
public function setDoubleStrikethrough($value = true)
public function setDoubleStrikethrough($value = true): self
{
return $this->setPairedVal($this->doubleStrikethrough, $this->strikethrough, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Writer/Word2007/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private function writeStyle(): void
$xmlWriter->writeElementIf($style->isItalic() !== null, 'w:iCs', 'w:val', $this->writeOnOf($style->isItalic()));

// Strikethrough, double strikethrough
$xmlWriter->writeElementIf($style->isStrikethrough() !== null, 'w:strike', 'w:val', $this->writeOnOf($style->isStrikethrough()));
$xmlWriter->writeElementIf($style->isDoubleStrikethrough() !== null, 'w:dstrike', 'w:val', $this->writeOnOf($style->isDoubleStrikethrough()));
$xmlWriter->writeElementIf($style->isStrikethrough(), 'w:strike', 'w:val', $this->writeOnOf($style->isStrikethrough()));
$xmlWriter->writeElementIf($style->isDoubleStrikethrough(), 'w:dstrike', 'w:val', $this->writeOnOf($style->isDoubleStrikethrough()));

// Small caps, all caps
$xmlWriter->writeElementIf($style->isSmallCaps() !== null, 'w:smallCaps', 'w:val', $this->writeOnOf($style->isSmallCaps()));
Expand Down
35 changes: 35 additions & 0 deletions tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,47 @@ public function testWriteFontStyle(): void
self::assertTrue($doc->elementExists("{$parent}/w:i"));
self::assertEquals($styles['underline'], $doc->getElementAttribute("{$parent}/w:u", 'w:val'));
self::assertTrue($doc->elementExists("{$parent}/w:strike"));
self::assertFalse($doc->elementExists("{$parent}/w:dstrike"));
self::assertEquals('superscript', $doc->getElementAttribute("{$parent}/w:vertAlign", 'w:val'));
self::assertEquals($styles['color'], $doc->getElementAttribute("{$parent}/w:color", 'w:val'));
self::assertEquals($styles['fgColor'], $doc->getElementAttribute("{$parent}/w:highlight", 'w:val'));
self::assertTrue($doc->elementExists("{$parent}/w:smallCaps"));
}

/**
* covers ::_writeTextStyle.
*
* @dataProvider providerFontStyleStrikethrough
*/
public function testWriteFontStyleStrikethrough(
bool $isStrikethrough,
bool $isDoubleStrikethrough,
bool $expectedStrikethrough,
bool $expectedDoubleStrikethrough
): void {
$phpWord = new PhpWord();
$styles['strikethrough'] = $isStrikethrough;
$styles['doublestrikethrough'] = $isDoubleStrikethrough;

$section = $phpWord->addSection();
$section->addText('Test', $styles);
$doc = TestHelperDOCX::getDocument($phpWord);

$parent = '/w:document/w:body/w:p/w:r/w:rPr';
self::assertSame($expectedStrikethrough, $doc->elementExists("{$parent}/w:strike"));
self::assertSame($expectedDoubleStrikethrough, $doc->elementExists("{$parent}/w:dstrike"));
}

public static function providerFontStyleStrikethrough(): iterable
{
return [
[true, true, false, true],
[true, false, true, false],
[false, true, false, true],
[false, false, false, false],
];
}

/**
* Tests that if no color is set on a cell a border gets writen with the default color.
*/
Expand Down
Loading