PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Small caps not working in LibreOffice

Open cambraca opened this issue 4 years ago • 0 comments

Describe the Bug

When adding the small-caps style (e.g. Sample_01_SimpleTest.php), the style is not shown in LibreOffice.

This is because the XML that's generated looks like this:

<w:rPr>
    <w:smallCaps w:val="1"/>
    <w:caps w:val="0"/>
</w:rPr>

The problem, I believe, is that "caps=0", which LibreOffice interprets as overriding "smallCaps=1" so the final style is "no caps of any kind". This doesn't seem to happen in MS Word or Google Docs (when importing the .docx file).

Looking through the code, I found this in PhpWord/Style/Font.php:

public function setSmallCaps($value = true)
{
    return $this->setPairedVal($this->smallCaps, $this->allCaps, $value);
}

Which I think is related (i.e. when setting small caps to true, it automatically sets all caps to false). But I'm not sure what a fix would look like.

Steps to Reproduce

Open the first sample exported as .docx in LibreOffice.

Expected Behavior

Small caps style in the "smallCaps" string, which, in the XML, would look like this:

<w:rPr>
    <w:smallCaps w:val="1"/>
</w:rPr>

Context

Please fill in your environment information:

  • PHP Version: 7.4.3
  • PHPWord Version: 0.18.2
  • LibreOffice Version: 6.4.7.2
  • OS: Ubuntu 20.04

cambraca avatar Jul 22 '21 17:07 cambraca