linebender / linebender/parley

Inconsistent baseline difference line-to-line for some fonts/sizes

Open
#602 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
736
Forks
120
Avg merge
1d 3h
Merged PRs (30d)
53

Description

parley = { version = "0.8.0" }

When experimenting with B612 Mono in a text box UI widget I'm building, I noticed the text wobbling up and down during line scrolling. It looks like the change in baseline from line to line is not always consistent for this font, though I'm not sure what it is about this font that makes it that way.

Repro:

use parley::{FontContext, FontFamily, LayoutContext, StyleProperty};

const TEXT: &str = "|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n";

pub fn repro() {
    let mut font = FontContext::new();
    font.collection.load_system_fonts();
    font.collection.register_fonts(
        include_bytes!("path/to/B612Mono-Bold.ttf").to_vec().into(),
        None,
    );

    print_baselines(&mut font, "Segoe UI", TEXT);
    print_baselines(&mut font, "B612 Mono", TEXT);
}

fn print_baselines(font: &mut FontContext, family: &'static str, text: &'static str) {
    let mut layout = LayoutContext::<()>::new();

    let mut builder = layout.ranged_builder(font, text, 1.0, false);

    builder.push_default(StyleProperty::FontSize(14.0));
    builder.push_default(StyleProperty::FontFamily(FontFamily::Source(family.into())));

    let mut layout = builder.build(text);

    layout.break_all_lines(None);

    let mut last = 0.0;
    let baselines = layout
        .lines()
        .map(|l| {
            let baseline = l.metrics().baseline;
            let delta = baseline - last;
            last = baseline;
            (baseline, delta)
        })
        .collect::<Vec<_>>();

    println!(
        "{family}: {}",
        baselines.iter().map(|(b, d)| format!("({b}, +{d})")).collect::<Vec<_>>().join(", ")
    );
}

Output:

Segoe UI: (15.107422, +15.107422), (33.728516, +18.621094), (52.34961, +18.621094), (70.9707, +18.621094), (89.5918, +18.621094), (108.21289, +18.621094), (126.833984, +18.621094), (145.45508, +18.621094), (164.07617, +18.621094), (182.69727, +18.621094), (201.31836, +18.621094), (219.93945, +18.621094), (238.56055, +18.621094), (257.18164, +18.621094), (275.80273, +18.621094), (294.42383, +18.621094), (313.04492, +18.621094), (331.66602, +18.621094)
B612 Mono: (13.51, +13.51), (30.52, +17.01), (47.53, +17.009998), (64.54, +17.010002), (81.55, +17.010002), (98.560005, +17.010002), (115.57, +17.009995), (132.58, +17.010002), (149.59, +17.009995), (166.59999, +17.009995), (183.61, +17.01001), (200.62, +17.009995), (217.62999, +17.009995), (234.64, +17.01001), (251.65, +17.009995), (268.66, +17.01001), (285.67, +17.01001), (302.68002, +17.01001)

Notice the 17.01, 17.009998, 17.010002 etc. delta values for B612 Mono compared to the very consistent 18.621094 value for Segoe UI. This is causing some jittery pixel offsets when I go to quantize in some situations. I'm not sure if this is a consequence of #273 or a separate issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Rust reproduction, focusing on LayoutContext::ranged_builder, layout.lines(), and each line's metrics().baseline. Trace how baseline values are calculated for B612 Mono versus Segoe UI and capture the case in a regression test; done means repeated line deltas no longer produce the reported inconsistent offsets.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.