diff --git a/src/lib.rs b/src/lib.rs index 3d2ddef..4751811 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,22 +1,22 @@ +//! The unsvg crate provides a very simple interface for drawing images. +//! +//! See below for an example: +//! +//! ```rust +//! use unsvg::{Image, COLORS, Error}; +//! +//! fn main() -> Result<(), Error> { +//! let mut img: Image = Image::new(200, 200); +//! let second_point = img.draw_simple_line(10.0, 10.0, 120, 100.0, COLORS[1])?; +//! let third_point = img.draw_simple_line(second_point.0, second_point.1, 240, 100.0, COLORS[2])?; +//! let _ = img.draw_simple_line(third_point.0, third_point.1, 0, 100.0, COLORS[3])?; +//! +//! img.save_svg("path_to.svg")?; +//! +//! Ok(()) +//! } +//! ``` use resvg::usvg::{NodeExt, TreeWriting, XmlOptions}; -/// The unsvg crate provides a very simple interface for drawing images. -/// -/// See below for an example: -/// -/// ```rust -/// use unsvg::{Image, COLORS, Error}; -/// -/// fn main() -> Result<(), Error> { -/// let mut img: Image = Image::new(200, 200); -/// let second_point = img.draw_simple_line(10.0, 10.0, 120, 100.0, COLORS[1])?; -/// let third_point = img.draw_simple_line(second_point.0, second_point.1, 240, 100.0, COLORS[2])?; -/// let _ = img.draw_simple_line(third_point.0, third_point.1, 0, 100.0, COLORS[3])?; -/// -/// img.save_svg("path_to.svg")?; -/// -/// Ok(()) -/// } -/// ``` use resvg::{tiny_skia, usvg}; use std::rc::Rc; @@ -41,22 +41,24 @@ type Result = core::result::Result; /// This contains 16 simple colors which users can select from. /// These correspond to the 16 colors available in the original Logo language. /// The colors are: -/// - Black -/// - Blue -/// - Cyan -/// - Green -/// - Red -/// - Magenta -/// - Yellow -/// - White -/// - Brown -/// - Tan -/// - Forest -/// - Aqua -/// - Salmon -/// - Purple -/// - Orange -/// - Grey +/// ``` +/// 0: Black +/// 1: Blue +/// 2: Cyan +/// 3: Green +/// 4: Red +/// 5: Magenta +/// 6: Yellow +/// 7: White +/// 8: Brown +/// 9: Tan +/// 10: Forest +/// 11: Aqua +/// 12: Salmon +/// 13: Purple +/// 14: Orange +/// 15: Grey +/// ``` pub static COLORS: [Color; 16] = [ Color { red: 0, @@ -209,7 +211,10 @@ impl Image { (self.width, self.height) } - /// Save the image to a file. + /// Save the image to a file in the `png` format. + /// + /// Rasterises the image and stores it as a grid of pixels. + /// Use this if you want an image that is easy to display/view. /// /// ```rs /// let image = Image::new(100, 100); @@ -223,7 +228,10 @@ impl Image { pixmap.save_png(path).map_err(|e| Error(e.to_string())) } - /// Save the image to a file. + /// Save the image to a file in the `svg` format. + /// + /// Stores the image in a lossless vector image format. + /// Use this if the precision of your lines is important. /// /// ```rs /// let image = Image::new(100, 100);