Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glyf bbox fallback #49

Closed
alexheretic opened this issue Jan 17, 2021 · 2 comments
Closed

Add glyf bbox fallback #49

alexheretic opened this issue Jan 17, 2021 · 2 comments

Comments

@alexheretic
Copy link

Using airstrip.ttf https://dl.dafont.com/dl/?f=airstrip_four character v returns a zero bounding box result from outline_glyph which seems wrong.

Reproduce

const AIRSTRIP: &[u8] = include_bytes!("../airstrip.ttf");

fn main() {
    let airstrip = ttf_parser::Face::from_slice(AIRSTRIP, 0).unwrap();

    let v = airstrip.glyph_index('v').unwrap();
    let bounds = airstrip.outline_glyph(v, &mut OutlinePrinter);

    dbg!(bounds);
}

struct OutlinePrinter;

impl ttf_parser::OutlineBuilder for OutlinePrinter {
    fn move_to(&mut self, x: f32, y: f32) {
        eprintln!("outline-move_to({}, {})", x, y);
    }
    fn line_to(&mut self, x: f32, y: f32) {
        eprintln!("outline-line_to({}, {})", x, y);
    }
    fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) {
        eprintln!("outline-quad_to({}, {}, {}, {})", x1, y1, x, y);
    }
    fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) {
        eprintln!("outline-curve_to({}, {}, {}, {}, {}, {})", x1, y1, x2, y2, x, y);
    }
    fn close(&mut self) {
        eprintln!("outline-close");
    }
}
outline-move_to(955, 1301)
outline-quad_to(864, 1298, 833, 1247)
outline-quad_to(802, 1196, 552, 447)
outline-quad_to(300, 1196, 272.5, 1248.5)
outline-quad_to(245, 1301, 150, 1301)
outline-quad_to(0, 1301, 0, 1151)
outline-line_to(401, 99)
outline-quad_to(443, 14, 493.5, 5.5)
outline-quad_to(544, -3, 602.5, 2.5)
outline-quad_to(661, 8, 697, 99)
outline-line_to(1102, 1149)
outline-quad_to(1102, 1301, 955, 1301)
outline-close
[src/main.rs:11] bounds = Some(
    Rect {
        x_min: 0,
        y_min: 0,
        x_max: 0,
        y_max: 0,
    },
)
@RazrFalcon
Copy link
Owner

Glyph 89 indeed has a zero bbox. So this a malformed font.
Surprisingly, FreeType actually recovers/calculates the bbox somehow, but harfbuzz is not.

I guess you should calculate the bbox manually and/or use glyph_hor_advance and glyph_hor_side_bearing.
Not sure if ttf-parser should do it automatically.

@alexheretic
Copy link
Author

Thanks for the info. I'll put a workaround fix in downstream for the time being.

@RazrFalcon RazrFalcon changed the title airstrip.ttf incorrect zero bounding box for 'v' Add glyf bbox fallback Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants