line: do not allocate new uniform
This commit is contained in:
parent
8e6affff41
commit
26651ce252
@ -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 {
|
||||
|
4
line.go
4
line.go
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user