pub struct SvgImageData {
pub tree: Arc<Tree>,
pub intrinsic_dimensions: SvgIntrinsicDimensions,
}Expand description
A parsed SVG image.
usvg always resolves the root <svg> to a concrete usvg::Tree::size,
falling back to the viewBox size when width/height are absent or given
as percentages. For CSS sizing purposes, however, such an SVG has no
intrinsic width/height (only an intrinsic aspect ratio). The accessors on
this type resolve the CSS intrinsic dimensions from the declared root
attributes, which are captured at parse time.
Fields§
§tree: Arc<Tree>The parsed SVG tree.
intrinsic_dimensions: SvgIntrinsicDimensionsThe dimensions declared on the root <svg> element.
Implementations§
Source§impl SvgImageData
impl SvgImageData
Sourcepub fn from_data(data: &[u8], options: &Options<'_>) -> Result<Self, Error>
pub fn from_data(data: &[u8], options: &Options<'_>) -> Result<Self, Error>
Parse an SVG image from raw data, capturing both the rendered
usvg::Tree and the declared root dimensions from a single XML
parse.
Like usvg::Tree::from_data, gzip-compressed data (SVGZ) is
decompressed first.
Sourcepub fn intrinsic_width(&self) -> Option<f32>
pub fn intrinsic_width(&self) -> Option<f32>
The intrinsic width in CSS px, present only when the root <svg>
declared an absolute (non-percentage) width.
Sourcepub fn intrinsic_height(&self) -> Option<f32>
pub fn intrinsic_height(&self) -> Option<f32>
The intrinsic height in CSS px, present only when the root <svg>
declared an absolute (non-percentage) height.
Sourcepub fn viewbox_aspect_ratio(&self) -> Option<f32>
pub fn viewbox_aspect_ratio(&self) -> Option<f32>
The aspect ratio of the root <svg>’s viewBox, if it declares one.
Sourcepub fn resolved_width(&self, container_width: Option<f32>) -> Option<f32>
pub fn resolved_width(&self, container_width: Option<f32>) -> Option<f32>
The root width attribute resolved against a containing block width:
percentages resolve against the containing block (None if it is
indefinite) and an absent attribute is None.
This is only appropriate for an inline <svg> element, where the
attributes behave as presentation attributes. SVG used as an image
(e.g. <img src> or a background) must use Self::intrinsic_width,
as its intrinsic dimensions are context-free per CSS.
Sourcepub fn resolved_height(&self, container_height: Option<f32>) -> Option<f32>
pub fn resolved_height(&self, container_height: Option<f32>) -> Option<f32>
The root height attribute resolved against a containing block height.
See Self::resolved_width.
Sourcepub fn aspect_ratio(&self) -> f32
pub fn aspect_ratio(&self) -> f32
The intrinsic aspect ratio of the SVG: the ratio of its declared
width/height when both are absolute lengths, otherwise the
viewBox ratio, otherwise the ratio of the resolved
usvg::Tree::size (which is always non-zero).
Sourcepub fn intrinsic_size(&self) -> (f32, f32)
pub fn intrinsic_size(&self) -> (f32, f32)
The intrinsic dimensions of the SVG resolved per CSS replaced element
sizing: a missing dimension is computed from the declared one and the
intrinsic aspect ratio; if neither is declared, the resolved
usvg::Tree::size is used as a fallback.
Trait Implementations§
Source§impl Clone for SvgImageData
impl Clone for SvgImageData
Source§fn clone(&self) -> SvgImageData
fn clone(&self) -> SvgImageData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SvgImageData
impl !UnwindSafe for SvgImageData
impl Freeze for SvgImageData
impl Send for SvgImageData
impl Sync for SvgImageData
impl Unpin for SvgImageData
impl UnsafeUnpin for SvgImageData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more