mod context;
pub use context::TinySkiaCpuRenderContext;
#[cfg(test)]
mod shaper_tests {
use uzor::render::TextMetrics;
use super::TinySkiaCpuRenderContext;
fn ctx() -> TinySkiaCpuRenderContext {
TinySkiaCpuRenderContext::new(1, 1, 1.0)
}
const FONT: &str = "16px sans-serif";
#[test]
fn hello_five_clusters() {
let glyphs = ctx().measure_text_glyphs("Hello", FONT);
assert_eq!(glyphs.len(), 5, "expected 5 clusters for 'Hello', got {:?}", glyphs);
for (i, g) in glyphs.iter().enumerate() {
let expected = ["H", "e", "l", "l", "o"][i];
assert_eq!(g.cluster, expected, "cluster[{i}] mismatch");
}
for w in glyphs.windows(2) {
assert!(
w[1].x_offset >= w[0].x_offset,
"x_offset not increasing: {:?} >= {:?}", w[0].x_offset, w[1].x_offset
);
}
}
#[test]
fn cafe_four_clusters() {
let glyphs = ctx().measure_text_glyphs("caf\u{00e9}", FONT);
assert_eq!(glyphs.len(), 4, "expected 4 clusters for 'café', got {:?}", glyphs);
assert_eq!(glyphs[3].cluster, "\u{00e9}", "last cluster should be é (U+00E9)");
}
#[test]
fn emoji_one_cluster() {
let text = "hi \u{1F44B}"; let glyphs = ctx().measure_text_glyphs(text, FONT);
assert_eq!(glyphs.len(), 4, "expected 4 clusters for 'hi 👋', got {:?}", glyphs);
assert_eq!(glyphs[3].cluster, "\u{1F44B}", "emoji should be one cluster");
}
#[test]
fn empty_string_empty_vec() {
let glyphs = ctx().measure_text_glyphs("", FONT);
assert!(glyphs.is_empty(), "empty string should return empty Vec");
}
}