Account for linegap in Metrics.Height.
This commit is contained in:
parent
f9531a3606
commit
e5f489534a
2 changed files with 8 additions and 3 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Reference in a new issue