1pub mod elements;
2pub mod xml_string_tools;
3pub mod xml;
4pub mod to_xml_attributes;
5pub mod attributes;
6pub mod to_xml;
7
8pub use simple_vector2 as sv2;
9
10macro_rules! wrapper_from {
11 ($mapping:ident, $element:ty, $wrapper:ident) => {
12 impl From<$element> for $wrapper {
13 fn from(value: $element) -> Self {
14 $wrapper::$mapping(value)
15 }
16 }
17 };
18}
19
20
21pub(crate) use wrapper_from;
22
23#[cfg(test)]
24mod tests {
25 use simple_vector2::Vector2;
26 use crate::elements::text::{FontWeight, Text};
27 use crate::to_xml::ToXml;
28 use crate::xml::document::Document;
29
30 #[test]
31 fn january() {
32 const REFERENCE_SIZE: Vector2<f32> = Vector2::new(800.0, 600.0);
33 const H1_SIZE:f32 = 36.0;
34
35 let month_header = Text::builder()
37 .position(Vector2::new(20.0, 50.0))
38 .font_family("Arial, sans-serif".to_string())
39 .font_size(H1_SIZE)
40 .font_weight(FontWeight::Bold)
41 .text("January".to_string())
42 .build();
43
44 let year_header = Text::builder()
45 .position(Vector2::new(20.0, 50.0))
46 .font_family("Arial, sans-serif".to_string())
47 .font_size(H1_SIZE)
48 .font_weight(FontWeight::Bold)
49 .text(2024.to_string())
50 .build();
51
52 let document = Document::new(
53 vec![
54 month_header.to_xml(),
55 year_header.to_xml(),
56 ],
57 REFERENCE_SIZE
58 );
59
60 println!("{}", document.as_xml());
61
62 assert_eq!(document.as_xml().to_string(),r#"<svg version="1.1" width="800" height="600" xmlns="http://www.w3.org/2000/svg">
63 <text x="20" y="50" font-family="Arial, sans-serif" font-size="36" font-weight="bold">
64 January
65 </text>
66 <text x="20" y="50" font-family="Arial, sans-serif" font-size="36" font-weight="bold">
67 2024
68 </text>
69</svg>"#);
70 }
71}