geo_svg/lib.rs
1//! This crate is a lib to generate SVG strings from [geo-types](https://docs.rs/geo-types/0.7.13/geo_types/).
2//!
3//! Below is an example of a geometry collection rendered to SVG.
4//!
5//! 
6//!
7//! # Features
8//!
9//! - [GeometryCollection](https://docs.rs/geo-types/0.7.13/geo_types/geometry/struct.GeometryCollection.html) and all variants of [Geometry](https://docs.rs/geo-types/0.7.13/geo_types/enum.Geometry.html) are supported
10//! - the viewport size is automatically computed to contain all shapes
11//! - style and formatting options are available
12//!
13//! # Example
14//!
15//! The following will show how to convert a line to a SVG string.
16//! The [`to_svg`] method is provided by the [`ToSvg`] trait which is implemented for all [geo-types](https://docs.rs/geo-types/0.7.13/geo_types/).
17//!
18//! ```
19//! # fn main() {
20//! use geo_types::{Coord, Line, Point};
21//! use geo_svg::{Color, ToSvg};
22//! let point = Point::new(10.0, 28.1);
23//! let line = Line::new(
24//! Coord { x: 114.19, y: 22.26 },
25//! Coord { x: 15.93, y: -15.76 },
26//! );
27//!
28//! let svg = point
29//! .to_svg()
30//! .with_radius(2.0)
31//! .and(line.to_svg().with_stroke_width(2.5))
32//! .with_fill_color(Color::Named("red"))
33//! .with_stroke_color(Color::Rgb(200, 0, 100))
34//! .with_fill_opacity(0.7);
35//!
36//! println!("{}", svg);
37//! # assert_eq!(svg.to_string(), r#"<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" viewBox="7 -18.26 109.69 49.36"><circle cx="10.0" cy="28.1" r="2" fill="red" fill-opacity="0.7" stroke="rgb(200,0,100)"/><path d="M 114.19 22.26 L 15.93 -15.76" fill="red" fill-opacity="0.7" stroke="rgb(200,0,100)" stroke-width="2.5"/></svg>"#);
38//! # }
39//! ```
40//!
41//! ## Result
42//!
43//! ```xml
44//! <svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" viewBox="7 -18.26 109.69 49.36"><circle cx="10" cy="28.1" r="2" fill="red" fill-opacity="0.7" stroke="rgb(200,0,100)"/><path d="M 114.19 22.26 L 15.93 -15.76" fill="red" fill-opacity="0.7" stroke="rgb(200,0,100)" stroke-width="2.5"/></svg>
45//! ```
46//!
47//! [`ToSvg`]: svg/trait.ToSvg.html
48//! [`to_svg`]: svg/trait.ToSvg.html#method.to_svg
49
50mod color;
51mod combine;
52mod style;
53mod svg;
54mod svg_impl;
55mod text;
56mod to_svg;
57mod to_svg_str;
58mod unit;
59mod viewbox;
60
61pub use color::*;
62pub use combine::*;
63pub use style::*;
64pub use svg::Svg;
65pub use text::*;
66pub use to_svg::*;
67pub use to_svg_str::*;
68pub use unit::Unit;
69pub use viewbox::ViewBox;