Text bounds are now returned correctly

This commit is contained in:
2023-09-14 20:28:32 -04:00
parent c4dce027ef
commit 388a113a01
2 changed files with 23 additions and 17 deletions
+9 -5
View File
@@ -111,7 +111,7 @@ type LineLayout struct {
// wrap is set to true, this function will stop processing words once maxWidth
// is crossed. The word which would have crossed over the limit will not be
// processed.
func DoLine (text []rune, face font.Face, wrap bool, maxWidth fixed.Int26_6) (line LineLayout, remaining []rune) {
func DoLine (text []rune, face font.Face, wrap bool, width fixed.Int26_6) (line LineLayout, remaining []rune) {
remaining = text
x := fixed.Int26_6(0)
lastWord := WordLayout { }
@@ -122,9 +122,9 @@ func DoLine (text []rune, face font.Face, wrap bool, maxWidth fixed.Int26_6) (li
word.X = x
x += word.Width
// if we have gone over the maximum width, stop processing
// if we have gone over the preferred width, stop processing
// words (if wrap is enabled)
if !isFirstWord && wrap && x > maxWidth {
if !isFirstWord && wrap && x > width {
break
}
@@ -149,9 +149,13 @@ func DoLine (text []rune, face font.Face, wrap bool, maxWidth fixed.Int26_6) (li
}
// set the width of the line's content.
line.Width = maxWidth
line.ContentWidth = lastWord.X + lastWord.Width
line.SpaceAfter = lastWord.SpaceAfter
if wrap {
line.Width = width
} else {
line.Width = line.ContentWidth
}
line.SpaceAfter = lastWord.SpaceAfter
return
}