summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/library')
-rw-r--r--src/library/layout.rs2
-rw-r--r--src/library/mod.rs54
-rw-r--r--src/library/text.rs18
3 files changed, 36 insertions, 38 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs
index 19352062..cbc5ff94 100644
--- a/src/library/layout.rs
+++ b/src/library/layout.rs
@@ -199,7 +199,7 @@ impl Display for AlignValue {
}
}
-castable! {
+dynamic! {
AlignValue: "alignment",
}
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 28387218..3c1d752d 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -18,7 +18,7 @@ use std::rc::Rc;
use crate::color::{Color, RgbaColor};
use crate::eco::EcoString;
-use crate::eval::{EvalContext, FuncArgs, Scope, Template, Value};
+use crate::eval::{EvalContext, FuncArgs, Scope, Template, Type, Value};
use crate::exec::{Exec, FontFamily};
use crate::font::{FontStyle, FontWeight, VerticalFontMetric};
use crate::geom::*;
@@ -71,34 +71,34 @@ pub fn new() -> Scope {
std.def_const("forest", RgbaColor::new(0x43, 0xA1, 0x27, 0xFF));
// Arbitrary constants.
- std.def_any("start", AlignValue::Start);
- std.def_any("center", AlignValue::Center);
- std.def_any("end", AlignValue::End);
- std.def_any("left", AlignValue::Left);
- std.def_any("right", AlignValue::Right);
- std.def_any("top", AlignValue::Top);
- std.def_any("bottom", AlignValue::Bottom);
- std.def_any("ltr", Dir::LTR);
- std.def_any("rtl", Dir::RTL);
- std.def_any("ttb", Dir::TTB);
- std.def_any("btt", Dir::BTT);
- std.def_any("serif", FontFamily::Serif);
- std.def_any("sans-serif", FontFamily::SansSerif);
- std.def_any("monospace", FontFamily::Monospace);
- std.def_any("normal", FontStyle::Normal);
- std.def_any("italic", FontStyle::Italic);
- std.def_any("oblique", FontStyle::Oblique);
- std.def_any("regular", FontWeight::REGULAR);
- std.def_any("bold", FontWeight::BOLD);
- std.def_any("ascender", VerticalFontMetric::Ascender);
- std.def_any("cap-height", VerticalFontMetric::CapHeight);
- std.def_any("x-height", VerticalFontMetric::XHeight);
- std.def_any("baseline", VerticalFontMetric::Baseline);
- std.def_any("descender", VerticalFontMetric::Descender);
+ std.def_const("start", AlignValue::Start);
+ std.def_const("center", AlignValue::Center);
+ std.def_const("end", AlignValue::End);
+ std.def_const("left", AlignValue::Left);
+ std.def_const("right", AlignValue::Right);
+ std.def_const("top", AlignValue::Top);
+ std.def_const("bottom", AlignValue::Bottom);
+ std.def_const("ltr", Dir::LTR);
+ std.def_const("rtl", Dir::RTL);
+ std.def_const("ttb", Dir::TTB);
+ std.def_const("btt", Dir::BTT);
+ std.def_const("serif", FontFamily::Serif);
+ std.def_const("sans-serif", FontFamily::SansSerif);
+ std.def_const("monospace", FontFamily::Monospace);
+ std.def_const("normal", FontStyle::Normal);
+ std.def_const("italic", FontStyle::Italic);
+ std.def_const("oblique", FontStyle::Oblique);
+ std.def_const("regular", FontWeight::REGULAR);
+ std.def_const("bold", FontWeight::BOLD);
+ std.def_const("ascender", VerticalFontMetric::Ascender);
+ std.def_const("cap-height", VerticalFontMetric::CapHeight);
+ std.def_const("x-height", VerticalFontMetric::XHeight);
+ std.def_const("baseline", VerticalFontMetric::Baseline);
+ std.def_const("descender", VerticalFontMetric::Descender);
std
}
-castable! {
- Dir: "direction"
+dynamic! {
+ Dir: "direction",
}
diff --git a/src/library/text.rs b/src/library/text.rs
index 0f6f3ec1..14a0ee9a 100644
--- a/src/library/text.rs
+++ b/src/library/text.rs
@@ -78,7 +78,6 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
})
}
-#[derive(Debug)]
struct FontDef(Vec<FontFamily>);
castable! {
@@ -89,10 +88,9 @@ castable! {
.filter_map(|v| v.cast().ok())
.collect()
),
- #(family: FontFamily) => Self(vec![family]),
+ @family: FontFamily => Self(vec![family.clone()]),
}
-#[derive(Debug)]
struct FamilyDef(Vec<String>);
castable! {
@@ -106,28 +104,28 @@ castable! {
),
}
-castable! {
+dynamic! {
FontFamily: "font family",
- Value::Str(string) => Self::Named(string.to_lowercase())
+ Value::Str(string) => Self::Named(string.to_lowercase()),
}
-castable! {
+dynamic! {
FontStyle: "font style",
}
-castable! {
+dynamic! {
FontWeight: "font weight",
Value::Int(number) => {
u16::try_from(number).map_or(Self::BLACK, Self::from_number)
- }
+ },
}
-castable! {
+dynamic! {
FontStretch: "font stretch",
Value::Relative(relative) => Self::from_ratio(relative.get() as f32),
}
-castable! {
+dynamic! {
VerticalFontMetric: "vertical font metric",
}