mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +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
|
// lineHeight captures the gap that should exist between the baseline of this
|
||||||
// line and the previous (if any).
|
// line and the previous (if any).
|
||||||
lineHeight fixed.Int26_6
|
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
|
// 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
|
// 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
|
// 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,
|
PPEM: run.Size,
|
||||||
}
|
}
|
||||||
line.runeCount += run.Runes.Count
|
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
|
line.width += run.Advance
|
||||||
if line.ascent < run.LineBounds.Ascent {
|
if line.ascent < run.LineBounds.Ascent {
|
||||||
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
|
line.lineHeight = maxSize
|
||||||
computeVisualOrder(&line)
|
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
|
return line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-21
@@ -52,16 +52,11 @@ func TestEmptyString(t *testing.T) {
|
|||||||
t.Fatalf("Layout returned no lines for empty string; expected 1")
|
t.Fatalf("Layout returned no lines for empty string; expected 1")
|
||||||
}
|
}
|
||||||
l := lines.lines[0]
|
l := lines.lines[0]
|
||||||
exp := fixed.Rectangle26_6{
|
if expected := fixed.Int26_6(12094); l.ascent != expected {
|
||||||
Min: fixed.Point26_6{
|
t.Errorf("unexpected ascent for empty string: %v, expected %v", l.ascent, expected)
|
||||||
Y: fixed.Int26_6(-12094),
|
|
||||||
},
|
|
||||||
Max: fixed.Point26_6{
|
|
||||||
Y: fixed.Int26_6(2700),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
if got := l.bounds; got != exp {
|
if expected := fixed.Int26_6(2700); l.descent != expected {
|
||||||
t.Errorf("got bounds %+v for empty string; expected %+v", got, exp)
|
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
|
totalInputRunes += run.Runes.Count
|
||||||
}
|
}
|
||||||
output := toLine(shaper.faceToIndex, input, tc.dir)
|
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 {
|
if output.direction != tc.dir {
|
||||||
t.Errorf("line %d: expected direction %v, got %v", i, tc.dir, output.direction)
|
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()
|
t.Helper()
|
||||||
runesSeen := 0
|
runesSeen := 0
|
||||||
for i, line := range lines {
|
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)
|
totalRunWidth := fixed.I(0)
|
||||||
totalLineGlyphs := 0
|
totalLineGlyphs := 0
|
||||||
lineRunesSeen := 0
|
lineRunesSeen := 0
|
||||||
|
|||||||
Reference in New Issue
Block a user