fret_core/svg.rs
1use crate::ids::SvgId;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
4pub enum SvgFit {
5 /// Uniformly scale to fully fit inside the target rect (no cropping).
6 #[default]
7 Contain,
8 /// Uniformly scale based on target width (height may overflow and should be clipped).
9 Width,
10 /// Non-uniformly scale to match the target rect (may distort).
11 Stretch,
12}
13
14/// SVG asset registration service.
15///
16/// This keeps `SceneOp` cheap (it stores `SvgId`, not raw bytes) while allowing renderers to
17/// rasterize/cache SVGs at paint time using their GPU context.
18pub trait SvgService {
19 /// Register SVG bytes and return a stable `SvgId`.
20 ///
21 /// Implementations may deduplicate repeated registrations.
22 fn register_svg(&mut self, bytes: &[u8]) -> SvgId;
23
24 /// Release a previously registered SVG.
25 ///
26 /// This is a ref-counted release: each successful `register_svg` increments a reference count
27 /// (including deduplicated registrations that return an existing `SvgId`), and
28 /// `unregister_svg` decrements it. Implementations should only drop the underlying bytes and
29 /// any cached rasterizations when the count reaches zero.
30 fn unregister_svg(&mut self, svg: SvgId) -> bool;
31}