mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
text/v2: add a non-image glyphs for index info
This commit is contained in:
parent
800835d081
commit
668124d25c
@ -125,6 +125,9 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
// You can customize how to render each glyph.
|
||||
// In this example, multiple colors are used to render glyphs.
|
||||
for i, gl := range g.glyphs {
|
||||
if gl.Image == nil {
|
||||
continue
|
||||
}
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(x, y)
|
||||
op.GeoM.Translate(gl.X, gl.Y)
|
||||
|
@ -300,7 +300,8 @@ func (g *GoTextFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffse
|
||||
_, gs := g.Source.shape(line, g)
|
||||
for _, glyph := range gs {
|
||||
img, imgX, imgY := g.glyphImage(glyph, origin)
|
||||
if img != nil {
|
||||
// Append a glyph even if img is nil.
|
||||
// This is necessary to return index information for control characters.
|
||||
glyphs = append(glyphs, Glyph{
|
||||
StartIndexInBytes: indexOffset + glyph.startIndex,
|
||||
EndIndexInBytes: indexOffset + glyph.endIndex,
|
||||
@ -309,7 +310,6 @@ func (g *GoTextFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffse
|
||||
X: float64(imgX),
|
||||
Y: float64(imgY),
|
||||
})
|
||||
}
|
||||
origin = origin.Add(fixed.Point26_6{
|
||||
X: glyph.shapingGlyph.XAdvance,
|
||||
Y: -glyph.shapingGlyph.YAdvance,
|
||||
|
@ -106,6 +106,9 @@ func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) {
|
||||
|
||||
geoM := options.GeoM
|
||||
for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) {
|
||||
if g.Image == nil {
|
||||
continue
|
||||
}
|
||||
op := &options.DrawImageOptions
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(g.X, g.Y)
|
||||
|
@ -108,10 +108,13 @@ func (s *StdFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffset i
|
||||
origin.X += s.f.Kern(prevR, r)
|
||||
}
|
||||
img, imgX, imgY, a := s.glyphImage(r, origin)
|
||||
if img != nil {
|
||||
|
||||
// Adjust the position to the integers.
|
||||
// The current glyph images assume that they are rendered on integer positions so far.
|
||||
_, size := utf8.DecodeRuneInString(line[i:])
|
||||
|
||||
// Append a glyph even if img is nil.
|
||||
// This is necessary to return index information for control characters.
|
||||
glyphs = append(glyphs, Glyph{
|
||||
StartIndexInBytes: indexOffset + i,
|
||||
EndIndexInBytes: indexOffset + i + size,
|
||||
@ -119,7 +122,6 @@ func (s *StdFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffset i
|
||||
X: float64(imgX),
|
||||
Y: float64(imgY),
|
||||
})
|
||||
}
|
||||
origin.X += a
|
||||
prevR = r
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user