mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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.
|
// You can customize how to render each glyph.
|
||||||
// In this example, multiple colors are used to render glyphs.
|
// In this example, multiple colors are used to render glyphs.
|
||||||
for i, gl := range g.glyphs {
|
for i, gl := range g.glyphs {
|
||||||
|
if gl.Image == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
op.GeoM.Reset()
|
op.GeoM.Reset()
|
||||||
op.GeoM.Translate(x, y)
|
op.GeoM.Translate(x, y)
|
||||||
op.GeoM.Translate(gl.X, gl.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)
|
_, gs := g.Source.shape(line, g)
|
||||||
for _, glyph := range gs {
|
for _, glyph := range gs {
|
||||||
img, imgX, imgY := g.glyphImage(glyph, origin)
|
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{
|
glyphs = append(glyphs, Glyph{
|
||||||
StartIndexInBytes: indexOffset + glyph.startIndex,
|
StartIndexInBytes: indexOffset + glyph.startIndex,
|
||||||
EndIndexInBytes: indexOffset + glyph.endIndex,
|
EndIndexInBytes: indexOffset + glyph.endIndex,
|
||||||
@ -309,7 +310,6 @@ func (g *GoTextFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffse
|
|||||||
X: float64(imgX),
|
X: float64(imgX),
|
||||||
Y: float64(imgY),
|
Y: float64(imgY),
|
||||||
})
|
})
|
||||||
}
|
|
||||||
origin = origin.Add(fixed.Point26_6{
|
origin = origin.Add(fixed.Point26_6{
|
||||||
X: glyph.shapingGlyph.XAdvance,
|
X: glyph.shapingGlyph.XAdvance,
|
||||||
Y: -glyph.shapingGlyph.YAdvance,
|
Y: -glyph.shapingGlyph.YAdvance,
|
||||||
|
@ -106,6 +106,9 @@ func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) {
|
|||||||
|
|
||||||
geoM := options.GeoM
|
geoM := options.GeoM
|
||||||
for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) {
|
for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) {
|
||||||
|
if g.Image == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
op := &options.DrawImageOptions
|
op := &options.DrawImageOptions
|
||||||
op.GeoM.Reset()
|
op.GeoM.Reset()
|
||||||
op.GeoM.Translate(g.X, g.Y)
|
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)
|
origin.X += s.f.Kern(prevR, r)
|
||||||
}
|
}
|
||||||
img, imgX, imgY, a := s.glyphImage(r, origin)
|
img, imgX, imgY, a := s.glyphImage(r, origin)
|
||||||
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.
|
||||||
_, size := utf8.DecodeRuneInString(line[i:])
|
_, 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{
|
glyphs = append(glyphs, Glyph{
|
||||||
StartIndexInBytes: indexOffset + i,
|
StartIndexInBytes: indexOffset + i,
|
||||||
EndIndexInBytes: indexOffset + i + size,
|
EndIndexInBytes: indexOffset + i + size,
|
||||||
@ -119,7 +122,6 @@ func (s *StdFace) appendGlyphsForLine(glyphs []Glyph, line string, indexOffset i
|
|||||||
X: float64(imgX),
|
X: float64(imgX),
|
||||||
Y: float64(imgY),
|
Y: float64(imgY),
|
||||||
})
|
})
|
||||||
}
|
|
||||||
origin.X += a
|
origin.X += a
|
||||||
prevR = r
|
prevR = r
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user