add Text.Bounds, Atlas.Ascent, Atlas.Descent

This commit is contained in:
faiface 2017-05-05 16:02:47 +02:00
parent e9a3c900cf
commit c47d77b2b5
1 changed files with 16 additions and 4 deletions

View File

@ -20,6 +20,8 @@ type Atlas struct {
pic pixel.Picture
mapping map[rune]Glyph
kern map[struct{ r0, r1 rune }]float64
ascent float64
descent float64
lineHeight float64
}
@ -95,10 +97,12 @@ func NewAtlas(face font.Face, runes []rune) *Atlas {
}
return &Atlas{
pixel.PictureDataFromImage(atlasImg),
mapping,
kern,
float64(face.Metrics().Height) / (1 << 6),
pic: pixel.PictureDataFromImage(atlasImg),
mapping: mapping,
kern: kern,
ascent: float64(face.Metrics().Ascent) / (1 << 6),
descent: float64(face.Metrics().Descent) / (1 << 6),
lineHeight: float64(face.Metrics().Height) / (1 << 6),
}
}
@ -119,6 +123,14 @@ func (a *Atlas) Kern(r0, r1 rune) float64 {
return a.kern[struct{ r0, r1 rune }{r0, r1}]
}
func (a *Atlas) Ascent() float64 {
return a.ascent
}
func (a *Atlas) Descent() float64 {
return a.descent
}
func (a *Atlas) LineHeight() float64 {
return a.lineHeight
}