Implement svg::Handle::from_memory

Useful if you already have your SVG data in memory.
This commit is contained in:
Héctor Ramón Jiménez 2020-03-31 00:39:18 +02:00
parent 6e9ab1cd6f
commit ae009158cc
4 changed files with 76 additions and 28 deletions

View file

@ -45,9 +45,19 @@ impl Cache {
let opt = resvg::Options::default();
let svg = match resvg::usvg::Tree::from_file(handle.path(), &opt.usvg) {
Ok(tree) => Svg::Loaded(tree),
Err(_) => Svg::NotFound,
let svg = match handle.data() {
svg::Data::Path(path) => {
match resvg::usvg::Tree::from_file(path, &opt.usvg) {
Ok(tree) => Svg::Loaded(tree),
Err(_) => Svg::NotFound,
}
}
svg::Data::Bytes(bytes) => {
match resvg::usvg::Tree::from_data(&bytes, &opt.usvg) {
Ok(tree) => Svg::Loaded(tree),
Err(_) => Svg::NotFound,
}
}
};
let _ = self.svgs.insert(handle.id(), svg);