Struct svg_metadata::Metadata

source ·
pub struct Metadata {
    pub view_box: Option<ViewBox>,
    pub width: Option<Width>,
    pub height: Option<Height>,
}
Expand description

Contains all metadata that was extracted from an SVG image.

Fields§

§view_box: Option<ViewBox>

The viewBox of the SVG image A viewBox is a rectangle that defines the dimensions of the image. For more information see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox

§width: Option<Width>

The width of the SVG image

§height: Option<Height>

The height of the SVG image

Implementations§

source§

impl Metadata

source

pub fn parse_file<T: Into<PathBuf>>(path: T) -> Result<Metadata, MetadataError>

Parse an SVG file and extract metadata from it.

Example
use svg_metadata::{Metadata, ViewBox};

let meta = Metadata::parse_file("fixtures/test.svg").unwrap();
    assert_eq!(
    meta.view_box,
    Some(ViewBox {
        min_x: 0.0,
        min_y: 0.0,
        width: 96.0,
        height: 105.0
    })
);
Errors

Returns an error if the file cannot be read or if the SVG data is invalid.

source

pub fn parse<T: AsRef<str>>(input: T) -> Result<Metadata, MetadataError>

Parse SVG data and extract metadata from it.

Example
use svg_metadata::{Metadata, ViewBox, Width, Height, Unit};

let svg = r#"<svg viewBox="0 1 99 100" width="2em" height="10cm" xmlns="http://www.w3.org/2000/svg">
 <rect x="0" y="0" width="100%" height="100%"/>
</svg>"#;

let meta = Metadata::parse(svg).unwrap();
assert_eq!(
   meta.view_box,
   Some(ViewBox {
     min_x: 0.0,
     min_y: 1.0,
     width: 99.0,
     height: 100.0
   })
);
assert_eq!(
  meta.width,
  Some(Width {
    width: 2.0,
    unit: Unit::Em
  })
);
assert_eq!(
 meta.height,
 Some(Height {
   height: 10.0,
   unit: Unit::Cm
  })
);
Errors

Returns an error if the SVG data is invalid.

source

pub fn width(&self) -> Option<f64>

Returns the value of the width attribute. If the width is set to 100% then this refers to the width of the viewbox.

source

pub fn height(&self) -> Option<f64>

Returns the value of the height attribute. If the height is set to 100% then this refers to the height of the viewbox.

source

pub const fn view_box(&self) -> Option<ViewBox>

Return view_box

Trait Implementations§

source§

impl Clone for Metadata

source§

fn clone(&self) -> Metadata

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Metadata

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<Metadata> for Metadata

source§

fn eq(&self, other: &Metadata) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Metadata

source§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.