From ee345c10ef67aebaeea47f8f17bf90cc40e44c2f Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 7 Aug 2023 00:59:02 -0400 Subject: [PATCH] A blank line is now added to the end of TypeSetter when needed --- setter.go | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/setter.go b/setter.go index 718fa5a..610836b 100644 --- a/setter.go +++ b/setter.go @@ -34,23 +34,15 @@ func (setter *TypeSetter) needLayout () { setter.layoutBounds = image.Rectangle { } setter.layoutBoundsSpace = image.Rectangle { } setter.minWidth = 0 - if len(setter.text) == 0 { return } if setter.face == nil { return } horizontalExtent := fixed.Int26_6(0) horizontalExtentSpace := fixed.Int26_6(0) - - metrics := setter.face.Metrics() - remaining := setter.text - y := fixed.Int26_6(0) - for len(remaining) > 0 { - // process one line - line, remainingFromLine := DoLine ( - remaining, setter.face, setter.wrap, - fixed.I(setter.maxWidth)) - remaining = remainingFromLine - - // add the line + metrics := setter.face.Metrics() + remaining := setter.text + y := fixed.Int26_6(0) + + addLine := func (line LineLayout) { line.Y = y y += metrics.Height if line.ContentWidth > horizontalExtent { @@ -62,8 +54,25 @@ func (setter *TypeSetter) needLayout () { } setter.lines = append(setter.lines, line) } - setter.minWidth = horizontalExtentSpace + // process every line + for len(remaining) > 0 { + line, remainingFromLine := DoLine ( + remaining, setter.face, setter.wrap, + fixed.I(setter.maxWidth)) + remaining = remainingFromLine + addLine(line) + } + + // if there were no lines processed or the last line has a break after + // it, add a blank line at the end + needBlankLine := + len(setter.lines) == 0 || + setter.lines[len(setter.lines) - 1].BreakAfter + if needBlankLine { addLine(LineLayout { }) } + + // calculate layout boundaries + setter.minWidth = horizontalExtentSpace setter.layoutBounds.Max.X = setter.maxWidth setter.layoutBoundsSpace.Max.X = setter.maxWidth