fix resvg scaling

This commit is contained in:
Dominic 2024-07-06 19:39:51 +02:00
parent caf17aa3e5
commit dba691783a
Signed by: msrd0
GPG key ID: AAF7C8430CA3345D

View file

@ -47,12 +47,17 @@ impl AssetsWriter {
let hash = hasher.finish();
let const_name = format!("ASSET_{hash:X}");
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir: PathBuf = out_dir.into();
png.save_png(out_dir.join(format!("{const_name}.png")))
.expect("Failed to save png");
writeln!(self.file, "// {}", canonical_path.as_ref().display()).unwrap();
write!(self.file, "const {const_name}: &'static [u8] = &[").unwrap();
for byte in png.encode_png().expect("Failed to encode png") {
write!(self.file, "{byte}, ").unwrap();
}
writeln!(self.file, "];").unwrap();
writeln!(
self.file,
"const {const_name}: &[u8] = include_bytes!(\"{const_name}.png\");"
)
.unwrap();
const_name
}
@ -183,7 +188,11 @@ fn process_svg<P: AsRef<Path> + Copy, Q: AsRef<Path>>(
panic!("Cannot parse svg file {}: {err}", file.as_ref().display())
});
let mut pixmap = tiny_skia::Pixmap::new(TILE_SIZE, TILE_SIZE).unwrap();
resvg::render(&tree, Default::default(), &mut pixmap.as_mut());
let transform = tiny_skia::Transform::from_scale(
TILE_SIZE as f32 / tree.size().width(),
TILE_SIZE as f32 / tree.size().height()
);
resvg::render(&tree, transform, &mut pixmap.as_mut());
let const_name = writer.add_png(
file.as_ref()