mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
text: drop unused line.bounds
This commit removes the logic that calculates the bounding box of a line. We don't actually use this information anywhere, so computing it is just a waste of CPU and memory. Widgets arrive at their own bounding boxes from consuming the glyph stream anyway. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -82,8 +82,6 @@ type line struct {
|
||||
// lineHeight captures the gap that should exist between the baseline of this
|
||||
// line and the previous (if any).
|
||||
lineHeight fixed.Int26_6
|
||||
// bounds is the visible bounds of the line.
|
||||
bounds fixed.Rectangle26_6
|
||||
// direction is the dominant direction of the line. This direction will be
|
||||
// used to align the text content of the line, but may not match the actual
|
||||
// direction of the runs of text within the line (such as an RTL sentence
|
||||
@@ -888,13 +886,6 @@ func toLine(faceToIndex map[font.Font]int, o shaping.Line, dir system.TextDirect
|
||||
PPEM: run.Size,
|
||||
}
|
||||
line.runeCount += run.Runes.Count
|
||||
if line.bounds.Min.Y > -run.LineBounds.Ascent {
|
||||
line.bounds.Min.Y = -run.LineBounds.Ascent
|
||||
}
|
||||
if line.bounds.Max.Y < -run.LineBounds.Ascent+run.LineBounds.LineHeight() {
|
||||
line.bounds.Max.Y = -run.LineBounds.Ascent + run.LineBounds.LineHeight()
|
||||
}
|
||||
line.bounds.Max.X += run.Advance
|
||||
line.width += run.Advance
|
||||
if line.ascent < run.LineBounds.Ascent {
|
||||
line.ascent = run.LineBounds.Ascent
|
||||
@@ -905,20 +896,6 @@ func toLine(faceToIndex map[font.Font]int, o shaping.Line, dir system.TextDirect
|
||||
}
|
||||
line.lineHeight = maxSize
|
||||
computeVisualOrder(&line)
|
||||
// Account for glyphs hanging off of either side in the bounds.
|
||||
if len(line.visualOrder) > 0 {
|
||||
runIdx := line.visualOrder[0]
|
||||
run := o[runIdx]
|
||||
if len(run.Glyphs) > 0 {
|
||||
line.bounds.Min.X = run.Glyphs[0].LeftSideBearing()
|
||||
}
|
||||
runIdx = line.visualOrder[len(line.visualOrder)-1]
|
||||
run = o[runIdx]
|
||||
if len(run.Glyphs) > 0 {
|
||||
lastGlyphIdx := len(run.Glyphs) - 1
|
||||
line.bounds.Max.X += run.Glyphs[lastGlyphIdx].RightSideBearing()
|
||||
}
|
||||
}
|
||||
return line
|
||||
}
|
||||
|
||||
|
||||
+4
-21
@@ -52,16 +52,11 @@ func TestEmptyString(t *testing.T) {
|
||||
t.Fatalf("Layout returned no lines for empty string; expected 1")
|
||||
}
|
||||
l := lines.lines[0]
|
||||
exp := fixed.Rectangle26_6{
|
||||
Min: fixed.Point26_6{
|
||||
Y: fixed.Int26_6(-12094),
|
||||
},
|
||||
Max: fixed.Point26_6{
|
||||
Y: fixed.Int26_6(2700),
|
||||
},
|
||||
if expected := fixed.Int26_6(12094); l.ascent != expected {
|
||||
t.Errorf("unexpected ascent for empty string: %v, expected %v", l.ascent, expected)
|
||||
}
|
||||
if got := l.bounds; got != exp {
|
||||
t.Errorf("got bounds %+v for empty string; expected %+v", got, exp)
|
||||
if expected := fixed.Int26_6(2700); l.descent != expected {
|
||||
t.Errorf("unexpected descent for empty string: %v, expected %v", l.descent, expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,12 +387,6 @@ func TestToLine(t *testing.T) {
|
||||
totalInputRunes += run.Runes.Count
|
||||
}
|
||||
output := toLine(shaper.faceToIndex, input, tc.dir)
|
||||
if output.bounds.Min == (fixed.Point26_6{}) {
|
||||
t.Errorf("line %d: Bounds.Min not populated", i)
|
||||
}
|
||||
if output.bounds.Max == (fixed.Point26_6{}) {
|
||||
t.Errorf("line %d: Bounds.Max not populated", i)
|
||||
}
|
||||
if output.direction != tc.dir {
|
||||
t.Errorf("line %d: expected direction %v, got %v", i, tc.dir, output.direction)
|
||||
}
|
||||
@@ -604,12 +593,6 @@ func validateLines(t *testing.T, lines []line, expectedRuneCount int) {
|
||||
t.Helper()
|
||||
runesSeen := 0
|
||||
for i, line := range lines {
|
||||
if line.bounds.Min == (fixed.Point26_6{}) {
|
||||
t.Errorf("line %d: Bounds.Min not populated", i)
|
||||
}
|
||||
if line.bounds.Max == (fixed.Point26_6{}) {
|
||||
t.Errorf("line %d: Bounds.Max not populated", i)
|
||||
}
|
||||
totalRunWidth := fixed.I(0)
|
||||
totalLineGlyphs := 0
|
||||
lineRunesSeen := 0
|
||||
|
||||
Reference in New Issue
Block a user