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

Strikethrough font style in Word2007 does not work #1722

Open
martinsuly opened this issue Sep 13, 2019 · 1 comment · May be fixed by #2604
Open

Strikethrough font style in Word2007 does not work #1722

martinsuly opened this issue Sep 13, 2019 · 1 comment · May be fixed by #2604

Comments

@martinsuly
Copy link

It's not possible to use strike font style with Word2007 writer because it uses strict comparison. Methods isStrikethrough and isDoubleStrikethrough can return true, false or null, false !== null.

src/PhpWord/Writer/Word2007/Style/Font.php

// 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()));

You cannot use elements w:strike and w:dstrike in same time. When you set strike style to true eg. with setStrikethrough then it calls method setPairedVal that should disable double strike style.

src/PhpWord/Style/Font.php

    /**
     * Set strikethrough
     *
     * @param bool $value
     * @return self
     */
    public function setStrikethrough($value = true)
    {
        return $this->setPairedVal($this->strikethrough, $this->doubleStrikethrough, $value);
    }

src/PhpWord/Style/AbstractStyle.php

    /**
     * Set $property value and set $pairProperty = false when $value = true
     *
     * @param bool &$property
     * @param bool &$pairProperty
     * @param bool $value
     * @return self
     */
    protected function setPairedVal(&$property, &$pairProperty, $value)
    {
        $property = $this->setBoolVal($value, $property);
        if ($value === true) {
            $pairProperty = false;
        }
        return $this;
    }

In the writer the method $style->isDoubleStrikethrough() !== null evaluates as true even when this method returns false. Please note that method setPairedVal sets this value to false.

mussbach added a commit to mussbach/PHPWord that referenced this issue Aug 18, 2021
As stated in PHPOffice#1722 and PHPOffice#1693 `setPairedVal` sets DoubleStrikethrough to
false which does not equal `null`
This change may somehow infer with 54e7c6d but as no tests could be
found it is hard to say what would possibly break
@noec764
Copy link

noec764 commented Apr 4, 2024

Any news on that issue ?

@Progi1984 Progi1984 added this to the 2.0.0 milestone Aug 10, 2024
@Progi1984 Progi1984 linked a pull request Aug 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants