use uzor::render::{TextMetrics, TextRenderer};
const SAMPLES: &[&str] = &["12", "Jan 24", "1,234.5", "Volume", "The quick brown fox", "AVWX", "gpqjy"];
const SIZES: &[f64] = &[11.0, 13.0, 18.0];
#[test]
fn measure_text_agrees_exactly_across_tiny_skia_vello_cpu_and_urx() {
for &size in SIZES {
for &text in SAMPLES {
let font = format!("{size}px Roboto");
let mut tiny_skia = uzor_render_tiny_skia::TinySkiaCpuRenderContext::new(200, 100, 1.0);
tiny_skia.set_font(&font);
let tiny_skia_w = tiny_skia.measure_text(text);
let mut vello_cpu = uzor_render_vello_cpu::VelloCpuRenderContext::new(1.0);
vello_cpu.begin_frame(200, 100);
vello_cpu.set_font(&font);
let vello_cpu_w = vello_cpu.measure_text(text);
let mut urx = uzor_render_urx::UrxRenderContext::new(1.0);
urx.set_font(&font);
let urx_w = urx.measure_text(text);
assert_eq!(
tiny_skia_w.to_bits(),
urx_w.to_bits(),
"tiny-skia vs urx measure_text diverged for {text:?} @ {size}px: {tiny_skia_w} != {urx_w}"
);
assert_eq!(
vello_cpu_w.to_bits(),
urx_w.to_bits(),
"vello-cpu vs urx measure_text diverged for {text:?} @ {size}px: {vello_cpu_w} != {urx_w}"
);
}
}
}
#[test]
fn text_bounds_width_agrees_exactly_across_tiny_skia_vello_cpu_and_urx() {
for &size in SIZES {
for &text in SAMPLES {
let font = format!("{size}px Roboto");
let tiny_skia = uzor_render_tiny_skia::TinySkiaCpuRenderContext::new(200, 100, 1.0);
let tiny_skia_w = uzor::render::TextMetrics::text_bounds(&tiny_skia, text, &font).w;
let mut vello_cpu = uzor_render_vello_cpu::VelloCpuRenderContext::new(1.0);
vello_cpu.begin_frame(200, 100);
let vello_cpu_w = uzor::render::TextMetrics::text_bounds(&vello_cpu, text, &font).w;
let urx = uzor_render_urx::UrxRenderContext::new(1.0);
let urx_w = uzor::render::TextMetrics::text_bounds(&urx, text, &font).w;
assert_eq!(
tiny_skia_w.to_bits(),
urx_w.to_bits(),
"tiny-skia vs urx text_bounds.w diverged for {text:?} @ {size}px: {tiny_skia_w} != {urx_w}"
);
assert_eq!(
vello_cpu_w.to_bits(),
urx_w.to_bits(),
"vello-cpu vs urx text_bounds.w diverged for {text:?} @ {size}px: {vello_cpu_w} != {urx_w}"
);
}
}
}