mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-26 04:20:56 +01:00
- assets/app-icon: the rabbit vectorised onto the shared Crafting Apps tile (512 viewBox, rx 112) with a neutral white paper tone; renders for Windows (.ico), Linux (hicolor) and Apple's icon grid (padded tile); trace.py and scripts/icons.sh regenerate them. - The app shows it on the window, the macOS Dock, the Windows taskbar and anicraft.exe (winresource), and in Help > About (--open about). - README: icon header, screenshots, the sample animation as a GIF, quick start, status, downloads and the Crafting Apps table. - ATTRIBUTION and CHANGELOG rows for the new files.
100 lines
4.3 KiB
Rust
100 lines
4.3 KiB
Rust
//! Optional font build input (the Craft family convention, as in PhotoCraft), and the app icon
|
|
//! embedded in the Windows executable.
|
|
//!
|
|
//! `CRAFT_FONTS_DIR=<craft-fonts checkout> cargo build` embeds the UI typefaces chosen in
|
|
//! ADR 0005: Inter (prose) and JetBrains Mono (data), both SIL OFL 1.1. Font files are never
|
|
//! committed to this repository. Without the variable the app uses egui's bundled defaults, and
|
|
//! everything still works.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// Files we look for, and the generated constant each fills.
|
|
const FONTS: [(&str, &str); 2] = [("Inter-Regular.ttf", "UI_FONT"), ("JetBrainsMono-Regular.ttf", "MONO_FONT")];
|
|
|
|
fn find(dir: &Path, name: &str, depth: u32) -> Option<PathBuf> {
|
|
let entries = std::fs::read_dir(dir).ok()?;
|
|
let mut subdirs = Vec::new();
|
|
for e in entries.flatten() {
|
|
let p = e.path();
|
|
if p.is_dir() {
|
|
subdirs.push(p);
|
|
} else if p.file_name().is_some_and(|n| n.eq_ignore_ascii_case(name)) {
|
|
return Some(p);
|
|
}
|
|
}
|
|
if depth == 0 {
|
|
return None;
|
|
}
|
|
subdirs.iter().find_map(|d| find(d, name, depth - 1))
|
|
}
|
|
|
|
/// Where to look for the fonts when `CRAFT_FONTS_DIR` is not set: a `craft-fonts` checkout next
|
|
/// to this repository (or up to three folders above it), then a sibling Craft app that vendors
|
|
/// the same OFL files (PhotoCraft's `assets/fonts`). This makes ordinary local builds look like
|
|
/// releases without committing font files here.
|
|
fn discover() -> Option<PathBuf> {
|
|
if let Some(d) = std::env::var_os("CRAFT_FONTS_DIR") {
|
|
return Some(PathBuf::from(d));
|
|
}
|
|
let manifest = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR")?);
|
|
let mut dir = manifest.parent().map(Path::to_path_buf);
|
|
for _ in 0..4 {
|
|
let Some(d) = dir else { break };
|
|
for candidate in [d.join("craft-fonts"), d.join("photocraft").join("assets").join("fonts")] {
|
|
if candidate.is_dir() {
|
|
return Some(candidate);
|
|
}
|
|
}
|
|
dir = d.parent().map(Path::to_path_buf);
|
|
}
|
|
None
|
|
}
|
|
|
|
/// Windows only: embed the app icon into `anicraft.exe` (taskbar, Start menu, Explorer, Alt-Tab).
|
|
/// A missing resource compiler is a warning, so a cross-compile still links.
|
|
fn windows_icon() {
|
|
println!("cargo:rerun-if-changed=assets/app-icon/anicraft.ico");
|
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
|
return;
|
|
}
|
|
let mut res = winresource::WindowsResource::new();
|
|
res.set_icon("assets/app-icon/anicraft.ico").set("ProductName", "AniCraft").set("FileDescription", "AniCraft 2D vector animation studio");
|
|
if let Err(e) = res.compile() {
|
|
println!("cargo:warning=anicraft.exe built without its icon: {e}");
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
windows_icon();
|
|
println!("cargo:rerun-if-env-changed=CRAFT_FONTS_DIR");
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
let dir = discover();
|
|
match &dir {
|
|
Some(d) => println!("cargo:rerun-if-changed={}", d.display()),
|
|
None => println!("cargo:warning=UI fonts: no craft-fonts found (set CRAFT_FONTS_DIR or clone storytold/craft-fonts next to the repo); using the built-in fallback fonts"),
|
|
}
|
|
let mut code = String::from("// Generated by build.rs (CRAFT_FONTS_DIR font input).\n");
|
|
let mut total = 0u64;
|
|
for (file, constant) in FONTS {
|
|
let found = dir.as_deref().and_then(|d| find(d, file, 3));
|
|
match found {
|
|
Some(p) => {
|
|
println!("cargo:rerun-if-changed={}", p.display());
|
|
total += std::fs::metadata(&p).map(|m| m.len()).unwrap_or(0);
|
|
code.push_str(&format!("pub const {constant}: Option<&[u8]> = Some(include_bytes!({:?}));\n", p.display().to_string()));
|
|
}
|
|
None => {
|
|
if dir.is_some() {
|
|
println!("cargo:warning=CRAFT_FONTS_DIR is set but {file} was not found; using the bundled default");
|
|
}
|
|
code.push_str(&format!("pub const {constant}: Option<&[u8]> = None;\n"));
|
|
}
|
|
}
|
|
}
|
|
code.push_str(&format!("pub const CRAFT_FONT_BYTES: u64 = {total};\n"));
|
|
let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap_or_default()).join("fonts.rs");
|
|
if let Err(e) = std::fs::write(&out, code) {
|
|
println!("cargo:warning=could not write {}: {e}", out.display());
|
|
}
|
|
}
|