From 5b524dadd8908fbb1361cc7234927577df3a60e2 Mon Sep 17 00:00:00 2001 From: faiface Date: Sun, 7 May 2017 20:59:41 +0200 Subject: [PATCH] add Atlas.DrawRune --- text/atlas.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/text/atlas.go b/text/atlas.go index 0461e2d..9624ebe 100644 --- a/text/atlas.go +++ b/text/atlas.go @@ -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 +}