summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/font.rs26
-rw-r--r--src/library/mod.rs11
-rw-r--r--tests/typ/library/font.typ5
3 files changed, 18 insertions, 24 deletions
diff --git a/src/library/font.rs b/src/library/font.rs
index 439d9805..79cc8518 100644
--- a/src/library/font.rs
+++ b/src/library/font.rs
@@ -12,10 +12,10 @@ use super::*;
/// # Named arguments
/// - Font Style: `style`, of type `font-style`.
/// - Font Weight: `weight`, of type `font-weight`.
-/// - Font Stretch: `stretch`, of type `font-stretch`.
/// - Serif family definition: `serif`, of type `font-families`.
/// - Sans-serif family definition: `sans-serif`, of type `font-families`.
/// - Monospace family definition: `monospace`, of type `font-families`.
+/// - Font Stretch: `stretch`, of type `relative`, between 0.5 and 2.0.
///
/// # Relevant types and constants
/// - Type `font-families`
@@ -42,16 +42,6 @@ use super::*;
/// - `extrabold` (800)
/// - `black` (900)
/// - coerces from `integer`
-/// - Type `font-stretch`
-/// - `ultra-condensed`
-/// - `extra-condensed`
-/// - `condensed`
-/// - `semi-condensed`
-/// - `normal`
-/// - `semi-expanded`
-/// - `expanded`
-/// - `extra-expanded`
-/// - `ultra-expanded`
pub fn font(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
let size = args.find::<Linear>(ctx);
let list: Vec<_> = args.filter::<FontFamily>(ctx).map(|f| f.to_string()).collect();
@@ -160,7 +150,7 @@ typify! {
}
typify! {
- FontStyle: "font style"
+ FontStyle: "font style",
}
typify! {
@@ -179,5 +169,15 @@ typify! {
}
typify! {
- FontStretch: "font stretch"
+ FontStretch: "font stretch",
+ Value::Relative(relative) => {
+ let f = |stretch: Self| Relative::new(stretch.to_ratio());
+ let [min, max] = [f(Self::UltraCondensed), f(Self::UltraExpanded)];
+ let value = Self::from_ratio(relative.get());
+ return if relative < min || relative > max {
+ CastResult::Warn(value, format!("should be between {} and {}", min, max))
+ } else {
+ CastResult::Ok(value)
+ };
+ },
}
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 7e968994..09fda20f 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -23,7 +23,7 @@ pub use spacing::*;
use std::fmt::{self, Display, Formatter};
-use fontdock::{FontStretch, FontStyle, FontWeight};
+use fontdock::{FontStyle, FontWeight};
use crate::eval::{Scope, ValueAny, ValueFunc};
use crate::exec::Softness;
@@ -81,15 +81,6 @@ pub fn new() -> Scope {
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
}
diff --git a/tests/typ/library/font.typ b/tests/typ/library/font.typ
index 566f2e87..c00bff5a 100644
--- a/tests/typ/library/font.typ
+++ b/tests/typ/library/font.typ
@@ -18,7 +18,7 @@
#font(weight: bold)[Bold]
// Set stretch (not available, matching closest).
-#font(stretch: ultra-condensed)[Condensed]
+#font(stretch: 50%)[Condensed]
// Set family.
#font("PT Sans")[Sans serif]
@@ -45,5 +45,8 @@ Emoji: 🐪, 🌋, 🏞
// Warning: 15-19 should be between 100 and 900
#font(weight: 2700)
+// Warning: 16-21 should be between 50% and 200%
+#font(stretch: 1000%)
+
// Error: 7-27 unexpected argument
#font(something: "invalid")