Skip to content

truetype: font metrics ascent and descent values appear incorrect #34

Open
@dskinner

Description

@dskinner

I believe this is related to #32 where eaburns pointed out a potential issue with the scale factor. I don't know a great deal about fonts, but presuming a zero line gap and that height == ascent+descent, I'm seeing issues with Droid Sans and Source Code Pro fonts using font.Drawer, no hinting, 72dpi, 240pt.

For example:

bin, err := ioutil.ReadFile("DroidSans.ttf")
if err != nil {
    log.Fatal(err)
}
f, err := truetype.Parse(bin)
if err != nil {
    log.Fatal(err)
}

fc := truetype.NewFace(f, &truetype.Options{
    Size:    240,
    DPI:     72,
    Hinting: font.HintingNone,
})

fmt.Printf("metrics %+v\n", fc.Metrics())
// Output: metrics {Height:240:00 Ascent:222:50 Descent:56:39}
fmt.Printf("ascent+descent %v\n", fc.Metrics().Ascent+fc.Metrics().Descent)
// Output: ascent+descent 279:25

I'm packing glyphs in a texture and exporting the metrics for use in opengl. The above was causing my baseline calculation to be lower than expected. For now I've worked around this by scaling the ascent and descent by size/(ascent+descent) which produced the semi-correct result I'd expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions