shiny/font: have Face.Glyph return an advance width, not a new dot.

This is consistent with Face.GlyphBounds and Face.GlyphAdvance.

Change-Id: I9da6b4f2fdb8f093fc9567c717e8fbbecc624e30
Reviewed-on: https://go-review.googlesource.com/14090
Reviewed-by: David Symonds <dsymonds@golang.org>
This commit is contained in:
Nigel Tao 2015-08-31 11:16:53 +10:00
parent 627898392a
commit 5ae59125bf
2 changed files with 11 additions and 14 deletions

View File

@ -36,8 +36,8 @@ type Face interface {
io.Closer
// Glyph returns the draw.DrawMask parameters (dr, mask, maskp) to draw r's
// glyph at the sub-pixel destination location dot. It also returns the new
// dot after adding the glyph's advance width.
// glyph at the sub-pixel destination location dot, and that glyph's
// advance width.
//
// It returns !ok if the face does not contain a glyph for r.
//
@ -45,7 +45,7 @@ type Face interface {
// after the next Glyph call. Callers that want to cache the mask must make
// a copy.
Glyph(dot fixed.Point26_6, r rune) (
newDot fixed.Point26_6, dr image.Rectangle, mask image.Image, maskp image.Point, ok bool)
dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool)
// GlyphBounds returns the bounding box of r's glyph, drawn at a dot equal
// to the origin, and that glyph's advance width.
@ -114,7 +114,7 @@ func (d *Drawer) DrawString(s string) {
if i != 0 {
d.Dot.X += d.Face.Kern(prevC, c)
}
newDot, dr, mask, maskp, ok := d.Face.Glyph(d.Dot, c)
dr, mask, maskp, advance, ok := d.Face.Glyph(d.Dot, c)
if !ok {
// TODO: is falling back on the U+FFFD glyph the responsibility of
// the Drawer or the Face?
@ -122,7 +122,8 @@ func (d *Drawer) DrawString(s string) {
continue
}
draw.DrawMask(d.Dst, dr, d.Src, image.Point{}, mask, maskp, draw.Over)
d.Dot, prevC = newDot, c
d.Dot.X += advance
prevC = c
}
}

View File

@ -66,19 +66,15 @@ func (f *subface) Close() error { return nil }
func (f *subface) Kern(r0, r1 rune) fixed.Int26_6 { return 0 }
func (f *subface) Glyph(dot fixed.Point26_6, r rune) (
newDot fixed.Point26_6, dr image.Rectangle, mask image.Image, maskp image.Point, ok bool) {
dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool) {
r -= f.firstRune
if r < 0 || f.n <= int(r) {
return fixed.Point26_6{}, image.Rectangle{}, nil, image.Point{}, false
return image.Rectangle{}, nil, image.Point{}, 0, false
}
i := &f.fontchars[r+0]
j := &f.fontchars[r+1]
newDot = fixed.Point26_6{
X: dot.X + fixed.Int26_6(i.width)<<6,
Y: dot.Y,
}
minX := int(dot.X+32)>>6 + int(i.left)
minY := int(dot.Y+32)>>6 + int(i.top) - f.ascent
dr = image.Rectangle{
@ -91,7 +87,7 @@ func (f *subface) Glyph(dot fixed.Point26_6, r rune) (
Y: minY + int(i.bottom) - int(i.top),
},
}
return newDot, dr, f.img, image.Point{int(i.x), int(i.top)}, true
return dr, f.img, image.Point{int(i.x), int(i.top)}, fixed.Int26_6(i.width) << 6, true
}
func (f *subface) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) {
@ -144,12 +140,12 @@ func (f *face) Close() error { return nil }
func (f *face) Kern(r0, r1 rune) fixed.Int26_6 { return 0 }
func (f *face) Glyph(dot fixed.Point26_6, r rune) (
newDot fixed.Point26_6, dr image.Rectangle, mask image.Image, maskp image.Point, ok bool) {
dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool) {
if s, rr := f.subface(r); s != nil {
return s.Glyph(dot, rr)
}
return fixed.Point26_6{}, image.Rectangle{}, nil, image.Point{}, false
return image.Rectangle{}, nil, image.Point{}, 0, false
}
func (f *face) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) {