diff --git a/README.md b/README.md index 2dcb7ea..15aa60b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Documentation on [docs.rs](https://docs.rs/dessin/0.8.2-pre/) ```rust use dessin::prelude::*; -use dessin_svg::ToSVG; #[derive(Default, Shape)] struct MyShape { @@ -58,7 +57,7 @@ fn main() { MyShape(say_this = "Hello world"), ]); - let svg = dessin.to_svg().unwrap(); + let svg = dessin_svg::to_string(&dessin).unwrap(); } ``` diff --git a/dessin-svg/src/lib.rs b/dessin-svg/src/lib.rs index 477a03a..b0d0d5f 100644 --- a/dessin-svg/src/lib.rs +++ b/dessin-svg/src/lib.rs @@ -7,7 +7,6 @@ use nalgebra::{Scale2, Transform2}; use std::{ fmt::{self, Write}, io::Cursor, - ops::Deref, }; #[derive(Debug)] @@ -356,67 +355,48 @@ impl Exporter for SVGExporter { } } -pub struct SVG { - pub input_dessin: Shape, - pub options: SVGOptions, -} - -impl SVG { - pub fn to_string_with_options(&self, options: SVGOptions) -> Result { - let (min_x, min_y, span_x, span_y) = match options.viewport { - ViewPort::ManualCentered { width, height } => { - (-width / 2., -height / 2., width, height) - } - ViewPort::ManualViewport { - x, - y, - width, - height, - } => (x - width / 2., y - height / 2., width, height), - ViewPort::AutoCentered => { - let bb = self.input_dessin.local_bounding_box().straigthen(); - - let mirror_bb = bb - .transform(&nalgebra::convert::<_, Transform2>(Scale2::new( - -1., -1., - ))) - .into_straight(); - - let overall_bb = bb.join(mirror_bb); - - ( - -overall_bb.width() / 2., - -overall_bb.height() / 2., - overall_bb.width(), - overall_bb.height(), - ) - } - ViewPort::AutoBoundingBox => { - let bb = self.input_dessin.local_bounding_box().straigthen(); - - (bb.top_left().x, -bb.top_left().y, bb.width(), bb.height()) - } - }; +pub fn to_string_with_options(shape: &Shape, options: SVGOptions) -> Result { + let (min_x, min_y, span_x, span_y) = match options.viewport { + ViewPort::ManualCentered { width, height } => (-width / 2., -height / 2., width, height), + ViewPort::ManualViewport { + x, + y, + width, + height, + } => (x - width / 2., y - height / 2., width, height), + ViewPort::AutoCentered => { + let bb = shape.local_bounding_box().straigthen(); + + let mirror_bb = bb + .transform(&nalgebra::convert::<_, Transform2>(Scale2::new( + -1., -1., + ))) + .into_straight(); + + let overall_bb = bb.join(mirror_bb); + + ( + -overall_bb.width() / 2., + -overall_bb.height() / 2., + overall_bb.width(), + overall_bb.height(), + ) + } + ViewPort::AutoBoundingBox => { + let bb = shape.local_bounding_box().straigthen(); - let mut exporter = SVGExporter::new(min_x, min_y, span_x, span_y); + (bb.top_left().x, -bb.top_left().y, bb.width(), bb.height()) + } + }; - let parent_transform = nalgebra::convert(Scale2::new(1., -1.)); - self.input_dessin - .write_into_exporter(&mut exporter, &parent_transform)?; + let mut exporter = SVGExporter::new(min_x, min_y, span_x, span_y); - Ok(exporter.finish()) - } + let parent_transform = nalgebra::convert(Scale2::new(1., -1.)); + shape.write_into_exporter(&mut exporter, &parent_transform)?; - pub fn to_string(&self) -> Result { - self.to_string_with_options(self.options.clone()) - } + Ok(exporter.finish()) } -impl> From for SVG { - fn from(value: T) -> Self { - SVG { - input_dessin: value.into(), - options: SVGOptions::default(), - } - } +pub fn to_string(shape: &Shape) -> Result { + to_string_with_options(shape, SVGOptions::default()) } diff --git a/examples/432technologies.rs b/examples/432technologies.rs index 19bd3de..5a68c7b 100644 --- a/examples/432technologies.rs +++ b/examples/432technologies.rs @@ -4,12 +4,8 @@ use dessin::{ }; use dessin_image::ToImage; use dessin_pdf::ToPDF; -use dessin_svg::SVG; use project_root::get_project_root; -use std::{ - f32::consts::{FRAC_PI_4, FRAC_PI_8, PI}, - fs, -}; +use std::f32::consts::{FRAC_PI_4, FRAC_PI_8, PI}; const C: Color = rgb(0x3b, 0x54, 0x85); fn c(a: u8) -> Color { @@ -306,20 +302,6 @@ fn main() { let path = get_project_root().unwrap().join("examples/out/"); - // SVG - fs::write( - "./target/432.svg", - SVG::from(dessin.clone()).to_string().unwrap(), - ) - .unwrap(); - - // // PDF - // fs::write( - // path.join("432technologies.pdf"), - // dessin.to_pdf().unwrap().save_to_bytes().unwrap(), - // ) - // .unwrap(); - // Image dessin2!({ dessin }(scale = [5., 5.])) .rasterize() diff --git a/examples/animation.rs b/examples/animation.rs index e2b73d2..6fee2fe 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -8,6 +8,10 @@ use project_root::get_project_root; fn main() { let skip_animation = std::env::var("NO_ANIMATION") == Ok("1".to_string()); + let path = get_project_root() + .unwrap() + .join("examples/out/animation.svg"); + let test_img = dessin2!(polygons::Triangle!(fill = Color::BLUE) > (scale = [50., 50.])) .rasterize() .unwrap(); @@ -22,8 +26,12 @@ fn main() { ); loop { - let final_image = SVG::from(frame.clone()).to_string().unwrap(); - fs::write("test.svg", final_image).unwrap(); + let final_image = to_string(&frame.clone()).unwrap(); + fs::write(&path, final_image).unwrap(); + + if skip_animation { + break; + } std::thread::sleep(Duration::from_millis(100)); let mut t = triangle.write().unwrap(); diff --git a/examples/any_triangle_with_macro.rs b/examples/any_triangle_with_macro.rs index 1acfac5..f33178e 100644 --- a/examples/any_triangle_with_macro.rs +++ b/examples/any_triangle_with_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -36,7 +35,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/any_triangle.svg"), - SVG::from(triangle).to_string().unwrap(), + dessin_svg::to_string(&triangle).unwrap(), ) .unwrap(); } diff --git a/examples/any_triangle_without_macro.rs b/examples/any_triangle_without_macro.rs index c495009..eb3173c 100644 --- a/examples/any_triangle_without_macro.rs +++ b/examples/any_triangle_without_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -38,7 +37,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/any_triangle.svg"), - SVG::from(triangle).to_string().unwrap(), + dessin_svg::to_string(&triangle.into()).unwrap(), ) .unwrap(); } diff --git a/examples/arc_with_macro.rs b/examples/arc_with_macro.rs index 7b3fe08..d4b3a6f 100644 --- a/examples/arc_with_macro.rs +++ b/examples/arc_with_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -23,7 +22,7 @@ fn main() { // prints in svg version fs::write( get_project_root().unwrap().join("examples/out/arc.svg"), - SVG::from(arc).to_string().unwrap(), + dessin_svg::to_string(&arc).unwrap(), ) .unwrap(); } diff --git a/examples/arc_without_macro.rs b/examples/arc_without_macro.rs index dcb9f41..53ba7a3 100644 --- a/examples/arc_without_macro.rs +++ b/examples/arc_without_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -26,7 +25,7 @@ fn main() { // prints in svg version fs::write( get_project_root().unwrap().join("examples/out/arc.svg"), - SVG::from(arc).to_string().unwrap(), + dessin_svg::to_string(&arc.into()).unwrap(), ) .unwrap(); } diff --git a/examples/basque_cross_with_macro.rs b/examples/basque_cross_with_macro.rs index d46cd88..cd3ecdc 100644 --- a/examples/basque_cross_with_macro.rs +++ b/examples/basque_cross_with_macro.rs @@ -1,7 +1,7 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; +use project_root::get_project_root; fn main() { let basque_cross: Shape = dessin2!([ @@ -47,8 +47,10 @@ fn main() { // prints in svg version fs::write( - "./out/basque_cross.svg", - SVG::from(basque_cross).to_string().unwrap(), + get_project_root() + .unwrap() + .join("examples/out/basque_cross.svg"), + dessin_svg::to_string(&basque_cross).unwrap(), ) .unwrap(); } diff --git a/examples/basque_cross_without_macro.rs b/examples/basque_cross_without_macro.rs index c9afbcb..572aba9 100644 --- a/examples/basque_cross_without_macro.rs +++ b/examples/basque_cross_without_macro.rs @@ -1,7 +1,6 @@ -use std::{f32::consts::PI, fs}; - use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; +use project_root::get_project_root; +use std::{f32::consts::PI, fs}; fn main() { let circle_point = Circle::default().with_radius(0.01); @@ -75,8 +74,10 @@ fn main() { // prints in svg version with Shape::from(...) -> Shape::Group(group) because of the group fs::write( - "./out/basque_cross.svg", - SVG::from(Shape::Group(group)).to_string().unwrap(), + get_project_root() + .unwrap() + .join("examples/out/basque_cross.svg"), + dessin_svg::to_string(&Shape::Group(group)).unwrap(), ) .unwrap(); } diff --git a/examples/blue_triangle_with_macro.rs b/examples/blue_triangle_with_macro.rs index c0c1864..b5d4ea5 100644 --- a/examples/blue_triangle_with_macro.rs +++ b/examples/blue_triangle_with_macro.rs @@ -4,7 +4,6 @@ use dessin::{ nalgebra::{Rotation2, Scale2}, prelude::{polygons::Triangle, *}, }; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -31,7 +30,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/blue_triangle.svg"), - SVG::from(triangle).to_string().unwrap(), + dessin_svg::to_string(&triangle).unwrap(), ) .unwrap(); } diff --git a/examples/blue_triangle_without_macro.rs b/examples/blue_triangle_without_macro.rs index 04ca6a1..2413818 100644 --- a/examples/blue_triangle_without_macro.rs +++ b/examples/blue_triangle_without_macro.rs @@ -4,7 +4,6 @@ use dessin::{ nalgebra::{Rotation2, Scale2}, prelude::{polygons::Triangle, *}, }; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -32,7 +31,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/blue_triangle.svg"), - SVG::from(triangle).to_string().unwrap(), + dessin_svg::to_string(&triangle.into()).unwrap(), ) .unwrap(); } diff --git a/examples/diamond_with_macro.rs b/examples/diamond_with_macro.rs index cbb208b..ee2843c 100644 --- a/examples/diamond_with_macro.rs +++ b/examples/diamond_with_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -14,34 +13,33 @@ fn main() { Diamond: #( - // chooses a width of 4 for following the x axis - width={4.} + // chooses a width of 4 for following the x axis + width={4.} - // chooses a size of 5 between the origin and the diamond top apex following the y axis - height_top={5.} + // chooses a size of 5 between the origin and the diamond top apex following the y axis + height_top={5.} - // chooses a size of 3 between the origin and the diamond bottom apex following the y axis - height_bottom={3.} + // chooses a size of 3 between the origin and the diamond bottom apex following the y axis + height_bottom={3.} - // paints the inside of the diamond in diamond color - fill={rgb(185,242,255)} + // paints the inside of the diamond in diamond color + fill={rgb(185,242,255)} - // creates a black margin with a width of 0.1 (0.05 outside and the same inside the diamond) - stroke={Stroke::Full { color: rgb(0, 0, 0), width: 0.1}} + // creates a black margin with a width of 0.1 (0.05 outside and the same inside the diamond) + stroke={Stroke::Full { color: rgb(0, 0, 0), width: 0.1}} - // chooses a rotation of -10 radians in the trigonometric direction - rotate={Rotation2::new(-10_f32.to_radians())} - - // moves of 15 following the x axis and 5 following the y axis - translate={[15.,5.]} - ), + // chooses a rotation of -10 radians in the trigonometric direction + rotate={Rotation2::new(-10_f32.to_radians())} + // moves of 15 following the x axis and 5 following the y axis + translate={[15.,5.]} + ), ]); // prints in svg version fs::write( get_project_root().unwrap().join("examples/out/diamond.svg"), - SVG::from(diamond).to_string().unwrap(), + dessin_svg::to_string(&diamond).unwrap(), ) .unwrap(); } diff --git a/examples/diamond_without_macro.rs b/examples/diamond_without_macro.rs index f094edb..82a155b 100644 --- a/examples/diamond_without_macro.rs +++ b/examples/diamond_without_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::prelude::*; -use dessin_svg::SVG; use dessin::nalgebra::Rotation2; use project_root::get_project_root; @@ -51,7 +50,7 @@ fn main() { // prints in svg version with Shape::from(...) -> Shape::Group(group) because of the group fs::write( get_project_root().unwrap().join("examples/out/diamond.svg"), - SVG::from(Shape::Group(group)).to_string().unwrap(), + dessin_svg::to_string(&Shape::Group(group)).unwrap(), ) .unwrap(); } diff --git a/examples/green_rectangle_with_macro.rs b/examples/green_rectangle_with_macro.rs index 505a731..90f6633 100644 --- a/examples/green_rectangle_with_macro.rs +++ b/examples/green_rectangle_with_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -31,7 +30,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/green_rectangle.svg"), - SVG::from(rectangle).to_string().unwrap(), + dessin_svg::to_string(&rectangle).unwrap(), ) .unwrap(); } diff --git a/examples/green_rectangle_without_macro.rs b/examples/green_rectangle_without_macro.rs index 6ffd976..019361a 100644 --- a/examples/green_rectangle_without_macro.rs +++ b/examples/green_rectangle_without_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -27,7 +26,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/green_rectangle.svg"), - SVG::from(rectangle).to_string().unwrap(), + dessin_svg::to_string(&rectangle.into()).unwrap(), ) .unwrap(); } diff --git a/examples/line_with_macro.rs b/examples/line_with_macro.rs index ced2571..852fa19 100644 --- a/examples/line_with_macro.rs +++ b/examples/line_with_macro.rs @@ -1,7 +1,6 @@ -use std::fs; - use dessin::{nalgebra::Point2, prelude::*}; -use dessin_svg::SVG; +use project_root::get_project_root; +use std::fs; fn main() { let line: Shape = dessin2!([ @@ -24,5 +23,9 @@ fn main() { ]); // prints in svg version - fs::write("./out/line.svg", SVG::from(line).to_string().unwrap()).unwrap(); + fs::write( + get_project_root().unwrap().join("examples/out/line.svg"), + dessin_svg::to_string(&line).unwrap(), + ) + .unwrap(); } diff --git a/examples/line_without_macro.rs b/examples/line_without_macro.rs index 5e76d56..925b242 100644 --- a/examples/line_without_macro.rs +++ b/examples/line_without_macro.rs @@ -1,7 +1,6 @@ -use std::fs; - use dessin::{nalgebra::Point2, prelude::*}; -use dessin_svg::SVG; +use project_root::get_project_root; +use std::fs; fn main() { let circle_point = Circle::default().with_radius(0.1); @@ -30,8 +29,8 @@ fn main() { // prints in svg version fs::write( - "./out/line.svg", - SVG::from(Shape::Group(group)).to_string().unwrap(), + get_project_root().unwrap().join("examples/out/out.svg"), + dessin_svg::to_string(&Shape::Group(group)).unwrap(), ) .unwrap(); } diff --git a/examples/optical_effect_with_macro.rs b/examples/optical_effect_with_macro.rs index 02f77e6..6c2e3c8 100644 --- a/examples/optical_effect_with_macro.rs +++ b/examples/optical_effect_with_macro.rs @@ -1,7 +1,7 @@ -use std::{f32::consts::PI, fs}; - use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::{SVGOptions, SVG}; +use dessin_svg::SVGOptions; +use project_root::get_project_root; +use std::{f32::consts::PI, fs}; fn main() { let optical_effect: Shape = dessin2!([ @@ -50,22 +50,19 @@ fn main() { // prints in svg version fs::write( - "./out/optical_effect.svg", - SVG::from(truc) - .to_string_with_options(SVGOptions { + get_project_root() + .unwrap() + .join("examples/out/optical_effect.svg"), + dessin_svg::to_string_with_options( + &truc, + SVGOptions { viewport: dessin_svg::ViewPort::ManualCentered { width: 14., height: 14., }, - }) - .unwrap(), + }, + ) + .unwrap(), ) .unwrap(); } -//.to_svg_with_options(SVGOptions{viewport:dessin_svg::ViewPort::ManualCentered permits to choose how we will see the svg -//.to_svg_with_options(SVGOptions{viewport:dessin_svg::ViewPort::ManualCentered permits to choose how we will see the svg - -// Note : -// (1) This solution is not be optimal because we can merge these two renctangles into one. -// (1) This solution is not be optimal because we can merge these two renctangles into one. -// (2) This code micht not return what we expect if you use "microsoft edge" but there is no same case with others like "google chrome" or "firefox" diff --git a/examples/optical_effect_without_macro.rs b/examples/optical_effect_without_macro.rs index f52cb7c..968a2d8 100644 --- a/examples/optical_effect_without_macro.rs +++ b/examples/optical_effect_without_macro.rs @@ -1,7 +1,7 @@ -use std::{f32::consts::PI, fs}; - use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::{SVGOptions, SVG}; +use dessin_svg::SVGOptions; +use project_root::get_project_root; +use std::{f32::consts::PI, fs}; fn main() { let rectangle1 = Rectangle::default(); @@ -89,15 +89,19 @@ fn main() { // prints in svg version with Shape::from(...) -> Shape::Group(group) because of the group fs::write( - "./out/optical_effect.svg", - SVG::from(Shape::Group(group)) - .to_string_with_options(SVGOptions { + get_project_root() + .unwrap() + .join("examples/out/optical_effect.svg"), + dessin_svg::to_string_with_options( + &Shape::Group(group), + SVGOptions { viewport: dessin_svg::ViewPort::ManualCentered { width: 14., height: 14., }, - }) - .unwrap(), + }, + ) + .unwrap(), ) .unwrap(); } diff --git a/examples/orange_octogon_with_macro.rs b/examples/orange_octogon_with_macro.rs index 04babb7..5ae5a57 100644 --- a/examples/orange_octogon_with_macro.rs +++ b/examples/orange_octogon_with_macro.rs @@ -1,7 +1,6 @@ //Attention ! It is the same way to make all polygons, you just have to replace : "Octogon" by "Polygon< the number of side you want >" use dessin::{contrib::polygons::Octogon, nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; use std::fs; @@ -27,7 +26,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/orange_octogon.svg"), - SVG::from(octogon).to_string().unwrap(), + dessin_svg::to_string(&octogon).unwrap(), ) .unwrap(); } diff --git a/examples/orange_octogon_without_macro.rs b/examples/orange_octogon_without_macro.rs index 7362d0b..ec159e9 100644 --- a/examples/orange_octogon_without_macro.rs +++ b/examples/orange_octogon_without_macro.rs @@ -1,7 +1,6 @@ //Attention ! It is the same way to make all polygons, you just have to replace : "Octogon" by "Polygon< the number of side you want >" use dessin::{contrib::polygons::Octogon, nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; use std::fs; @@ -30,7 +29,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/orange_octogon.svg"), - SVG::from(octogon).to_string().unwrap(), + dessin_svg::to_string(&octogon.into()).unwrap(), ) .unwrap(); } diff --git a/examples/out/optical_effect.svg b/examples/out/optical_effect.svg index 2f47a4c..3c19f15 100644 --- a/examples/out/optical_effect.svg +++ b/examples/out/optical_effect.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/examples/out/out.svg b/examples/out/out.svg new file mode 100644 index 0000000..69b2133 --- /dev/null +++ b/examples/out/out.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/out/red_circle.svg b/examples/out/red_circle.svg index bb16fe1..400e4c8 100644 --- a/examples/out/red_circle.svg +++ b/examples/out/red_circle.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/examples/out/text_rotation.png b/examples/out/text_rotation.png new file mode 100644 index 0000000..cac26d7 Binary files /dev/null and b/examples/out/text_rotation.png differ diff --git a/examples/out/text_rotation.svg b/examples/out/text_rotation.svg new file mode 100644 index 0000000..088140d --- /dev/null +++ b/examples/out/text_rotation.svg @@ -0,0 +1 @@ +Helloworld!Thisisme! \ No newline at end of file diff --git a/examples/red_circle_with_macro.rs b/examples/red_circle_with_macro.rs index e39f8fd..8c9f012 100644 --- a/examples/red_circle_with_macro.rs +++ b/examples/red_circle_with_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -27,7 +26,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/red_circle.svg"), - SVG::from(circle).to_string().unwrap(), + dessin_svg::to_string(&circle).unwrap(), ) .unwrap(); } diff --git a/examples/red_circle_without_macro.rs b/examples/red_circle_without_macro.rs index 31285c2..b363640 100644 --- a/examples/red_circle_without_macro.rs +++ b/examples/red_circle_without_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::prelude::*; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -31,7 +30,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/red_circle.svg"), - SVG::from(circle).to_string().unwrap(), + dessin_svg::to_string(&circle.into()).unwrap(), ) .unwrap(); } diff --git a/examples/right_angle_triangle_with_macro.rs b/examples/right_angle_triangle_with_macro.rs index 5dcf3f5..81596fa 100644 --- a/examples/right_angle_triangle_with_macro.rs +++ b/examples/right_angle_triangle_with_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -36,7 +35,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/right_angle_triangle.svg"), - SVG::from(triangle).to_string().unwrap(), + dessin_svg::to_string(&triangle).unwrap(), ) .unwrap(); } diff --git a/examples/right_angle_triangle_without_macro.rs b/examples/right_angle_triangle_without_macro.rs index 05fb568..256a7ef 100644 --- a/examples/right_angle_triangle_without_macro.rs +++ b/examples/right_angle_triangle_without_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -37,7 +36,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/right_angle_triangle.svg"), - SVG::from(triangle).to_string().unwrap(), + dessin_svg::to_string(&triangle.into()).unwrap(), ) .unwrap(); } diff --git a/examples/text_rotation.rs b/examples/text_rotation.rs index 88871b3..06d6fef 100644 --- a/examples/text_rotation.rs +++ b/examples/text_rotation.rs @@ -1,7 +1,7 @@ use dessin::{nalgebra::Rotation2, prelude::*}; use dessin_image::ToImage; use dessin_pdf::ToPDF; -use dessin_svg::SVG; +use project_root::get_project_root; use std::{f32::consts::PI, fs}; #[derive(Shape, Default)] @@ -41,17 +41,12 @@ fn main() { } ); - // SVG - fs::write( - "./target/text_rotation.svg", - SVG::from(dessin.clone()).to_string().unwrap(), - ) - .unwrap(); + let path = get_project_root().unwrap().join("examples/out/"); - // PDF + // SVG fs::write( - "./target/text_rotation.pdf", - dessin.to_pdf().unwrap().save_to_bytes().unwrap(), + path.join("text_rotation.svg"), + dessin_svg::to_string(&dessin.clone()).unwrap(), ) .unwrap(); @@ -60,6 +55,6 @@ fn main() { .rasterize() .unwrap() .into_rgba8() - .save("./target/text_rotation.png") + .save(path.join("text_rotation.png")) .unwrap(); } diff --git a/examples/textbox_with_macro.rs b/examples/textbox_with_macro.rs index 58927c9..4e21d67 100644 --- a/examples/textbox_with_macro.rs +++ b/examples/textbox_with_macro.rs @@ -1,7 +1,6 @@ use std::fs; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -42,7 +41,7 @@ fn main() { // prints in svg version fs::write( get_project_root().unwrap().join("examples/out/text.svg"), - SVG::from(text).to_string().unwrap(), + dessin_svg::to_string(&text).unwrap(), ) .unwrap(); } diff --git a/examples/textbox_without_macro.rs b/examples/textbox_without_macro.rs index bef6a5d..598e0e2 100644 --- a/examples/textbox_without_macro.rs +++ b/examples/textbox_without_macro.rs @@ -1,5 +1,4 @@ use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; use std::fs; @@ -41,7 +40,7 @@ fn main() { // prints in svg version fs::write( get_project_root().unwrap().join("examples/out/text.svg"), - SVG::from(text).to_string().unwrap(), + dessin_svg::to_string(&text.into()).unwrap(), ) .unwrap(); } diff --git a/examples/yellow_thick_arc_with_macro.rs b/examples/yellow_thick_arc_with_macro.rs index f28734e..ad4c8bc 100644 --- a/examples/yellow_thick_arc_with_macro.rs +++ b/examples/yellow_thick_arc_with_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -34,7 +33,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/yellow_thick_arc.svg"), - SVG::from(thick_arc).to_string().unwrap(), + dessin_svg::to_string(&thick_arc).unwrap(), ) .unwrap(); } diff --git a/examples/yellow_thick_arc_without_macro.rs b/examples/yellow_thick_arc_without_macro.rs index e5357d5..a9be661 100644 --- a/examples/yellow_thick_arc_without_macro.rs +++ b/examples/yellow_thick_arc_without_macro.rs @@ -1,7 +1,6 @@ use std::{f32::consts::PI, fs}; use dessin::{nalgebra::Rotation2, prelude::*}; -use dessin_svg::SVG; use project_root::get_project_root; fn main() { @@ -36,7 +35,7 @@ fn main() { get_project_root() .unwrap() .join("examples/out/yellow_thick_arc.svg"), - SVG::from(thick_arc).to_string().unwrap(), + dessin_svg::to_string(&thick_arc.into()).unwrap(), ) .unwrap(); }