#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::identity_op)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::wrong_self_convention)]
pub use tiny_skia;
pub use usvgr;
mod cache;
mod clip;
mod filter;
mod geom;
mod image;
mod mask;
mod path;
mod render;
pub use cache::*;
pub use render::Context;
pub fn render(
tree: &usvgr::Tree,
transform: tiny_skia::Transform,
pixmap: &mut tiny_skia::PixmapMut,
cache: &mut cache::SvgrCache,
ctx: &render::Context,
) {
let ts = tree.view_box().to_transform(tree.size());
let root_transform = transform.pre_concat(ts);
render::render_nodes(tree.root(), &ctx, root_transform, pixmap, cache);
}
pub fn render_node(
node: &usvgr::Node,
mut transform: tiny_skia::Transform,
pixmap: &mut tiny_skia::PixmapMut,
cache: &mut cache::SvgrCache,
ctx: &render::Context,
) -> Option<()> {
let bbox = node.abs_layer_bounding_box()?;
transform = transform.pre_translate(-bbox.x(), -bbox.y());
render::render_node(node, &ctx, transform, pixmap, cache);
Some(())
}
pub(crate) trait OptionLog {
fn log_none<F: FnOnce()>(self, f: F) -> Self;
}
impl<T> OptionLog for Option<T> {
#[inline]
fn log_none<F: FnOnce()>(self, f: F) -> Self {
self.or_else(|| {
f();
None
})
}
}