summaryrefslogtreecommitdiffstats
path: root/packages/svgbob/src/lib.rs
blob: 6d4f329459c310e5ff84249cbee63cfbba7fc5a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![deny(warnings)]
#![allow(unused)]
#![deny(clippy::all)]

pub mod buffer;
pub mod map;
mod merge;
mod point;
mod settings;
pub mod util;

pub use buffer::{
    fragment, fragment::Fragment, Cell, CellBuffer, Direction, FragmentBuffer,
    FragmentSpan, Property, Signal,
};
pub use merge::Merge;
pub use nalgebra;
pub use point::Point;
/// reexport sauron
pub use sauron;
pub use sauron::{Node, Render};
pub use settings::Settings;

pub fn to_svg(ascii: &str) -> String {
    to_svg_string_pretty(ascii)
}

/// convert svgbob ascii art to svg string with indentions
pub fn to_svg_string_pretty(ascii: &str) -> String {
    let cb = CellBuffer::from(ascii);
    let node: Node<()> = cb.get_node();
    let mut buffer = String::new();
    node.render(&mut buffer).expect("must render");
    buffer
}

/// convert svgbob ascii art to svg string
pub fn to_svg_string_compressed(ascii: &str) -> String {
    let cb = CellBuffer::from(ascii);
    let node: Node<()> = cb.get_node();
    node.render_to_string()
}

/// convert ascii art into an svg
pub fn to_svg_with_settings(ascii: &str, settings: &Settings) -> String {
    let cb = CellBuffer::from(ascii);
    let (node, _w, _h): (Node<()>, f32, f32) = cb.get_node_with_size(settings);
    let mut buffer = String::new();
    node.render(&mut buffer).expect("must render");
    buffer
}

/// convert ascii art to svg using the size supplied
pub fn to_svg_with_override_size(
    ascii: &str,
    settings: &Settings,
    w: f32,
    h: f32,
) -> String {
    let cb = CellBuffer::from(ascii);
    let node: Node<()> = cb.get_node_override_size(settings, w, h);
    let mut buffer = String::new();
    node.render(&mut buffer).expect("must render");
    buffer
}