fix(compose): scale artboard bounds in proxy documents (#131)

This commit is contained in:
MikeeI authored and GitHub committed 2026-10-05 01:25:06 -04:00
1 parent f9f1efea6e
commit ad7046bf99
2 files changed
+20

No files matched your search

+9
View File
@@ -42,6 +42,15 @@ fn shrink_layer(l: &mut Layer, k: u32) {
match &mut l.content {
LayerContent::Raster(s) => *s = downsample(s, k),
LayerContent::Group(g) => {
if let Some(ab) = &mut g.artboard {
let divisor = i64::from(k);
// Pixel x samples source x*k: both half-open edges round up, including negatives.
let edge = |v: i32| {
let v = i64::from(v);
(v.div_euclid(divisor) + i64::from(v.rem_euclid(divisor) != 0)) as i32
};
ab.rect = Rect::new(edge(ab.rect.x0), edge(ab.rect.y0), edge(ab.rect.x1), edge(ab.rect.y1));
}
for c in &mut g.children {
shrink_layer(c, k);
}
+11
View File
@@ -44,6 +44,17 @@ fn contents_are_clipped_and_background_painted() {
assert_eq!(render_tiled(&d, d.bounds(), 7).px, buf.px);
}
}
// Proxy pixel (x,y) samples (4*x,4*y); unaligned half-open artboard edges must agree.
let original = artboard_doc(SampleType::F32, ArtboardBackground::White, BlendMode::PassThrough);
let source = render(&original, original.bounds());
let proxy = photocraft_compose::proxy::proxy_document(&original, 4);
let reduced = render(&proxy, proxy.bounds());
for y in 0..proxy.size.height as i32 {
for x in 0..proxy.size.width as i32 {
assert!(close(reduced.get(x, y), source.get(4 * x, 4 * y)), "proxy artboard differs at ({x}, {y})");
}
}
}
#[test]