WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Add support for CSS property: word-break

Open qwfy opened this issue 4 years ago • 4 comments

Currently, word-break is not supported, it's needed if you want to do fine-grained text layout, especially for CJK text.

qwfy avatar Jul 06 '20 06:07 qwfy

Hello!

Strange, word-break is documented as supported, but it’s definitely not. It should be possible to add the feature with the possibilities given by Pango.

liZe avatar Jul 06 '20 18:07 liZe

It seems as though this is a particularly acute problem in tables, as it can't be worked around with overflow-wrap in tables the way it can be in body text:

<style>
html {
  overflow-wrap: break-word;
}
</style>

<table><tr><td>LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG</td></tr></table>

<p>LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG</p>

Sample screenshot

I suspect this is probably about to cause some issues for my uses. If you have a few minutes, can you point me towards where in the code I might try to poke to get either overflow-wrap to work in tables or word-break to work generally?

(edit: ignore the space before the last G in the screenshot - that was a mistake on my part)

aschmitz avatar Nov 30 '21 02:11 aschmitz

Hi, have you any plans about this feature?

Bolik avatar Dec 03 '21 09:12 Bolik

It seems as though this is a particularly acute problem in tables

That’s right, it would be really useful.

Hi, have you any plans about this feature?

We have plans to rewrite the text management in the future, mostly to handle right-to-left and bidirectional text. But there’s nothing about that in the milestones yet.

If you have a few minutes, can you point me towards where in the code I might try to poke to get either overflow-wrap to work in tables or word-break to work generally?

As far as I can remember, overflow-wrap should work but we had some problems with Pango’s wrap mode that wasn’t working as expected. You can look at this code, that’s supposed to break lines at characters boundaries when needed:

https://github.com/Kozea/WeasyPrint/blob/22efdc832bde351dd68831954efb8e750864622f/weasyprint/text/line_break.py#L539-L556

liZe avatar Dec 06 '21 09:12 liZe

Is this still an issue? I tested overflow-wrap: break-word on a couple documents I have where some long URLs would overflow in a column layout, and it worked quite well.

oshmoun avatar Oct 18 '23 08:10 oshmoun

Is this still an issue? I tested overflow-wrap: break-word on a couple documents I have where some long URLs would overflow in a column layout, and it worked quite well.

You’re right, it’s supported now. And if it works "quite well" in columns, we can assume that it works well enough everywhere else 😄.

Thanks a lot!

liZe avatar Oct 18 '23 16:10 liZe