From 9259c18d1aa6cf1975db99e682a0feac0360f7d6 Mon Sep 17 00:00:00 2001 From: Jasper Bekkers Date: Wed, 16 Nov 2022 10:00:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=F0=9F=AA=B5=20Fix=20emoji=20placem?= =?UTF-8?q?ent=20by=20calculating=20full=20bounds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scale/mod.rs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/scale/mod.rs b/src/scale/mod.rs index 07eab49..58e9b86 100644 --- a/src/scale/mod.rs +++ b/src/scale/mod.rs @@ -894,6 +894,32 @@ impl<'a> Render<'a> { let mut base_w = 0u32; let mut base_h = 0u32; let mut ok = true; + + let mut total_bounds = zeno::Bounds::empty(); + + for i in 0..outline.len() { + let layer = match outline.get(i) { + Some(layer) => layer, + _ => { + ok = false; + break; + } + }; + let bounds = layer.bounds(); + total_bounds = total_bounds.grow(&bounds); + } + + base_x = total_bounds.min.x as i32; + base_y = total_bounds.min.y as i32; + base_w = total_bounds.width() as u32; + base_h = total_bounds.height() as u32; + + image.data.resize((base_w * base_h * 4) as usize, 0); + image.placement.left = 0; + image.placement.top = 0; + image.placement.width = total_bounds.width() as u32; + image.placement.height = total_bounds.height() as u32; + for i in 0..outline.len() { let layer = match outline.get(i) { Some(layer) => layer, @@ -902,6 +928,7 @@ impl<'a> Render<'a> { break; } }; + scratch.clear(); let placement = Mask::with_scratch(layer.path(), rcx) .origin(Origin::BottomLeft) @@ -911,14 +938,6 @@ impl<'a> Render<'a> { scratch.resize(fmt.buffer_size(w, h), 0); }) .render_into(&mut scratch[..], None); - if i == 0 { - base_x = placement.left; - base_y = placement.top; - base_w = placement.width; - base_h = placement.height; - image.data.resize((base_w * base_h * 4) as usize, 0); - image.placement = placement; - } let color = layer .color_index() .map(|i| palette.map(|p| p.get(i))) @@ -929,7 +948,7 @@ impl<'a> Render<'a> { placement.width, placement.height, placement.left.wrapping_sub(base_x), - base_y.wrapping_sub(placement.top), + (base_h as i32 + base_y).wrapping_sub(placement.top), color, &mut image.data, base_w,