From e5f489534a80f45d30cdc3e62bb491e4b7146dca Mon Sep 17 00:00:00 2001 From: Ethan Burns Date: Sun, 3 Apr 2016 08:03:45 -0400 Subject: [PATCH] Account for linegap in Metrics.Height. --- truetype/face.go | 9 ++++++--- truetype/truetype.go | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/truetype/face.go b/truetype/face.go index 099006f..c2b8423 100644 --- a/truetype/face.go +++ b/truetype/face.go @@ -254,10 +254,13 @@ func (a *face) Close() error { return nil } func (a *face) Metrics() font.Metrics { scale := float64(a.scale) fupe := float64(a.f.FUnitsPerEm()) + ascent := fixed.Int26_6(math.Ceil(scale * float64(+a.f.ascent) / fupe)) + descent := fixed.Int26_6(math.Ceil(scale * float64(-a.f.descent) / fupe)) + lineGap := fixed.Int26_6(math.Ceil(scale * float64(+a.f.lineGap) / fupe)) return font.Metrics{ - Height: a.scale, - Ascent: fixed.Int26_6(math.Ceil(scale * float64(+a.f.ascent) / fupe)), - Descent: fixed.Int26_6(math.Ceil(scale * float64(-a.f.descent) / fupe)), + Height: ascent + lineGap + descent, + Ascent: ascent, + Descent: descent, } } diff --git a/truetype/truetype.go b/truetype/truetype.go index 613fc17..c01fe9e 100644 --- a/truetype/truetype.go +++ b/truetype/truetype.go @@ -186,6 +186,7 @@ type Font struct { fUnitsPerEm int32 ascent int32 // In FUnits. descent int32 // In FUnits; typically negative. + lineGap int32 // In FUnits. bounds fixed.Rectangle26_6 // In FUnits. // Values from the maxp section. maxTwilightPoints, maxStorage, maxFunctionDefs, maxStackElements uint16 @@ -293,6 +294,7 @@ func (f *Font) parseHhea() error { } f.ascent = int32(int16(u16(f.hhea, 4))) f.descent = int32(int16(u16(f.hhea, 6))) + f.lineGap = int32(int16(u16(f.hhea, 8))) f.nHMetric = int(u16(f.hhea, 34)) if 4*f.nHMetric+2*(f.nGlyph-f.nHMetric) != len(f.hmtx) { return FormatError(fmt.Sprintf("bad hmtx length: %d", len(f.hmtx)))