Advance by char width+better debug tools

This commit is contained in:
bloeys
2022-07-08 07:58:08 +04:00
parent 2da4b7a53d
commit 9388bc0c92
5 changed files with 31 additions and 18 deletions

View File

@ -35,6 +35,7 @@ type FontAtlasGlyph struct {
Ascent float32
Descent float32
BearingX float32
Advance float32
}
//NewFontAtlasFromFile reads a TTF or TTC file and produces a font texture atlas containing
@ -149,7 +150,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
for currGlyphCount, g := range glyphs {
gBounds, _, _ := face.GlyphBounds(g)
gBounds, gAdvance, _ := face.GlyphBounds(g)
bearingX := gBounds.Min.X
ascentAbsFixed := absFixedI26_6(gBounds.Min.Y)
descentAbsFixed := absFixedI26_6(gBounds.Max.Y)
@ -174,6 +175,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
Ascent: float32(ascentAbsFixed.Ceil()),
Descent: float32(descentAbsFixed.Ceil()),
BearingX: float32(bearingX.Ceil()),
Advance: float32(gAdvance.Ceil()),
}
imgRect, mask, maskp, _, _ := face.Glyph(drawer.Dot, g)

View File

@ -178,15 +178,13 @@ func (gr *GlyphRend) drawRune(rs []rune, i int, prevRune rune, screenPos, pos *g
*bufIndex += 2
gr.GlyphCount++
pos.AddX(advanceF32)
pos.AddX(g.Advance)
//If we fill the buffer we issue a draw call
if gr.GlyphCount == MaxGlyphsPerBatch {
gr.Draw()
*bufIndex = 0
}
// prevRune = r
}
func (gr *GlyphRend) GetTextRuns(t string) [][]rune {