···
1
1
+
[package]
2
2
+
name = "postamble-motif"
3
3
+
version = "0.1.0"
4
4
+
edition = "2024"
5
5
+
6
6
+
[dependencies]
7
7
+
base64 = "0.22.1"
8
8
+
enum2str = "0.1.16"
9
9
+
rand = "0.9.1"
10
10
+
shapemaker = { version = "1.2.2", path = "../.." }
11
11
+
svg = "0.18.0"
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 207.54 203.5">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="a">
14
14
+
<rect class="cls-1" x="8.5" y="8.5" width="128.56" height="128.99"/>
15
15
+
<line class="cls-1" x1="201.77" y1="197.26" x2="137.06" y2="137.49"/>
16
16
+
</g>
17
17
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 145.99 137.49">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="b">
14
14
+
<polyline class="cls-1" points="8.5 0 8.5 128.99 137.49 128.99 137.49 59.77 8.5 59.77"/>
15
15
+
</g>
16
16
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 73.21 86.23">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="e">
14
14
+
<path class="cls-1" d="M73.21,77.73H8.5V8.5h48.94c5.99,0,9.09,7.15,5,11.52L8.5,77.73"/>
15
15
+
</g>
16
16
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 137.06 137.49">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="l">
14
14
+
<polyline class="cls-1" points="8.5 0 8.5 128.99 137.06 128.99"/>
15
15
+
</g>
16
16
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 146.42 137.51">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="m">
14
14
+
<g>
15
15
+
<polyline class="cls-1" points="8.5 137.49 8.5 8.5 73 8.5 137.92 8.5 137.92 137.49"/>
16
16
+
<line class="cls-1" x1="73.21" y1="137.49" x2="73" y2="8.5"/>
17
17
+
<line class="cls-1" x1="105.67" y1="8.5" x2="105.67" y2="137.49"/>
18
18
+
<line class="cls-1" x1="41.61" y1="8.5" x2="41.61" y2="137.49"/>
19
19
+
</g>
20
20
+
</g>
21
21
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 145.56 145.99">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="o">
14
14
+
<rect class="cls-1" x="8.5" y="8.5" width="128.56" height="128.99"/>
15
15
+
</g>
16
16
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 145.99 266.48">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="p">
14
14
+
<polyline class="cls-1" points="8.5 266.48 8.5 8.5 137.49 8.5 137.49 137.49 8.5 137.49"/>
15
15
+
</g>
16
16
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 146.95 145.99">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="s">
14
14
+
<path class="cls-1" d="M146.95,8.5H8.5v64.5h120.16c5.12,0,9.26,4.15,9.26,9.26v55.23H8.5"/>
15
15
+
</g>
16
16
+
</svg>
···
1
1
+
<?xml version="1.0" encoding="UTF-8"?>
2
2
+
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 137.49 137.49">
3
3
+
<defs>
4
4
+
<style>
5
5
+
.cls-1 {
6
6
+
fill: none;
7
7
+
stroke: red;
8
8
+
stroke-miterlimit: 10;
9
9
+
stroke-width: 17px;
10
10
+
}
11
11
+
</style>
12
12
+
</defs>
13
13
+
<g id="t">
14
14
+
<g>
15
15
+
<polyline class="cls-1" points="137.49 128.99 8.5 128.99 8.5 59.61 8.5 0"/>
16
16
+
<line class="cls-1" x1="73" y1="60.63" x2="8.5" y2="60.63"/>
17
17
+
</g>
18
18
+
</g>
19
19
+
</svg>
···
1
1
+
<svg width="1370" height="2420" viewBox="-10 -10 1370 2420" xmlns="http://www.w3.org/2000/svg" ><rect x="-10" fill="white" y="-10" width="1370" height="2420" /><g class="layer" data-layer="root" ><image data-object="root--dIeOhbYYVycAvflNl2gTS" height="100" x="0" width="50" href="C:\Users\ewen\projects.local\shapemaker\examples\postamble-motif/letters/p.svg" y="0" style="" /><image data-object="root--6g9SoCwTTpV2LtY-4rH8H" height="50" width="50" x="50" href="C:\Users\ewen\projects.local\shapemaker\examples\postamble-motif/letters/o.svg" y="0" style="" /></g><defs /></svg>
···
1
1
+
use enum2str::EnumStr;
2
2
+
use shapemaker::*;
3
3
+
4
4
+
fn main() {
5
5
+
let mut canvas = Canvas::new(27, 48);
6
6
+
canvas.set_background(Color::White);
7
7
+
canvas
8
8
+
.root()
9
9
+
.add_anon(Letter::P.object(Region::new(0, 0, 0, 1).unwrap()));
10
10
+
canvas
11
11
+
.root()
12
12
+
.add_anon(Letter::O.object(Region::new(1, 0, 1, 0).unwrap()));
13
13
+
14
14
+
canvas
15
15
+
.render_to_svg_file("out.svg")
16
16
+
.expect("Failed to render SVG");
17
17
+
canvas
18
18
+
.render_to_png("out.png", 500)
19
19
+
.expect("Failed to render PNG");
20
20
+
}
21
21
+
22
22
+
#[derive(Debug, Clone, Copy, EnumStr)]
23
23
+
enum Letter {
24
24
+
P,
25
25
+
O,
26
26
+
S,
27
27
+
T,
28
28
+
A,
29
29
+
M,
30
30
+
B,
31
31
+
L,
32
32
+
E,
33
33
+
}
34
34
+
35
35
+
impl Letter {
36
36
+
fn object(&self, at: Region) -> ColoredObject {
37
37
+
Image(
38
38
+
at,
39
39
+
// format!(
40
40
+
// "data:image/svg+xml;base64,{}",
41
41
+
// BASE64.encode(
42
42
+
// fs::read_to_string(format!(
43
43
+
// "./letters/{}.svg",
44
44
+
// self.to_string().to_lowercase()
45
45
+
// ))
46
46
+
// .expect("Letter {self} not found")
47
47
+
// .replace(r#"<?xml version="1.0" encoding="UTF-8"?>"#, ""),
48
48
+
// )
49
49
+
// ),
50
50
+
format!(
51
51
+
"{}/letters/{}.svg",
52
52
+
std::path::absolute(".").unwrap().display(),
53
53
+
self.to_string().to_lowercase()
54
54
+
),
55
55
+
)
56
56
+
.into()
57
57
+
}
58
58
+
}