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.
|
||||
// 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,16 +300,16 @@ 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 {
|
||||
glyphs = append(glyphs, Glyph{
|
||||
StartIndexInBytes: indexOffset + glyph.startIndex,
|
||||
EndIndexInBytes: indexOffset + glyph.endIndex,
|
||||
GID: uint32(glyph.shapingGlyph.GlyphID),
|
||||
Image: img,
|
||||
X: float64(imgX),
|
||||
Y: float64(imgY),
|
||||
})
|
||||
}
|
||||
// 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,
|
||||
GID: uint32(glyph.shapingGlyph.GlyphID),
|
||||
Image: img,
|
||||
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,18 +108,20 @@ 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:])
|
||||
glyphs = append(glyphs, Glyph{
|
||||
StartIndexInBytes: indexOffset + i,
|
||||
EndIndexInBytes: indexOffset + i + size,
|
||||
Image: img,
|
||||
X: float64(imgX),
|
||||
Y: float64(imgY),
|
||||
})
|
||||
}
|
||||
|
||||
// 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,
|
||||
Image: img,
|
||||
X: float64(imgX),
|
||||
Y: float64(imgY),
|
||||
})
|
||||
origin.X += a
|
||||
prevR = r
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user