diff --git a/recommend.go b/recommend.go new file mode 100644 index 0000000..db9d14e --- /dev/null +++ b/recommend.go @@ -0,0 +1,37 @@ +package typeset + +import "golang.org/x/image/font" +import "golang.org/x/image/math/fixed" + +func recommendHeight (tokens []token, face font.Face, width fixed.Int26_6) fixed.Int26_6 { + metrics := face.Metrics() + var dot fixed.Point26_6 + + newline := func () { + dot.Y += metrics.Height + dot.X = 0 + } + + sawLineBreak := false + for _, token := range tokens { + // demarcate lines + if sawLineBreak { + newline() + sawLineBreak = false + } + if token.kind == tokenKindLineBreak { + sawLineBreak = true + } else { + needWrap := + token.kind == tokenKindWord && + dot.X + token.width > width + if needWrap { + newline() + } + dot.X += token.width + } + } + newline() + + return dot.Y +}