git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

commitf1e9747265419bad9a8f6c68d4094e911874346d
parent7b1c29e1d6
authorNigel Tao <nigeltao@golang.org>
date2016-03-24 10:11
font: add Metrics.Descent.

Change-Id: Id38e7e54264e0e77a28afd8e10cf574610b47336
Reviewed-on: https://go-review.googlesource.com/21019
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>

 font/basicfont/basicfont.go |  5 +++--
 font/font.go                | 10 ++++++++--
 font/plan9font/plan9font.go | 10 ++++++----
 3 files changed, 17 insertions(+), 8 deletions(-)

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) 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),
 	}
 }
 
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 @@ 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
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) 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),
 	}
 }