mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
7afac3f1ad
commit
05e23bd55c
1 changed files with 12 additions and 8 deletions
|
@ -91,16 +91,20 @@ func (f textFilter) Draw(dst draw.Image, src image.Image, options *gift.Options)
|
||||||
y := f.y
|
y := f.y
|
||||||
d.Dot = fixed.P(f.x, f.y)
|
d.Dot = fixed.P(f.x, f.y)
|
||||||
|
|
||||||
// Draw text and break line at max width
|
// Draw text line by line, breaking each line at the maximum width.
|
||||||
parts := strings.Fields(f.text)
|
f.text = strings.ReplaceAll(f.text, "\r", "")
|
||||||
for _, str := range parts {
|
for _, line := range strings.Split(f.text, "\n") {
|
||||||
strWith := font.MeasureString(face, str)
|
for _, str := range strings.Fields(line) {
|
||||||
if (d.Dot.X.Ceil() + strWith.Ceil()) >= maxWidth {
|
strWidth := font.MeasureString(face, str)
|
||||||
|
if (d.Dot.X.Ceil() + strWidth.Ceil()) >= maxWidth {
|
||||||
y = y + fontHeight + f.linespacing
|
y = y + fontHeight + f.linespacing
|
||||||
d.Dot = fixed.P(f.x, y)
|
d.Dot = fixed.P(f.x, y)
|
||||||
}
|
}
|
||||||
d.DrawString(str + " ")
|
d.DrawString(str + " ")
|
||||||
}
|
}
|
||||||
|
y = y + fontHeight + f.linespacing
|
||||||
|
d.Dot = fixed.P(f.x, y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f textFilter) Bounds(srcBounds image.Rectangle) image.Rectangle {
|
func (f textFilter) Bounds(srcBounds image.Rectangle) image.Rectangle {
|
||||||
|
|
Loading…
Reference in a new issue