line: do not allocate new uniform

This commit is contained in:
Yonah 2025-07-13 02:08:38 +09:00
parent 8e6affff41
commit 26651ce252
Signed by: yonah
SSH Key Fingerprint: SHA256:vnQvK8+XXH9Tbni2AV1a/8qdVK/zPcXw52GM0ruQvwA
2 changed files with 10 additions and 10 deletions

View File

@ -32,6 +32,7 @@ func TestRender(t *testing.T) {
0, 0, "", truetype.FormatError("TTF data is too short")},
{"bad fast path font", &caption.Line{}, caption.NewContext([]byte{0xfd}, nil),
0, 0, "", truetype.FormatError("TTF data is too short")},
{"custom line options", &caption.Line{
Data: []caption.Segment{{"Beispieltext", color.Black}},
Options: &truetype.Options{Size: 24},
@ -77,18 +78,17 @@ func TestRender(t *testing.T) {
redraw:
got := image.NewRGBA64(image.Rectangle{Max: image.Point{X: 1 << 10, Y: 1 << 9}})
err := tc.line.Render(ctx, got, tc.x, tc.y)
if err != nil {
if !errors.Is(err, tc.wantErr) {
t.Errorf("Render: error = %q, want %q",
err, tc.wantErr)
}
return
}
for _, f := range beforeCheck {
f(t, tc.name, redraw == "", got)
}
if !errors.Is(err, tc.wantErr) {
t.Fatalf("Render: error = %q, want %q", err, tc.wantErr)
}
if err != nil {
return
}
t.Run("hash"+redraw, func(t *testing.T) {
var wantDigest []byte
if wantDigest, err = hex.DecodeString(tc.want); err != nil {

View File

@ -59,9 +59,9 @@ func (l *Line) Render(ctx *Context, frame draw.Image, x, y int) error {
face = ctx.defaultFont
}
drawer := &font.Drawer{Dst: frame, Face: face, Dot: fixed.Point26_6{X: fixed.I(x), Y: fixed.I(y)}}
drawer := &font.Drawer{Dst: frame, Src: new(image.Uniform), Face: face, Dot: fixed.Point26_6{X: fixed.I(x), Y: fixed.I(y)}}
for _, seg := range l.Data {
drawer.Src = image.NewUniform(seg.Color)
drawer.Src.(*image.Uniform).C = seg.Color
drawer.DrawString(seg.Value)
}