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

Inter-word spacing problem with text-align: justify and text-indent > 0 #567

Closed
vilarneto opened this issue Jan 30, 2018 · 2 comments
Closed
Labels
bug Existing features not working as expected
Milestone

Comments

@vilarneto
Copy link

Hello there,

If text-align is set to justify and text-indent is set to a positive value, the first paragraph line ends before the trailing margin. This is due to reduced (instead of increased) inter-word spacing applied during justification, which may even make words overlap.

I've tracked down the bug to text_align() function in file layout/inlines.py. For the first line only, the offset variable stores a negative value, which is divided to line spaces and causes reduced or negative inter-word spacing.

MWE (larger values for text-indent worsen the result):

from weasyprint import HTML, CSS

html = HTML(
    string='<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do'
           ' eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut'
           ' enim ad minim veniam, quis nostrud exercitation ullamco laboris'
           ' nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor'
           ' in reprehenderit in voluptate velit esse cillum dolore eu fugiat'
           ' nulla pariatur. Excepteur sint occaecat cupidatat non proident,'
           ' sunt in culpa qui officia deserunt mollit anim id est laborum.</p>')
css = CSS(string='@page { size: A4; margin: 25mm; } '
                 'p { text-align: justify; text-indent: 20mm; }')

html.write_pdf('bug-minimal.pdf', stylesheets=[css])

Environment: Python 3.6.3 and WeasyPrint 0.42, both under Arch Linux and Mac OS.

Result (default font varies with OS):

bug-minimal

@liZe
Copy link
Member

liZe commented Jan 30, 2018

Thanks for the report!

Good news: it's already been fixed by 13bba98 (see unrelated-but-actually-related #507).

@liZe liZe closed this as completed Jan 30, 2018
@liZe liZe added this to the 43 milestone Jan 30, 2018
@liZe liZe added the bug Existing features not working as expected label Jan 30, 2018
@vilarneto
Copy link
Author

Thanks for the lightning fast response! I've just confirmed expected behavior with current master (commit ee6b506).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants