mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
text: Remove the optimization for GopherJS
This commit is contained in:
parent
00f3d83d4c
commit
a046700ae1
16
text/text.go
16
text/text.go
@ -60,20 +60,19 @@ func drawGlyph(dst *ebiten.Image, face font.Face, r rune, img *ebiten.Image, x,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Use pointers as copying is expensive on GopherJS.
|
glyphBoundsCache = map[font.Face]map[rune]fixed.Rectangle26_6{}
|
||||||
glyphBoundsCache = map[font.Face]map[rune]*fixed.Rectangle26_6{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getGlyphBounds(face font.Face, r rune) *fixed.Rectangle26_6 {
|
func getGlyphBounds(face font.Face, r rune) fixed.Rectangle26_6 {
|
||||||
if _, ok := glyphBoundsCache[face]; !ok {
|
if _, ok := glyphBoundsCache[face]; !ok {
|
||||||
glyphBoundsCache[face] = map[rune]*fixed.Rectangle26_6{}
|
glyphBoundsCache[face] = map[rune]fixed.Rectangle26_6{}
|
||||||
}
|
}
|
||||||
if b, ok := glyphBoundsCache[face][r]; ok {
|
if b, ok := glyphBoundsCache[face][r]; ok {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
b, _, _ := face.GlyphBounds(r)
|
b, _, _ := face.GlyphBounds(r)
|
||||||
glyphBoundsCache[face][r] = &b
|
glyphBoundsCache[face][r] = b
|
||||||
return &b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
type glyphImageCacheEntry struct {
|
type glyphImageCacheEntry struct {
|
||||||
@ -95,7 +94,7 @@ func getGlyphImages(face font.Face, runes []rune) []*ebiten.Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imgs := make([]*ebiten.Image, len(runes))
|
imgs := make([]*ebiten.Image, len(runes))
|
||||||
glyphBounds := map[rune]*fixed.Rectangle26_6{}
|
glyphBounds := map[rune]fixed.Rectangle26_6{}
|
||||||
neededGlyphIndices := map[int]rune{}
|
neededGlyphIndices := map[int]rune{}
|
||||||
for i, r := range runes {
|
for i, r := range runes {
|
||||||
if _, ok := emptyGlyphs[face][r]; ok {
|
if _, ok := emptyGlyphs[face][r]; ok {
|
||||||
@ -262,8 +261,7 @@ func BoundString(face font.Face, text string) image.Rectangle {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
bp := getGlyphBounds(face, r)
|
b := getGlyphBounds(face, r)
|
||||||
b := *bp
|
|
||||||
b.Min.X += fx
|
b.Min.X += fx
|
||||||
b.Max.X += fx
|
b.Max.X += fx
|
||||||
b.Min.Y += fy
|
b.Min.Y += fy
|
||||||
|
Loading…
Reference in New Issue
Block a user