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)))