Skip to content

Strikethrough font style in Word2007 does not work #1722

@martinsuly

Description

@martinsuly

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions