alexheretic / glyph-brush

Fast GPU cached text rendering
Apache License 2.0
673 stars 52 forks source link

glyph_brush_layout: Right-Aligned Whitespace Ignored #130

Closed anlumo closed 2 years ago

anlumo commented 3 years ago

When layouting text in right-aligned paragraphs, space characters on the right do not change the layout in any way.

It works with spaces on the left in left-aligned paragraphs.

image

Green text is:

<sp><sp>Left
Aligned

Blue text is:

Right<sp><sp>
Aligned

With <sp> being ASCII space (0x20).

alexheretic commented 3 years ago

It is deliberate that the built in layout will drop spaces between lines, otherwise the space would cause words to bump out of the align bound in some cases and it would look wrong.

So just including the trailing space in a word would be wrong, but maybe the current method could be improved / made more standard. Can you provide some more detailed examples of how other layout engines handle this?

anlumo commented 3 years ago

I should have mentioned that this is not an automatic line break, that's a manual one. I'm not limiting the bounds on either axis.

alexheretic commented 3 years ago

Ah yes that's an interesting distinction that isn't considered by the logic at the moment.

So I think if other layout engines handle right-aligned Foo \nbar with the space jutting the "Foo" out then glyph-brush probably should too.

anlumo commented 3 years ago

Wordpad: image

Affinity Designer: image

Froala (aka a Chrome contenteditable): image

Autodesk Fusion 360: image

So, so far it's 1/4 on the text layouting engines I have access to right now…

alexheretic commented 3 years ago

Thanks for investigating. So there's some inconsistency here it seems.

I'll also add that GIMP will ignore spaces when bound-wrapping Foo bar in the same way as glyph-brush, but will respect the space in Foo \nbar

My current thinking is that as long as it only affects explicit hard breaks it probably won't be any harm for glyph-brush to act this way too (assuming it won't be horrible to implement).

alexheretic commented 3 years ago

GIMP's method seem to be it'll ignore 1 space and 1 space only.

Foo<sp>bar

Foo<sp><sp>bar

Foo<sp><sp><sp>bar

anlumo commented 3 years ago

LibreOffice does show the extra spaces: image

It's really wild that there's such a difference between text layout engines. I have no idea which one is “correct”…

I've talked to our product owner, and he told me that he's fine with either way.

alexheretic commented 3 years ago

I've implemented one take to handle Foo bar & Foo \nbar differently (#131). I'm just not 100% convinced that's actually correct.

PSteinhaus commented 3 years ago

Merging it would at least make the behaviour of spaces on the right when using right alignment consistent with how spaces on the left side work when text is left aligned, wouldn't it? So I'd say it's an improvement in consistency.

alexheretic commented 3 years ago

Merging it would at least make the behaviour of spaces on the right when using right alignment consistent with how spaces on the left side work when text is left aligned, wouldn't it? So I'd say it's an improvement in consistency.

Yeah yours is the first opinion on this for a while. I'm leaning toward merging this too, I don't think they'll be too many drawbacks or places where people were relying on the current behaviour.

alexheretic commented 2 years ago

This is addressed in _glyph_brushlayout 0.2.3.

I imagine they'll be new edge cases to handle, please raise new issues for them :)