ITADN

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

#602Openrecatek 创建于 2026-04-11
R
recatekcommented
`parley = { version = "0.8.0" }` When experimenting with [B612 Mono](https://fonts.google.com/specimen/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: ```rust 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.
1 条评论