From 87994cae767eb990e2c8657fe63a178022faf0c6 Mon Sep 17 00:00:00 2001 From: Cassie Eliot Date: Sat, 23 Mar 2024 13:05:02 +1100 Subject: [PATCH 1/3] Fixed crate-level comment --- src/lib.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3d2ddef..8e137df 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; From 69e16f171b2b40aa2f029127f4f38bd46ed2d30a Mon Sep 17 00:00:00 2001 From: Cassie Eliot Date: Sat, 23 Mar 2024 13:07:33 +1100 Subject: [PATCH 2/3] Added index values to COLORS rustdoc --- src/lib.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8e137df..8067fd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, From ffdff8ce331ed3823d985452406e151cf1c73254 Mon Sep 17 00:00:00 2001 From: Cassie Eliot Date: Sat, 23 Mar 2024 13:29:20 +1100 Subject: [PATCH 3/3] Added motivations for save_png vs save_svg --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8067fd6..4751811 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,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); @@ -225,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);