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

Add support for CSS property: word-break #1153

Closed
qwfy opened this issue Jul 6, 2020 · 6 comments
Closed

Add support for CSS property: word-break #1153

qwfy opened this issue Jul 6, 2020 · 6 comments
Labels
feature New feature that should be supported

Comments

@qwfy
Copy link

qwfy commented Jul 6, 2020

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

@liZe
Copy link
Member

liZe commented Jul 6, 2020

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.

@aschmitz
Copy link
Contributor

aschmitz commented Nov 30, 2021

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)

@Bolik
Copy link

Bolik commented Dec 3, 2021

Hi, have you any plans about this feature?

@liZe
Copy link
Member

liZe commented Dec 6, 2021

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:

if not minimum and overflow_wrap == 'break-word' and space < 0:
# Is it really OK to remove hyphenation for word-break ?
hyphenated = False
# TODO: Modify code to preserve W3C condition:
# "Shaping characters are still shaped as if the word were not broken"
# The way new lines are processed in this function (one by one with no
# memory of the last) prevents shaping characters (arabic, for
# instance) from keeping their shape when wrapped on the next line with
# pango layout. Maybe insert Unicode shaping characters in text?
layout.set_text(text)
pango.pango_layout_set_width(
layout.layout, units_from_double(max_width))
pango.pango_layout_set_wrap(
layout.layout, PANGO_WRAP_MODE['WRAP_CHAR'])
first_line, index = layout.get_first_line()
resume_index = index or first_line.length
if resume_index >= len(text.encode('utf-8')):
resume_index = None

@oshmoun
Copy link
Contributor

oshmoun commented Oct 18, 2023

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.

@liZe
Copy link
Member

liZe commented Oct 18, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature that should be supported
Projects
None yet
Development

No branches or pull requests

5 participants