#![allow(unused)]
mod render;
mod error;
use error::Error;
mod util;
use bevy_vello::vello::{kurbo::Affine, peniko::Color};
pub(crate) fn render(
svg: &str,
path_color: Option<Color>,
) -> Result<bevy_vello::vello::Scene, Error> {
let opt = usvg::Options::default();
let tree = usvg::Tree::from_str(svg, &opt)?;
let mut scene = bevy_vello::vello::Scene::new();
append_tree(&mut scene, &tree, path_color);
Ok(scene)
}
pub(crate) fn append(scene: &mut bevy_vello::vello::Scene, svg: &str) -> Result<(), Error> {
let opt = usvg::Options::default();
let tree = usvg::Tree::from_str(svg, &opt)?;
append_tree(scene, &tree, None);
Ok(())
}
pub(crate) fn append_with<F: FnMut(&mut bevy_vello::vello::Scene, &usvg::Node)>(
scene: &mut bevy_vello::vello::Scene,
svg: &str,
error_handler: &mut F,
) -> Result<(), Error> {
let opt = usvg::Options::default();
let tree = usvg::Tree::from_str(svg, &opt)?;
append_tree_with(scene, &tree, None, error_handler);
Ok(())
}
pub(crate) fn render_tree(svg: &usvg::Tree, path_color: Option<Color>) -> bevy_vello::vello::Scene {
let mut scene = bevy_vello::vello::Scene::new();
append_tree(&mut scene, svg, path_color);
scene
}
pub(crate) fn append_tree(
scene: &mut bevy_vello::vello::Scene,
svg: &usvg::Tree,
color: Option<Color>,
) {
append_tree_with(scene, svg, color, &mut util::default_error_handler);
}
pub(crate) fn append_tree_with<F: FnMut(&mut bevy_vello::vello::Scene, &usvg::Node)>(
scene: &mut bevy_vello::vello::Scene,
svg: &usvg::Tree,
color: Option<Color>,
error_handler: &mut F,
) {
render::render_group(scene, svg.root(), color, Affine::IDENTITY, error_handler);
}