mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
text: Avoid creating 0-sized image
This commit is contained in:
parent
dff492955d
commit
6caebc2310
74
text/text.go
74
text/text.go
@ -148,46 +148,48 @@ func getGlyphImages(face font.Face, runes []rune) []*glyphImage {
|
|||||||
neededGlyphs[i] = b
|
neededGlyphs[i] = b
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: What if w2 is too big (e.g. > 4096)?
|
if len(neededGlyphs) > 0 {
|
||||||
w2 := 0
|
// TODO: What if w2 is too big (e.g. > 4096)?
|
||||||
h2 := 0
|
w2 := 0
|
||||||
for _, b := range neededGlyphs {
|
h2 := 0
|
||||||
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
for _, b := range neededGlyphs {
|
||||||
w2 += w
|
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
||||||
if h2 < h {
|
w2 += w
|
||||||
h2 = h
|
if h2 < h {
|
||||||
|
h2 = h
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
rgba := image.NewRGBA(image.Rect(0, 0, w2, h2))
|
||||||
rgba := image.NewRGBA(image.Rect(0, 0, w2, h2))
|
|
||||||
|
|
||||||
x := 0
|
x := 0
|
||||||
for i, b := range neededGlyphs {
|
for i, b := range neededGlyphs {
|
||||||
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
||||||
|
|
||||||
r := runes[i]
|
r := runes[i]
|
||||||
d := font.Drawer{
|
d := font.Drawer{
|
||||||
Dst: rgba,
|
Dst: rgba,
|
||||||
Src: image.White,
|
Src: image.White,
|
||||||
Face: face,
|
Face: face,
|
||||||
|
}
|
||||||
|
d.Dot = fixed.Point26_6{fixed.I(x) - b.Min.X, -b.Min.Y}
|
||||||
|
d.DrawString(string(r))
|
||||||
|
|
||||||
|
img, _ := ebiten.NewImageFromImage(rgba, ebiten.FilterDefault)
|
||||||
|
g := &glyphImage{
|
||||||
|
image: img,
|
||||||
|
x: x,
|
||||||
|
y: 0,
|
||||||
|
width: w,
|
||||||
|
height: h,
|
||||||
|
}
|
||||||
|
glyphImageCache[face][r] = &glyphImageCacheEntry{
|
||||||
|
image: g,
|
||||||
|
atime: now(),
|
||||||
|
}
|
||||||
|
imgs[i] = g
|
||||||
|
|
||||||
|
x += w
|
||||||
}
|
}
|
||||||
d.Dot = fixed.Point26_6{fixed.I(x) - b.Min.X, -b.Min.Y}
|
|
||||||
d.DrawString(string(r))
|
|
||||||
|
|
||||||
img, _ := ebiten.NewImageFromImage(rgba, ebiten.FilterDefault)
|
|
||||||
g := &glyphImage{
|
|
||||||
image: img,
|
|
||||||
x: x,
|
|
||||||
y: 0,
|
|
||||||
width: w,
|
|
||||||
height: h,
|
|
||||||
}
|
|
||||||
glyphImageCache[face][r] = &glyphImageCacheEntry{
|
|
||||||
image: g,
|
|
||||||
atime: now(),
|
|
||||||
}
|
|
||||||
imgs[i] = g
|
|
||||||
|
|
||||||
x += w
|
|
||||||
}
|
}
|
||||||
return imgs
|
return imgs
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user