Skip to content

Commit

Permalink
🤖🪵 Fix emoji placement by calculating full bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper-Bekkers committed Nov 16, 2022
1 parent d3f8bbf commit 9259c18
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/scale/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -902,6 +928,7 @@ impl<'a> Render<'a> {
break;
}
};

scratch.clear();
let placement = Mask::with_scratch(layer.path(), rcx)
.origin(Origin::BottomLeft)
Expand All @@ -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)))
Expand All @@ -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,
Expand Down

0 comments on commit 9259c18

Please sign in to comment.