account for leading/trailing newlines when measuring code shapes
This commit is contained in:
parent
3d3d6235ba
commit
7f13be1524
1 changed files with 21 additions and 0 deletions
|
|
@ -1027,6 +1027,27 @@ func GetTextDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler, t *d2
|
||||||
var h int
|
var h int
|
||||||
if t.Language != "" {
|
if t.Language != "" {
|
||||||
w, h = ruler.Measure(d2fonts.SourceCodePro.Font(t.FontSize, d2fonts.FONT_STYLE_REGULAR), t.Text)
|
w, h = ruler.Measure(d2fonts.SourceCodePro.Font(t.FontSize, d2fonts.FONT_STYLE_REGULAR), t.Text)
|
||||||
|
|
||||||
|
// count empty leading and trailing lines since ruler will not be able to measure it
|
||||||
|
lines := strings.Split(t.Text, "\n")
|
||||||
|
leadingLines := 0
|
||||||
|
for _, line := range lines {
|
||||||
|
if strings.TrimSpace(line) == "" {
|
||||||
|
leadingLines++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trailingLines := 0
|
||||||
|
for i := len(lines) - 1; i >= 0; i-- {
|
||||||
|
if strings.TrimSpace(lines[i]) == "" {
|
||||||
|
trailingLines++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h += t.FontSize * (leadingLines + trailingLines)
|
||||||
|
|
||||||
// padding
|
// padding
|
||||||
w += 12
|
w += 12
|
||||||
h += 12
|
h += 12
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue