mooman219 / fontdue

The fastest font renderer in the world, written in pure rust.
Apache License 2.0
1.44k stars 72 forks source link

Glyph metrics are incorrect #129

Closed spencerkohan closed 2 years ago

spencerkohan commented 2 years ago

I'm attempting to render the text "hola" using glyphs generated by fontdue, using the font Courier New.

I create the metrics like so:


        let font = include_bytes!("../res/Courier-New.ttf") as &[u8];
        let font = Font::from_bytes(
            font,
            fontdue::FontSettings {
                collection_index: 0,
                scale: 12.0,
            },
        )
        .unwrap();

        let char_data: Vec<((Metrics, Vec<u8>), char)> = (32..127)
            .map(char::from_u32)
            .flatten()
            .map(|c| (font.rasterize(c, 12.0), c))
            .collect();

When I render based on these metrics, the spacing is clearly wrong, as the characters are too far apart:

Screen Shot 2022-11-12 at 12 19 44

When I look at the metrics for the character 'h' I get the following:

Metrics {
    xmin: 1,
    ymin: -1,
    width: 6,
    height: 7,
    advance_width: 7.201172,
    advance_height: 0.0,
    bounds: OutlineBounds {
        xmin: 1.0019531,
        ymin: -0.19335938,
        width: 5.4375,
        height: 5.4433594,
    },
}

I compared this with the metrics produced by fontdrop.info, and the ratios between the width of the character and the advance width are not the same:

Screen Shot 2022-11-12 at 12 23 56

So it would appear fontdue is giving me the incorrect glyph metrics here

spencerkohan commented 2 years ago

Never mind, this was an unrelated issue, and I was getting the incorrect glyph metrics