mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Switch from name to ratio for font stretch parameter 📐
This commit is contained in:
parent
8cdfc7faaf
commit
49bb7f9a2b
@ -12,10 +12,10 @@ use super::*;
|
|||||||
/// # Named arguments
|
/// # Named arguments
|
||||||
/// - Font Style: `style`, of type `font-style`.
|
/// - Font Style: `style`, of type `font-style`.
|
||||||
/// - Font Weight: `weight`, of type `font-weight`.
|
/// - Font Weight: `weight`, of type `font-weight`.
|
||||||
/// - Font Stretch: `stretch`, of type `font-stretch`.
|
|
||||||
/// - Serif family definition: `serif`, of type `font-families`.
|
/// - Serif family definition: `serif`, of type `font-families`.
|
||||||
/// - Sans-serif family definition: `sans-serif`, of type `font-families`.
|
/// - Sans-serif family definition: `sans-serif`, of type `font-families`.
|
||||||
/// - Monospace family definition: `monospace`, 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
|
/// # Relevant types and constants
|
||||||
/// - Type `font-families`
|
/// - Type `font-families`
|
||||||
@ -42,16 +42,6 @@ use super::*;
|
|||||||
/// - `extrabold` (800)
|
/// - `extrabold` (800)
|
||||||
/// - `black` (900)
|
/// - `black` (900)
|
||||||
/// - coerces from `integer`
|
/// - 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 {
|
pub fn font(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let size = args.find::<Linear>(ctx);
|
let size = args.find::<Linear>(ctx);
|
||||||
let list: Vec<_> = args.filter::<FontFamily>(ctx).map(|f| f.to_string()).collect();
|
let list: Vec<_> = args.filter::<FontFamily>(ctx).map(|f| f.to_string()).collect();
|
||||||
@ -160,7 +150,7 @@ typify! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typify! {
|
typify! {
|
||||||
FontStyle: "font style"
|
FontStyle: "font style",
|
||||||
}
|
}
|
||||||
|
|
||||||
typify! {
|
typify! {
|
||||||
@ -179,5 +169,15 @@ typify! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
};
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ pub use spacing::*;
|
|||||||
|
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
|
||||||
use fontdock::{FontStretch, FontStyle, FontWeight};
|
use fontdock::{FontStyle, FontWeight};
|
||||||
|
|
||||||
use crate::eval::{Scope, ValueAny, ValueFunc};
|
use crate::eval::{Scope, ValueAny, ValueFunc};
|
||||||
use crate::exec::Softness;
|
use crate::exec::Softness;
|
||||||
@ -81,15 +81,6 @@ pub fn new() -> Scope {
|
|||||||
set!(any: "bold", FontWeight::BOLD);
|
set!(any: "bold", FontWeight::BOLD);
|
||||||
set!(any: "extrabold", FontWeight::EXTRABOLD);
|
set!(any: "extrabold", FontWeight::EXTRABOLD);
|
||||||
set!(any: "black", FontWeight::BLACK);
|
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
|
std
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#font(weight: bold)[Bold]
|
#font(weight: bold)[Bold]
|
||||||
|
|
||||||
// Set stretch (not available, matching closest).
|
// Set stretch (not available, matching closest).
|
||||||
#font(stretch: ultra-condensed)[Condensed]
|
#font(stretch: 50%)[Condensed]
|
||||||
|
|
||||||
// Set family.
|
// Set family.
|
||||||
#font("PT Sans")[Sans serif]
|
#font("PT Sans")[Sans serif]
|
||||||
@ -45,5 +45,8 @@ Emoji: 🐪, 🌋, 🏞
|
|||||||
// Warning: 15-19 should be between 100 and 900
|
// Warning: 15-19 should be between 100 and 900
|
||||||
#font(weight: 2700)
|
#font(weight: 2700)
|
||||||
|
|
||||||
|
// Warning: 16-21 should be between 50% and 200%
|
||||||
|
#font(stretch: 1000%)
|
||||||
|
|
||||||
// Error: 7-27 unexpected argument
|
// Error: 7-27 unexpected argument
|
||||||
#font(something: "invalid")
|
#font(something: "invalid")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user