Add shadow and outline options to text generation CLI and engine

This commit is contained in:
2026-03-23 01:36:18 +01:00
parent 484415870a
commit 8933a2e690
3 changed files with 200 additions and 34 deletions

View File

@@ -2,7 +2,7 @@ use std::{fs, path::PathBuf};
use clap::Parser;
use exporters::McFunctionExporter;
use lib::{BlockPalette, StructureExporter, TextBuilder, TtfFont};
use lib::{BlockPalette, OutlineMode, StructureExporter, TextBuilder, TtfFont};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
@@ -38,6 +38,30 @@ struct Cli {
/// Height of the text in blocks
#[arg(long, default_value_t = 16.0)]
size: f32,
/// Generate a drop shadow
#[arg(long)]
shadow: bool,
/// Shadow X offset in blocks (positive = right)
#[arg(long, default_value_t = 1)]
shadow_x: i32,
/// Shadow Y offset in blocks (negative = down)
#[arg(long, default_value_t = -1)]
shadow_y: i32,
/// Outline connectivity: 4 (cardinal only) or 8 (includes corners)
#[arg(long, default_value_t = 8, value_parser = clap::value_parser!(u8).range(4..=8))]
outline_mode: u8,
/// Extra blocks between each character (overrides font default)
#[arg(long)]
letter_spacing: Option<u32>,
/// Width in blocks inserted for a space character
#[arg(long, default_value_t = 4)]
word_spacing: u32,
}
fn palettes_dir() -> PathBuf {
@@ -93,7 +117,20 @@ pub fn run() -> anyhow::Result<()> {
let font = TtfFont::from_bytes(&font_bytes, cli.size).map_err(|e| anyhow::anyhow!(e))?;
tracing::info!("generating voxel grid for text: '{}'", text);
let builder = TextBuilder::new(&font).with_depth(cli.depth);
let outline_mode = if cli.outline_mode == 4 {
OutlineMode::FourConnected
} else {
OutlineMode::EightConnected
};
let mut builder = TextBuilder::new(&font)
.with_depth(cli.depth)
.with_shadow(cli.shadow)
.with_shadow_offset(cli.shadow_x, cli.shadow_y)
.with_outline_mode(outline_mode)
.with_word_spacing(cli.word_spacing);
if let Some(ls) = cli.letter_spacing {
builder = builder.with_letter_spacing(ls);
}
let grid = builder.generate(&text);
tracing::info!(