mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
widget: fix label vertical glyph padding logic
We previously were not handling glyphs that extended vertically beyond the ascent/descent declared by their font. This is done rarely with text fonts, but is apparently common among symbol and emoji fonts. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -150,11 +150,26 @@ func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visib
|
||||
// Compute the maximum extent to which glyphs overhang on the horizontal
|
||||
// axis.
|
||||
if d := g.Bounds.Min.X.Floor(); d < it.padding.Min.X {
|
||||
// If the distance between the dot and the left edge of this glyph is
|
||||
// less than the current padding, increase the left padding.
|
||||
it.padding.Min.X = d
|
||||
}
|
||||
if d := (g.Bounds.Max.X - g.Advance).Ceil(); d > it.padding.Max.X {
|
||||
// If the distance between the dot and the right edge of this glyph
|
||||
// minus the logical advance of this glyph is greater than the current
|
||||
// padding, increase the right padding.
|
||||
it.padding.Max.X = d
|
||||
}
|
||||
if d := (g.Bounds.Min.Y + g.Ascent).Floor(); d < it.padding.Min.Y {
|
||||
// If the distance between the dot and the top of this glyph is greater
|
||||
// than the ascent of the glyph, increase the top padding.
|
||||
it.padding.Min.Y = d
|
||||
}
|
||||
if d := (g.Bounds.Max.Y - g.Descent).Ceil(); d > it.padding.Max.Y {
|
||||
// If the distance between the dot and the bottom of this glyph is greater
|
||||
// than the descent of the glyph, increase the bottom padding.
|
||||
it.padding.Max.Y = d
|
||||
}
|
||||
logicalBounds := image.Rectangle{
|
||||
Min: image.Pt(g.X.Floor(), int(g.Y)-g.Ascent.Ceil()),
|
||||
Max: image.Pt((g.X + g.Advance).Ceil(), int(g.Y)+g.Descent.Ceil()),
|
||||
|
||||
Reference in New Issue
Block a user