From 6ec1c6da8340d9a77ee6131b802e52a61d5cd379 Mon Sep 17 00:00:00 2001 From: Billy Messenger <60663878+BillyDM@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:15:19 -0500 Subject: [PATCH] remove SVG helper struct --- Cargo.toml | 1 + examples/svg-icons.rs | 8 +++---- src/icon.rs | 55 ------------------------------------------- 3 files changed, 4 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 01350f8..a002877 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/grovesNL/glyphon" license = "MIT OR Apache-2.0 OR Zlib" [features] +default = ["svg-icons"] svg-icons = ["dep:resvg"] [dependencies] diff --git a/examples/svg-icons.rs b/examples/svg-icons.rs index ee8a93a..6534f61 100644 --- a/examples/svg-icons.rs +++ b/examples/svg-icons.rs @@ -1,5 +1,5 @@ use glyphon::{ - icon::{IconDesc, IconRenderer, IconSourceID, IconSystem, SvgSource}, + icon::{IconDesc, IconRenderer, IconSourceID, IconSystem}, Attrs, Buffer, Cache, Color, Family, FontSystem, Metrics, Resolution, Shaping, SwashCache, TextArea, TextAtlas, TextBounds, TextRenderer, Viewport, }; @@ -96,14 +96,12 @@ async fn run() { // Add SVG sources to the icon system. icon_system.add_svg( IconSourceID(0), - SvgSource::Data(LION_SVG).load(&Default::default()).unwrap(), + resvg::usvg::Tree::from_data(LION_SVG, &Default::default()).unwrap(), true, ); icon_system.add_svg( IconSourceID(1), - SvgSource::Data(EAGLE_SVG) - .load(&Default::default()) - .unwrap(), + resvg::usvg::Tree::from_data(EAGLE_SVG, &Default::default()).unwrap(), false, ); diff --git a/src/icon.rs b/src/icon.rs index 6da86a0..37c4442 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -425,58 +425,3 @@ impl IconSystem { fn zero_depth(_: usize) -> f32 { 0f32 } - -/// A helper struct to load SVG data. -pub enum SvgSource<'a> { - Data(&'a [u8]), - String(&'a str), - Path(&'a Path), -} - -impl<'a> SvgSource<'a> { - /// Load and parse the SVG data. - pub fn load(self, opt: &usvg::Options<'_>) -> Result { - let tree = match self { - Self::Data(data) => usvg::Tree::from_data(data, opt)?, - Self::String(text) => usvg::Tree::from_str(text, opt)?, - Self::Path(path) => { - let data = std::fs::read(path)?; - usvg::Tree::from_data(&data, opt)? - } - }; - - Ok(tree) - } -} - -/// An error that occured while loading and parsing an [`SvgSource`]. -#[derive(Debug)] -pub enum SvgSourceError { - /// An error occured while parsing the SVG data. - SvgError(usvg::Error), - /// An error occured while loading the SVG file. - IoError(std::io::Error), -} - -impl std::error::Error for SvgSourceError {} - -impl std::fmt::Display for SvgSourceError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::SvgError(e) => write!(f, "Could not load svg source: vg error: {}", e), - Self::IoError(e) => write!(f, "Could not load svg source: io error: {}", e), - } - } -} - -impl From for SvgSourceError { - fn from(e: usvg::Error) -> Self { - Self::SvgError(e) - } -} - -impl From for SvgSourceError { - fn from(e: std::io::Error) -> Self { - Self::IoError(e) - } -}