Skip to content

Paragraph style hanging #358

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

Closed
mburton603 opened this issue Sep 1, 2014 · 2 comments · Fixed by #1764
Closed

Paragraph style hanging #358

mburton603 opened this issue Sep 1, 2014 · 2 comments · Fixed by #1764

Comments

@mburton603
Copy link

mburton603 commented Sep 1, 2014

The hanging option does not work for paragraphs in Word2007 or RTF. One, it generates a first line indent rather than a hanging indent, and two, the amount of the indent is completely wrong - for example, setting a twips value of 1/2 inch was calculated as 4.09 inches.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@cmette
Copy link

cmette commented Mar 2, 2016

yes - it seems true
...but nobody fix it!? If you want to fix it in your local file,

edit PhpOffice\PhpWord\Style\Paragraph.php about the line 182

public function setStyleValue($key, $value)
{
    $key = String::removeUnderscorePrefix($key);
    if ($key == 'indent' || $key == 'hanging') {
      $value = $value * 720;
    } elseif ($key == 'spacing') {
        $value += 240; // because line height of 1 matches 240 twips
    }

    return parent::setStyleValue($key, $value);
}

and set the 720 to 0

$value = $value * 720;

or delete the whole line

@mdupont
Copy link
Contributor

mdupont commented Nov 28, 2019

I just had to work with hanging indents with version 0.17.0 and Word 2007 output. Here is the current status:

  • The documentation is wrong. https://phpword.readthedocs.io/en/latest/styles.html#paragraph says hanging and indent and not in twip, they are in half-inches (see the snippet above which shows the passed value is multiplied by 720).
    As to why this is the case, no idea, it has been this way since the Paragraph.php file was created in 2014.
  • You have to specify both indent and hanging values to have the hanging indent working correctly, setting hanging only did not work as expected.

UPDATE:: relevant code was added all the way back in 2012 through #11 without specific explanation for why the value is multiplied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants