go-text / typesetting

High quality text shaping in pure Go.
Other
88 stars 11 forks source link

Add Direction to Output #10

Closed whereswaldon closed 2 years ago

whereswaldon commented 2 years ago

I keep finding it necessary to know the direction of text when I'm manipulating a shaping.Output. I can tell if it's RTL or BTT by checking if the first glyph's cluster is higher than the last glyph, but I can't differentiate between vertical and horizontal text that way. Can we add a di.Direction to the shaping.Output so that tasks like line breaking are easier? I suspect we'll need this info anyway when trying to do bidi line-wrapping, though I haven't attempted that yet.

benoitkugler commented 2 years ago

Just to be certain : the direction of the shaping.Output is exactly the one set in the shaping.Input, right ? Is there any case where we will have Output without its Input ?

whereswaldon commented 2 years ago

I find that it's cumbersome to pass both the output and input around everywhere. I'm essentially done with the input once I've shaped the text, with the exception of needing to know the direction from it. That's the motivation here.

Additionally if our bidi algorithm operates on an Input to transform it into []Input with differing Directions, the mapping starts to get awkward. In my case, I have many []Output (wrapped lines) that map to one Input, so I can maintain the relationship for now. Once bidi enters the picture, I'm not sure.

Mostly I need the direction so that I can call Output.RecalculateAll() and friends. If the Output knew its own direction, those methods wouldn't need to accept any parameters at all.

Anyway, this is definitely more an ergonomics question than a design flaw. I'm currently working around this, and it's fine. It just seems relatively cheap to make this smoother, so I wanted to gather feedback on doing that.

andydotxyz commented 2 years ago

Adding this makes sense if we are allowing the input to be mixed-direction clusters. This was not in the plan before which I guess is why we didn't see it. The answer probably depends on whether we change the scope, which is being discussed in go-text/typesetting#8