fix(exporters): scale legend text with cell_size, extract layer_block_height helper

This commit is contained in:
2026-03-23 02:46:03 +01:00
parent 29cfe8e801
commit 87d49f8959

View File

@@ -231,14 +231,18 @@ fn active_voxel_types(palette: &BlockPalette, grid: &VoxelGrid) -> Vec<VoxelType
candidates candidates
} }
pub fn image_dimensions(grid: &VoxelGrid, palette: &BlockPalette, cell_size: u32) -> (u32, u32) { fn layer_block_height(grid: &VoxelGrid, cell_size: u32) -> u32 {
let label_height = cell_size + 4; let label_height = cell_size + 4;
let per_layer_height = if grid.height == 0 { let per_layer_height = if grid.height == 0 {
0 0
} else { } else {
grid.height * (cell_size + GAP) - GAP grid.height * (cell_size + GAP) - GAP
}; };
let layer_block_height = label_height + GAP + per_layer_height; label_height + GAP + per_layer_height
}
pub fn image_dimensions(grid: &VoxelGrid, palette: &BlockPalette, cell_size: u32) -> (u32, u32) {
let layer_block_height = layer_block_height(grid, cell_size);
let total_grid_height = grid.depth * layer_block_height let total_grid_height = grid.depth * layer_block_height
+ grid.depth.saturating_sub(1) * GAP; + grid.depth.saturating_sub(1) * GAP;
@@ -293,8 +297,8 @@ fn draw_legend(img: &mut RgbaImage, y_start: u32, palette: &BlockPalette, grid:
draw_char(img, lx, ly, voxel_letter(*vt), lscale, COLOR_TEXT); draw_char(img, lx, ly, voxel_letter(*vt), lscale, COLOR_TEXT);
let block_name = palette.resolve(vt); let block_name = palette.resolve(vt);
let text_x = GAP + cell_size + GAP * 3; let text_x = GAP + cell_size + GAP * 3;
let text_y = y + (cell_size.saturating_sub(7)) / 2; let text_y = y + (cell_size.saturating_sub(7 * lscale)) / 2;
draw_text(img, text_x, text_y, &block_name, 1, COLOR_TEXT); draw_text(img, text_x, text_y, &block_name, lscale, COLOR_TEXT);
} }
} }
@@ -303,19 +307,14 @@ impl StructureExporter for PngExporter {
use std::io::Cursor; use std::io::Cursor;
let cs = self.cell_size; let cs = self.cell_size;
let lbh = layer_block_height(grid, cs);
let label_height = cs + 4; let label_height = cs + 4;
let per_layer_height = if grid.height == 0 {
0
} else {
grid.height * (cs + GAP) - GAP
};
let layer_block_height = label_height + GAP + per_layer_height;
let (img_w, img_h) = image_dimensions(grid, &self.palette, cs); let (img_w, img_h) = image_dimensions(grid, &self.palette, cs);
let mut img = RgbaImage::from_pixel(img_w, img_h, Rgba(COLOR_BG)); let mut img = RgbaImage::from_pixel(img_w, img_h, Rgba(COLOR_BG));
for z in 0..grid.depth { for z in 0..grid.depth {
let layer_top_y = z * (layer_block_height + GAP); let layer_top_y = z * (lbh + GAP);
draw_layer_label(&mut img, layer_top_y, z, cs); draw_layer_label(&mut img, layer_top_y, z, cs);
let grid_top_y = layer_top_y + label_height + GAP; let grid_top_y = layer_top_y + label_height + GAP;
@@ -340,7 +339,7 @@ impl StructureExporter for PngExporter {
} }
} }
let total_grid_height = grid.depth * layer_block_height let total_grid_height = grid.depth * lbh
+ grid.depth.saturating_sub(1) * GAP; + grid.depth.saturating_sub(1) * GAP;
draw_legend(&mut img, total_grid_height + GAP, &self.palette, grid, cs); draw_legend(&mut img, total_grid_height + GAP, &self.palette, grid, cs);