text: fix typos and add fields to struct initializers (#2556)

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto 2023-01-27 16:14:37 +01:00 committed by GitHub
parent 7502da50ba
commit 04170d628f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -270,7 +270,7 @@ func DrawWithOptions(dst *ebiten.Image, text string, face font.Face, options *eb
// cacheSoftLimit indicates the soft limit of the number of glyphs in the cache.
// If the number of glyphs exceeds this soft limits, old glyphs are removed.
// Even after clearning up the cache, the number of glyphs might still exceeds the soft limit, but
// Even after cleaning up the cache, the number of glyphs might still exceed the soft limit, but
// this is fine.
const cacheSoftLimit = 512
@ -363,7 +363,7 @@ func BoundString(face font.Face, text string) image.Rectangle {
//
// If a rune's glyph is already cached, CacheGlyphs does nothing for the rune.
//
// One rune can have multiple varitations of glyphs due to sub-pixels in X direction.
// One rune can have multiple variations of glyphs due to sub-pixels in X direction.
// CacheGlyphs creates all such variations for one rune, while Draw creates only necessary glyphs.
func CacheGlyphs(face font.Face, text string) {
textM.Lock()
@ -435,7 +435,7 @@ func (f faceWithLineHeight) Metrics() font.Metrics {
return m
}
// Glyphs is information to render one glyph.
// Glyph is information to render one glyph.
type Glyph struct {
// Rune is a character for this glyph.
Rune rune
@ -484,7 +484,6 @@ func AppendGlyphs(glyphs []Glyph, face font.Face, text string) []Glyph {
Y: b.Min.Y & ((1 << 6) - 1),
}
if img := getGlyphImage(face, r, offset); img != nil {
b := getGlyphBounds(face, r)
// Adjust the position to the integers.
// The current glyph images assume that they are rendered on integer positions so far.
glyphs = append(glyphs, Glyph{

View File

@ -33,7 +33,7 @@ func TestMain(m *testing.M) {
}
func TestTextColor(t *testing.T) {
clr := color.RGBA{0x80, 0x80, 0x80, 0x80}
clr := color.RGBA{R: 0x80, G: 0x80, B: 0x80, A: 0x80}
img := ebiten.NewImage(30, 30)
text.Draw(img, "Hello", bitmapfont.Face, 12, 12, clr)
@ -42,7 +42,7 @@ func TestTextColor(t *testing.T) {
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := img.At(i, j)
want1 := color.RGBA{0x80, 0x80, 0x80, 0x80}
want1 := color.RGBA{R: 0x80, G: 0x80, B: 0x80, A: 0x80}
want2 := color.RGBA{}
if got != want1 && got != want2 {
t.Errorf("img At(%d, %d): got %v; want %v or %v", i, j, got, want1, want2)
@ -68,13 +68,13 @@ func (f *testFace) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, mask
case 'a':
for j := 0; j < testFaceSize; j++ {
for i := 0; i < testFaceSize; i++ {
a.SetAlpha(i, j, color.Alpha{0x80})
a.SetAlpha(i, j, color.Alpha{A: 0x80})
}
}
case 'b':
for j := 0; j < testFaceSize; j++ {
for i := 0; i < testFaceSize; i++ {
a.SetAlpha(i, j, color.Alpha{0xff})
a.SetAlpha(i, j, color.Alpha{A: 0xff})
}
}
}
@ -127,7 +127,7 @@ func TestTextOverlap(t *testing.T) {
for j := 0; j < testFaceSize; j++ {
for i := 0; i < testFaceSize; i++ {
got := dst.At(i, j)
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
want := color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
if got != want {
t.Errorf("At(%d, %d): got: %v, want: %v", i, j, got, want)
}
@ -139,7 +139,7 @@ func TestTextOverlap(t *testing.T) {
for j := 0; j < testFaceSize; j++ {
for i := testFaceSize; i < testFaceSize*2; i++ {
got := dst.At(i, j)
want := color.RGBA{0x80, 0x80, 0x80, 0x80}
want := color.RGBA{R: 0x80, G: 0x80, B: 0x80, A: 0x80}
if got != want {
t.Errorf("At(%d, %d): got: %v, want: %v", i, j, got, want)
}