go-text / typesetting

High quality text shaping in pure Go.
Other
101 stars 10 forks source link

shaping: implement simple line truncation #37

Closed whereswaldon closed 1 year ago

whereswaldon commented 1 year ago

This commit adds a mechanism to limit the number of wrapped lines of text to a fixed quantity. Doing so will currently still require shaping all of the text, but does skip the work to wrap any truncated text.

Updates #28

This does not implement inserting a symbol to indicate truncation, but seemed like a good starting point. Being able to truncate without the symbol is useful on its own, and this way the change is as simple as possible.

I deviated slightly from the discussion in #28 because I realized there are reasons one might wish to only display exactly N lines of text. Instead of a boolean indicating whether or not to truncate, I've used an integer count of lines. I think it's reasonably intuitive, and has the happy side effect of having a zero value which will not perform truncation.

I look forward to your thoughts!

benoitkugler commented 1 year ago

Nicely done ! If I understand correctly, WrapParagraph will return at most WrapAfterLine (unless its zero), right? Maybe that could appear explicitly in the doc?

whereswaldon commented 1 year ago

Nicely done ! If I understand correctly, WrapParagraph will return at most WrapAfterLine (unless its zero), right? Maybe that could appear explicitly in the doc?

Done!

whereswaldon commented 1 year ago

Thanks all!