//! The code font advances every character by the same amount (to the pixel grid): no ligature or pair //! kerning opens a gap inside a URL or an operator. use egui::{Color32, Context, FontId, RawInput}; /// x of every glyph of `text` laid out in the monospace family, plus the end of the row. fn xs(ctx: &Context, text: &str) -> Vec { ctx.fonts_mut(|fonts| { let galley = fonts.layout_no_wrap(text.to_owned(), FontId::monospace(14.0), Color32::WHITE); let row = &galley.rows[0]; row.glyphs.iter().map(|g| g.pos.x).chain(std::iter::once(row.size.x)).collect() }) } #[test] fn urls_and_operators_keep_one_advance_per_character() { let ctx = Context::default(); notescraft_ui_egui::fonts::install(&ctx); ctx.run_ui(RawInput::default(), |_| {}).textures_delta.clear(); for text in ["https://publish.obsidian.md/username/about", "a != b -> c => d // e "] { let xs = xs(&ctx, text); let steps: Vec = xs.windows(2).map(|w| w[1] - w[0]).collect(); let first = steps[0]; assert!(steps.iter().all(|s| (s - first).abs() <= 1.0), "{text}: uneven advances {steps:?}"); } }