font: add Metrics.Descent.
Change-Id: Id38e7e54264e0e77a28afd8e10cf574610b47336
Reviewed-on: https://go-review.googlesource.com/21019
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/font/basicfont/basicfont.go b/font/basicfont/basicfont.go
index ed05fa2..c6b2b68 100644
--- a/font/basicfont/basicfont.go
+++ b/font/basicfont/basicfont.go
@@ -73,8 +73,9 @@
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),
}
}
diff --git a/font/font.go b/font/font.go
index 3e3608e..c3041d9 100644
--- a/font/font.go
+++ b/font/font.go
@@ -74,11 +74,17 @@
// 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
diff --git a/font/plan9font/plan9font.go b/font/plan9font/plan9font.go
index b7948d3..d853b1c 100644
--- a/font/plan9font/plan9font.go
+++ b/font/plan9font/plan9font.go
@@ -67,8 +67,9 @@
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) 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),
}
}