summaryrefslogtreecommitdiff
path: root/src/library/mod.rs
blob: 59198846d700cd48e4315aacc4d7f445f99bf09c (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! The standard library.
//!
//! Call [`new`] to obtain a [`Scope`] containing all standard library
//! definitions.

mod extend;
mod insert;
mod layout;
mod style;

pub use extend::*;
pub use insert::*;
pub use layout::*;
pub use style::*;

use fontdock::{FontStretch, FontStyle, FontWeight};

use crate::eval::{Scope, ValueAny, ValueFunc};
use crate::geom::Dir;

/// Construct a scope containing all standard library definitions.
pub fn new() -> Scope {
    let mut std = Scope::new();
    macro_rules! set {
        (func: $name:expr, $func:expr) => {
            std.def_const($name, ValueFunc::new($name, $func))
        };
        (any: $var:expr, $any:expr) => {
            std.def_const($var, ValueAny::new($any))
        };
    }

    // Functions.
    set!(func: "align", align);
    set!(func: "box", box_);
    set!(func: "font", font);
    set!(func: "h", h);
    set!(func: "image", image);
    set!(func: "page", page);
    set!(func: "pagebreak", pagebreak);
    set!(func: "repr", repr);
    set!(func: "rgb", rgb);
    set!(func: "type", type_);
    set!(func: "v", v);

    // Constants.
    set!(any: "left", Alignment::Left);
    set!(any: "center", Alignment::Center);
    set!(any: "right", Alignment::Right);
    set!(any: "top", Alignment::Top);
    set!(any: "bottom", Alignment::Bottom);
    set!(any: "ltr", Dir::LTR);
    set!(any: "rtl", Dir::RTL);
    set!(any: "ttb", Dir::TTB);
    set!(any: "btt", Dir::BTT);
    set!(any: "serif", FontFamily::Serif);
    set!(any: "sans-serif", FontFamily::SansSerif);
    set!(any: "monospace", FontFamily::Monospace);
    set!(any: "normal", FontStyle::Normal);
    set!(any: "italic", FontStyle::Italic);
    set!(any: "oblique", FontStyle::Oblique);
    set!(any: "thin", FontWeight::THIN);
    set!(any: "extralight", FontWeight::EXTRALIGHT);
    set!(any: "light", FontWeight::LIGHT);
    set!(any: "regular", FontWeight::REGULAR);
    set!(any: "medium", FontWeight::MEDIUM);
    set!(any: "semibold", FontWeight::SEMIBOLD);
    set!(any: "bold", FontWeight::BOLD);
    set!(any: "extrabold", FontWeight::EXTRABOLD);
    set!(any: "black", FontWeight::BLACK);
    set!(any: "ultra-condensed", FontStretch::UltraCondensed);
    set!(any: "extra-condensed", FontStretch::ExtraCondensed);
    set!(any: "condensed", FontStretch::Condensed);
    set!(any: "semi-condensed", FontStretch::SemiCondensed);
    set!(any: "normal", FontStretch::Normal);
    set!(any: "semi-expanded", FontStretch::SemiExpanded);
    set!(any: "expanded", FontStretch::Expanded);
    set!(any: "extra-expanded", FontStretch::ExtraExpanded);
    set!(any: "ultra-expanded", FontStretch::UltraExpanded);

    std
}