From ae009158cc322b69403a2512ac51582062029c99 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 31 Mar 2020 00:39:18 +0200 Subject: Implement `svg::Handle::from_memory` Useful if you already have your SVG data in memory. --- wgpu/src/image/vector.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'wgpu/src/image/vector.rs') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index bae0f82f..b6776827 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -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); -- cgit