mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 12:32:05 +01:00
text/v2: refactoring
This commit is contained in:
parent
7c40b5f922
commit
9735687d3e
@ -95,15 +95,17 @@ func (s *StdFace) advance(text string) float64 {
|
|||||||
func (s *StdFace) appendGlyphs(glyphs []Glyph, text string, originX, originY float64) []Glyph {
|
func (s *StdFace) appendGlyphs(glyphs []Glyph, text string, originX, originY float64) []Glyph {
|
||||||
s.copyCheck()
|
s.copyCheck()
|
||||||
|
|
||||||
x := float64ToFixed26_6(originX)
|
origin := fixed.Point26_6{
|
||||||
y := float64ToFixed26_6(originY)
|
X: float64ToFixed26_6(originX),
|
||||||
|
Y: float64ToFixed26_6(originY),
|
||||||
|
}
|
||||||
prevR := rune(-1)
|
prevR := rune(-1)
|
||||||
|
|
||||||
for i, r := range text {
|
for i, r := range text {
|
||||||
if prevR >= 0 {
|
if prevR >= 0 {
|
||||||
x += s.f.Kern(prevR, r)
|
origin.X += s.f.Kern(prevR, r)
|
||||||
}
|
}
|
||||||
img, imgX, imgY, a := s.glyphImage(r, x, y)
|
img, imgX, imgY, a := s.glyphImage(r, origin)
|
||||||
if img != nil {
|
if img != nil {
|
||||||
// Adjust the position to the integers.
|
// Adjust the position to the integers.
|
||||||
// The current glyph images assume that they are rendered on integer positions so far.
|
// The current glyph images assume that they are rendered on integer positions so far.
|
||||||
@ -115,18 +117,18 @@ func (s *StdFace) appendGlyphs(glyphs []Glyph, text string, originX, originY flo
|
|||||||
Y: imgY,
|
Y: imgY,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
x += a
|
origin.X += a
|
||||||
prevR = r
|
prevR = r
|
||||||
}
|
}
|
||||||
|
|
||||||
return glyphs
|
return glyphs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StdFace) glyphImage(r rune, x, y fixed.Int26_6) (*ebiten.Image, float64, float64, fixed.Int26_6) {
|
func (s *StdFace) glyphImage(r rune, origin fixed.Point26_6) (*ebiten.Image, float64, float64, fixed.Int26_6) {
|
||||||
b, a, _ := s.f.GlyphBounds(r)
|
b, a, _ := s.f.GlyphBounds(r)
|
||||||
offset := fixed.Point26_6{
|
offset := fixed.Point26_6{
|
||||||
X: (adjustOffsetGranularity(x) + b.Min.X) & ((1 << 6) - 1),
|
X: (adjustOffsetGranularity(origin.X) + b.Min.X) & ((1 << 6) - 1),
|
||||||
Y: (fixed.I(y.Floor()) + b.Min.Y) & ((1 << 6) - 1),
|
Y: (fixed.I(origin.Y.Floor()) + b.Min.Y) & ((1 << 6) - 1),
|
||||||
}
|
}
|
||||||
key := glyphImageCacheKey{
|
key := glyphImageCacheKey{
|
||||||
rune: r,
|
rune: r,
|
||||||
@ -136,8 +138,8 @@ func (s *StdFace) glyphImage(r rune, x, y fixed.Int26_6) (*ebiten.Image, float64
|
|||||||
img := theGlyphImageCache.getOrCreate(s, key, func() *ebiten.Image {
|
img := theGlyphImageCache.getOrCreate(s, key, func() *ebiten.Image {
|
||||||
return s.glyphImageImpl(r, offset)
|
return s.glyphImageImpl(r, offset)
|
||||||
})
|
})
|
||||||
imgX := fixed26_6ToFloat64(x + b.Min.X - offset.X)
|
imgX := fixed26_6ToFloat64(origin.X + b.Min.X - offset.X)
|
||||||
imgY := fixed26_6ToFloat64(y + b.Min.Y - offset.Y)
|
imgY := fixed26_6ToFloat64(origin.Y + b.Min.Y - offset.Y)
|
||||||
return img, imgX, imgY, a
|
return img, imgX, imgY, a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user