Implement svg::Handle::from_memory
Useful if you already have your SVG data in memory.
This commit is contained in:
parent
6e9ab1cd6f
commit
ae009158cc
4 changed files with 76 additions and 28 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue