From 8c32ce3876792074496eb3cfdb7ffe513e7eba3f Mon Sep 17 00:00:00 2001 From: Yangtse Su Date: Thu, 15 Oct 2026 13:05:42 +0800 Subject: [PATCH] fix(ffi): bound the region pixel diff by share and delta, not absolute counts real_fixture_region_matches_full_page_and_preserves_cairo_ownership pins the anti-aliasing difference between the full-page and the region rendering to 32 channels with a per-channel delta of at most 2, which only holds on the font stack it was written on: Arch with FreeType 2.13 gives 21 differing channels with delta <= 2, while ubuntu-24.04 with the same FreeType gives 42 channels with delta <= 8, so a clean Debian build-dependency environment fails the test (crates/rofd-ffi/tests/region.rs:201). Bound the difference by its share of the tiles channels (1%) and a per-channel delta of 16 instead. A stitching or crop error moves whole pixels, which changes orders of magnitude more channels with far larger deltas, so the check keeps its meaning; exact geometric stitching stays covered by the renderer tests. Verified: cargo test -p rofd-ffi --test region ok on Arch (probe: rect 129x71, 36636 channels, 21 differing, max delta 2) and cargo fmt --all -- --check clean. --- crates/rofd-ffi/tests/region.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/rofd-ffi/tests/region.rs b/crates/rofd-ffi/tests/region.rs index 542516f0..44e712dc 100644 --- a/crates/rofd-ffi/tests/region.rs +++ b/crates/rofd-ffi/tests/region.rs @@ -195,12 +195,18 @@ fn real_fixture_region_matches_full_page_and_preserves_cairo_ownership() { } } } - // Cairo can change curve edge coverage with target extents even with an - // identical matrix. This fixed invoice has 21 differing channels, delta <=2; - // exact geometric/image stitching is covered in the renderer tests. + // Cairo changes curve edge coverage when the target extents change, so the + // two renderings differ in anti-aliasing only: 21 channels with delta <= 2 on + // Arch (FreeType 2.13), 42 channels with delta <= 8 on Ubuntu 24.04 with the + // same FreeType. Bound the share of differing channels and the per-channel + // delta instead of pinning absolute numbers that only hold on one font + // stack; a stitching or crop error moves whole pixels, which changes orders + // of magnitude more channels with far larger deltas, and exact geometric + // stitching is covered by the renderer tests. + let channels = rect.width as usize * rect.height as usize * 4; assert!( - differences.len() <= 32 && differences.iter().all(|v| v.2 <= 2), - "{} differing channels, max delta {}, first {:?}", + differences.len() * 100 <= channels && differences.iter().all(|v| v.2 <= 16), + "{} differing channels of {channels}, max delta {}, first {:?}", differences.len(), differences.iter().map(|v| v.2).max().unwrap_or(0), differences.first()