A blank line is now added to the end of TypeSetter when needed
This commit is contained in:
parent
6407baed13
commit
ee345c10ef
37
setter.go
37
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user