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

Layout is empty #16

Open
archseer opened this issue Apr 15, 2022 · 1 comment
Open

Layout is empty #16

archseer opened this issue Apr 15, 2022 · 1 comment

Comments

@archseer
Copy link

My code looks something like this, based on your code in https://github.com/dfrg/piet-gpu-text

    // let font = Font::from_file("assets/fonts/Inter Variable/Inter.ttf", 0).unwrap();
    let font = Font::from_file("assets/fonts/ttf/FiraCode-Regular.ttf", 0).unwrap();
    let font = font.as_ref();

    // experimenting with the scaler, glyph outlines are returned fine

    let mut context = ScaleContext::new();
    let mut scaler = context
        .builder(font)
        .hint(true)
        .size(14.)
        .variations(&[("wght", 400.0)])
        .build();
    let glyph_id = font.charmap().map('H');
    let outline = scaler.scale_outline(glyph_id).unwrap();

    // -- Layout

    let mut font_ctx = FontContext::new();
    let font_family = font_ctx.register_fonts(font.data.to_vec()).unwrap();
    let mut layout_ctx: LayoutContext<[u8; 4]> = LayoutContext::new();

    let mut builder = layout_ctx.ranged_builder(&mut font_ctx, "a quick brown fox?", 1.);
    builder.push_default(&StyleProperty::FontStack(FontStack::Single(
        FontFamily::Named(&font_family),
    )));
    builder.push_default(&StyleProperty::FontSize(14.));
    builder.push_default(&StyleProperty::Brush([255, 255, 255, 255]));
    let layout = builder.build();

    for line in layout.lines() {
        let mut last_x = 0.0;
        let mut last_y = 0.0;
        // base transform [1, 0, 0, -1]
        println!("hi!");

        for glyph_run in line.glyph_runs() {
            let run = glyph_run.run();
            // let color = &glyph_run.style().brush.0;
            let font = run.font();
            let font = font.as_ref();

            let mut first = true;

            // TODO: move let scaler here
            for glyph in glyph_run.positioned_glyphs() {
               // ...
            }
        }
    }

I had to make a small modification to font.rs to compile on Linux since Library::default is missing.

let mut builder = LibraryBuilder::default();
builder.build()

For some reason the layout is always empty and contains no data. I'm not relying on any system paths and instead manually registering the font, then using the font family name returned by FontContext.

@archseer
Copy link
Author

Hmm, turns out I needed to call layout.break_all_lines

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

1 participant