Add getMaxLineWidth method on StyledParagraph

This commit is contained in:
Adrian-George Bostan 2018-10-08 17:34:57 +03:00
parent fb41824815
commit db93b6e873

View File

@ -264,10 +264,10 @@ func (p *StyledParagraph) getTextLineWidth(line []TextChunk) float64 {
for _, chunk := range line {
style := &chunk.Style
for _, rune := range chunk.Text {
glyph, found := p.encoder.RuneToGlyph(rune)
for _, r := range chunk.Text {
glyph, found := p.encoder.RuneToGlyph(r)
if !found {
common.Log.Debug("Error! Glyph not found for rune: %s\n", rune)
common.Log.Debug("Error! Glyph not found for rune: %s\n", r)
// XXX/FIXME: return error.
return -1
@ -293,6 +293,23 @@ func (p *StyledParagraph) getTextLineWidth(line []TextChunk) float64 {
return width
}
// getMaxLineWidth returns the width of the longest line of text in the paragraph.
func (p *StyledParagraph) getMaxLineWidth() float64 {
if p.lines == nil || len(p.lines) == 0 {
p.wrapText()
}
var width float64
for _, line := range p.lines {
w := p.getTextLineWidth(line)
if w > width {
width = w
}
}
return width
}
// getTextHeight calculates the text height as if all in one line (not taking wrapping into account).
func (p *StyledParagraph) getTextHeight() float64 {
var height float64