rough_piet/lib.rs
1// This crate is entirely safe
2#![forbid(unsafe_code)]
3// Ensures that `pub` means published in the public API.
4// This property is useful for reasoning about breaking API changes.
5#![deny(unreachable_pub)]
6
7//!
8//! This crate is an adapter crate between [roughr](https://github.com/orhanbalci/rough-rs/main/roughr) and
9//! [piet](https://github.com/linebender/piet) crates. Converts from roughr drawing
10//! primitives to piets path types. Also has convenience traits for drawing onto piet contexts. For more detailed
11//! information you can check roughr crate.
12//!
13//! Below examples are output of [rough_piet](https://github.com/orhanbalci/rough-rs/tree/main/rough_piet) adapter.
14//!
15//! ## 📦 Cargo.toml
16//!
17//! ```toml
18//! [dependencies]
19//! rough_piet = "0.1"
20//! ```
21//!
22//! ## 🔧 Example
23//!
24//! ### Rectangle
25//!
26//! ```ignore
27//! let options = OptionsBuilder::default()
28//! .stroke(Srgba::from_raw(&[114u8, 87u8, 82u8, 255u8]).into_format())
29//! .fill(Srgba::from_raw(&[254u8, 246u8, 201u8, 255u8]).into_format())
30//! .fill_style(FillStyle::Hachure)
31//! .fill_weight(DPI * 0.01)
32//! .build()
33//! .unwrap();
34//! let generator = KurboGenerator::new(options);
35//! let rect_width = 100.0;
36//! let rect_height = 50.0;
37//! let rect = generator.rectangle::<f32>(
38//! (WIDTH as f32 - rect_width) / 2.0,
39//! (HEIGHT as f32 - rect_height) / 2.0,
40//! rect_width,
41//! rect_height,
42//! );
43//! let background_color = Color::from_hex_str("96C0B7").unwrap();
44//!
45//! rc.fill(
46//! Rect::new(0.0, 0.0, WIDTH as f64, HEIGHT as f64),
47//! &background_color,
48//! );
49//! rect.draw(&mut rc);
50//! ```
51//!
52//! ### 🖨️ Output Rectangle
53//! 
54//!
55//! ### Circle
56//!
57//! ```ignore
58//! let options = OptionsBuilder::default()
59//! .stroke(Srgba::from_raw(&[114u8, 87u8, 82u8, 255u8]).into_format())
60//! .fill(Srgba::from_raw(&[254u8, 246u8, 201u8, 255u8]).into_format())
61//! .fill_style(FillStyle::Hachure)
62//! .fill_weight(DPI * 0.01)
63//! .build()
64//! .unwrap();
65//! let generator = KurboGenerator::new(options);
66//! let circle_paths = generator.circle::<f32>(
67//! (WIDTH as f32) / 2.0,
68//! (HEIGHT as f32) / 2.0,
69//! HEIGHT as f32 - 10.0f32,
70//! );
71//! let background_color = Color::from_hex_str("96C0B7").unwrap();
72//!
73//! rc.fill(
74//! Rect::new(0.0, 0.0, WIDTH as f64, HEIGHT as f64),
75//! &background_color,
76//! );
77//! circle_paths.draw(&mut rc);
78//! ```
79//!
80//! ### 🖨️ Output Circle
81//! 
82//!
83//!
84//! ### Ellipse
85//!
86//! ```ignore
87//! let options = OptionsBuilder::default()
88//! .stroke(Srgba::from_raw(&[114u8, 87u8, 82u8, 255u8]).into_format())
89//! .fill(Srgba::from_raw(&[254u8, 246u8, 201u8, 255u8]).into_format())
90//! .fill_style(FillStyle::Hachure)
91//! .fill_weight(DPI * 0.01)
92//! .build()
93//! .unwrap();
94//! let generator = KurboGenerator::new(options);
95//! let ellipse_paths = generator.ellipse::<f32>(
96//! (WIDTH as f32) / 2.0,
97//! (HEIGHT as f32) / 2.0,
98//! WIDTH as f32 - 10.0,
99//! HEIGHT as f32 - 10.0,
100//! );
101//! let background_color = Color::from_hex_str("96C0B7").unwrap();
102//!
103//! rc.fill(
104//! Rect::new(0.0, 0.0, WIDTH as f64, HEIGHT as f64),
105//! &background_color,
106//! );
107//! ellipse_paths.draw(&mut rc);
108//! ```
109//!
110//! ### 🖨️ Output Ellipse
111//! 
112//!
113//!
114//! ### Svg Path
115//!
116//! ```ignore
117//! let options = OptionsBuilder::default()
118//! .stroke(Srgba::from_raw(&[114u8, 87u8, 82u8, 255u8]).into_format())
119//! .fill(Srgba::from_raw(&[254u8, 246u8, 201u8, 255u8]).into_format())
120//! .fill_style(FillStyle::Hachure)
121//! .fill_weight(DPI * 0.01)
122//! .build()
123//! .unwrap();
124//! let generator = KurboGenerator::new(options);
125//! let heart_svg_path = "M140 20C73 20 20 74 20 140c0 135 136 170 228 303 88-132 229-173 229-303 0-66-54-120-120-120-48 0-90 28-109 69-19-41-60-69-108-69z".into();
126//! let heart_svg_path_drawing = generator.path::<f32>(heart_svg_path);
127//! let background_color = Color::from_hex_str("96C0B7").unwrap();
128//!
129//! rc.fill(
130//! Rect::new(0.0, 0.0, WIDTH as f64, HEIGHT as f64),
131//! &background_color,
132//! );
133//! heart_svg_path_drawing.draw(&mut rc);
134//! ```
135//!
136//! ### 🖨️ Output Svg Path
137//! 
138//!
139//! ## Filler Implementation Status
140//! - [x] Hachure
141//! - [x] Zigzag
142//! - [x] Cross-Hatch
143//! - [x] Dots
144//! - [x] Dashed
145//! - [x] Zigzag-Line
146//!
147//! ## 🔭 Examples
148//!
149//! For more examples have a look at the
150//! [examples](https://github.com/orhanbalci/rough-rs/tree/main/rough_piet/examples) folder.
151
152pub mod kurbo_generator;
153pub use kurbo_generator::*;