add Atlas.DrawRune

This commit is contained in:
faiface 2017-05-07 20:59:41 +02:00
parent a86876a1cd
commit 5b524dadd8
1 changed files with 34 additions and 0 deletions

View File

@ -134,3 +134,37 @@ func (a *Atlas) Descent() float64 {
func (a *Atlas) LineHeight() float64 {
return a.lineHeight
}
func (a *Atlas) DrawRune(prevR, r rune, dot pixel.Vec) (rect, frame, bounds pixel.Rect, newDot pixel.Vec) {
if !a.Contains(r) {
r = unicode.ReplacementChar
}
if !a.Contains(unicode.ReplacementChar) {
return pixel.Rect{}, pixel.Rect{}, pixel.Rect{}, dot
}
if !a.Contains(prevR) {
prevR = unicode.ReplacementChar
}
if prevR >= 0 {
dot += pixel.X(a.Kern(prevR, r))
}
glyph := a.Glyph(r)
rect = glyph.Frame.Moved(dot - glyph.Orig)
bounds = rect
if bounds.W()*bounds.H() != 0 {
bounds = pixel.R(
bounds.Min.X(),
dot.Y()-a.Descent(),
bounds.Max.X(),
dot.Y()+a.Ascent(),
)
}
dot += pixel.X(glyph.Advance)
return rect, glyph.Frame, bounds, dot
}