diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-17 23:14:19 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-17 23:14:19 +0100 |
| commit | 49bb7f9a2bd2404fa6e14208041ef6a94068c1ec (patch) | |
| tree | e915ef96a1429def1135a8e17a9cfd875c37b728 /src/library | |
| parent | 8cdfc7faafc1d8df60d44e5db9d1c9e26345675b (diff) | |
Switch from name to ratio for font stretch parameter 📐
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/font.rs | 26 | ||||
| -rw-r--r-- | src/library/mod.rs | 11 |
2 files changed, 14 insertions, 23 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 } |
