font: add Metrics.Descent.

Change-Id: Id38e7e54264e0e77a28afd8e10cf574610b47336
Reviewed-on: https://go-review.googlesource.com/21019
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Nigel Tao 2016-03-24 10:11:33 +11:00
parent 7b1c29e1d6
commit f1e9747265
3 changed files with 17 additions and 8 deletions

View File

@ -73,8 +73,9 @@ func (f *Face) Kern(r0, r1 rune) fixed.Int26_6 { return 0 }
func (f *Face) Metrics() font.Metrics {
return font.Metrics{
Height: fixed.I(f.Height),
Ascent: fixed.I(f.Ascent),
Height: fixed.I(f.Height),
Ascent: fixed.I(f.Ascent),
Descent: fixed.I(f.Height - f.Ascent),
}
}

View File

@ -74,11 +74,17 @@ type Face interface {
// Metrics holds the metrics for a Face. A visual depiction is at
// https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png
type Metrics struct {
// Height is the recommended amount of vertical space between two lines of
// text.
Height fixed.Int26_6
// Ascent is the distance from the top of a line to its baseline.
Ascent fixed.Int26_6
// Height is the recommended amount of vertical space between two lines of text.
Height fixed.Int26_6
// Descent is the distance from the bottom of a line to its baseline. The
// value is typically positive, even though a descender goes below the
// baseline.
Descent fixed.Int26_6
}
// TODO: Drawer.Layout or Drawer.Measure methods to measure text without

View File

@ -67,8 +67,9 @@ func (f *subface) Kern(r0, r1 rune) fixed.Int26_6 { return 0 }
func (f *subface) Metrics() font.Metrics {
return font.Metrics{
Height: fixed.I(f.height),
Ascent: fixed.I(f.ascent),
Height: fixed.I(f.height),
Ascent: fixed.I(f.ascent),
Descent: fixed.I(f.height - f.ascent),
}
}
@ -148,8 +149,9 @@ func (f *face) Kern(r0, r1 rune) fixed.Int26_6 { return 0 }
func (f *face) Metrics() font.Metrics {
return font.Metrics{
Height: fixed.I(f.height),
Ascent: fixed.I(f.ascent),
Height: fixed.I(f.height),
Ascent: fixed.I(f.ascent),
Descent: fixed.I(f.height - f.ascent),
}
}