1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
use crate::prelude::{Handle, IfBoolSome, NativeAccess}; use crate::{interop, Path}; use skia_bindings as sb; use skia_bindings::SkPath; use std::ffi::CString; pub fn from_svg(svg: impl AsRef<str>) -> Option<Path> { let str = CString::new(svg.as_ref()).unwrap(); let mut path = Path::default(); unsafe { sb::SkParsePath_FromSVGString(str.as_ptr(), path.native_mut()) }.if_true_some(path) } pub fn to_svg(path: &Path) -> String { let mut svg = interop::String::default(); unsafe { sb::SkParsePath_ToSVGString(path.native(), svg.native_mut()) }; svg.as_str().into() } impl Handle<SkPath> { pub fn from_svg(svg: impl AsRef<str>) -> Option<Path> { from_svg(svg) } pub fn to_svg(&self) -> String { to_svg(self) } }