mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Number style -> type
This commit is contained in:
parent
072e7c710c
commit
c4a87e5e7c
@ -11,7 +11,7 @@ use crate::font::{
|
|||||||
};
|
};
|
||||||
use crate::geom::{Dir, Em, Length, Point, Size};
|
use crate::geom::{Dir, Em, Length, Point, Size};
|
||||||
use crate::style::{
|
use crate::style::{
|
||||||
FontFeatures, NumberPosition, NumberStyle, NumberWidth, Style, TextStyle,
|
FontFeatures, NumberPosition, NumberType, NumberWidth, Style, TextStyle,
|
||||||
};
|
};
|
||||||
use crate::util::SliceExt;
|
use crate::util::SliceExt;
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
castable! {
|
castable! {
|
||||||
NumberStyle: "auto or string",
|
NumberType: "auto or string",
|
||||||
Value::Auto => Self::Auto,
|
Value::Auto => Self::Auto,
|
||||||
Value::Str(string) => match string.as_str() {
|
Value::Str(string) => match string.as_str() {
|
||||||
"lining" => Self::Lining,
|
"lining" => Self::Lining,
|
||||||
@ -176,7 +176,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
let ligatures = args.named("ligatures")?;
|
let ligatures = args.named("ligatures")?;
|
||||||
let discretionary_ligatures = args.named("discretionary-ligatures")?;
|
let discretionary_ligatures = args.named("discretionary-ligatures")?;
|
||||||
let historical_ligatures = args.named("historical-ligatures")?;
|
let historical_ligatures = args.named("historical-ligatures")?;
|
||||||
let number_style = args.named("number-style")?;
|
let number_type = args.named("number-type")?;
|
||||||
let number_width = args.named("number-width")?;
|
let number_width = args.named("number-width")?;
|
||||||
let number_position = args.named("number-position")?;
|
let number_position = args.named("number-position")?;
|
||||||
let slashed_zero = args.named("slashed-zero")?;
|
let slashed_zero = args.named("slashed-zero")?;
|
||||||
@ -233,7 +233,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
set!(text.features_mut().ligatures.standard => ligatures);
|
set!(text.features_mut().ligatures.standard => ligatures);
|
||||||
set!(text.features_mut().ligatures.discretionary => discretionary_ligatures);
|
set!(text.features_mut().ligatures.discretionary => discretionary_ligatures);
|
||||||
set!(text.features_mut().ligatures.historical => historical_ligatures);
|
set!(text.features_mut().ligatures.historical => historical_ligatures);
|
||||||
set!(text.features_mut().numbers.style => number_style);
|
set!(text.features_mut().numbers.type_ => number_type);
|
||||||
set!(text.features_mut().numbers.width => number_width);
|
set!(text.features_mut().numbers.width => number_width);
|
||||||
set!(text.features_mut().numbers.position => number_position);
|
set!(text.features_mut().numbers.position => number_position);
|
||||||
set!(text.features_mut().numbers.slashed_zero => slashed_zero);
|
set!(text.features_mut().numbers.slashed_zero => slashed_zero);
|
||||||
@ -661,10 +661,10 @@ fn tags(features: &FontFeatures) -> Vec<Feature> {
|
|||||||
feat(b"hilg", 1);
|
feat(b"hilg", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
match features.numbers.style {
|
match features.numbers.type_ {
|
||||||
NumberStyle::Auto => {}
|
NumberType::Auto => {}
|
||||||
NumberStyle::Lining => feat(b"lnum", 1),
|
NumberType::Lining => feat(b"lnum", 1),
|
||||||
NumberStyle::OldStyle => feat(b"onum", 1),
|
NumberType::OldStyle => feat(b"onum", 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
match features.numbers.width {
|
match features.numbers.width {
|
||||||
|
@ -268,7 +268,7 @@ pub struct FontFeatures {
|
|||||||
pub smallcaps: bool,
|
pub smallcaps: bool,
|
||||||
/// Whether to apply stylistic alternates. ("salt")
|
/// Whether to apply stylistic alternates. ("salt")
|
||||||
pub alternates: bool,
|
pub alternates: bool,
|
||||||
/// Which stylistic set to apply. ("ss00" - "ss20")
|
/// Which stylistic set to apply. ("ss01" - "ss20")
|
||||||
pub stylistic_set: Option<u8>,
|
pub stylistic_set: Option<u8>,
|
||||||
/// Configuration of ligature features.
|
/// Configuration of ligature features.
|
||||||
pub ligatures: LigatureFeatures,
|
pub ligatures: LigatureFeatures,
|
||||||
@ -317,7 +317,7 @@ impl Default for LigatureFeatures {
|
|||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct NumberFeatures {
|
pub struct NumberFeatures {
|
||||||
/// Whether to use lining or old-style numbers.
|
/// Whether to use lining or old-style numbers.
|
||||||
pub style: NumberStyle,
|
pub type_: NumberType,
|
||||||
/// Whether to use proportional or tabular numbers.
|
/// Whether to use proportional or tabular numbers.
|
||||||
pub width: NumberWidth,
|
pub width: NumberWidth,
|
||||||
/// How to position numbers vertically.
|
/// How to position numbers vertically.
|
||||||
@ -331,7 +331,7 @@ pub struct NumberFeatures {
|
|||||||
impl Default for NumberFeatures {
|
impl Default for NumberFeatures {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
style: NumberStyle::Auto,
|
type_: NumberType::Auto,
|
||||||
width: NumberWidth::Auto,
|
width: NumberWidth::Auto,
|
||||||
position: NumberPosition::Normal,
|
position: NumberPosition::Normal,
|
||||||
slashed_zero: false,
|
slashed_zero: false,
|
||||||
@ -340,9 +340,9 @@ impl Default for NumberFeatures {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How numbers / figures look.
|
/// Which kind of numbers / figures to select.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub enum NumberStyle {
|
pub enum NumberType {
|
||||||
/// Select the font's preference.
|
/// Select the font's preference.
|
||||||
Auto,
|
Auto,
|
||||||
/// Numbers that fit well with capital text. ("lnum")
|
/// Numbers that fit well with capital text. ("lnum")
|
||||||
|
@ -21,10 +21,10 @@ a vs #font(alternates: true)[a] \
|
|||||||
fi vs. #font(ligatures: false)[No fi] \
|
fi vs. #font(ligatures: false)[No fi] \
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test number style.
|
// Test number type.
|
||||||
#font("Roboto")
|
#font("Roboto")
|
||||||
#font(number-style: "old-style") 0123456789 \
|
#font(number-type: "old-style") 0123456789 \
|
||||||
#font(number-style: auto)[0123456789]
|
#font(number-type: auto)[0123456789]
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test number width.
|
// Test number width.
|
||||||
@ -57,8 +57,8 @@ fi vs. #font(features: (liga: 0))[No fi]
|
|||||||
#font(stylistic-set: 25)
|
#font(stylistic-set: 25)
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 21-32 expected "lining" or "old-style"
|
// Error: 20-31 expected "lining" or "old-style"
|
||||||
#font(number-style: "different")
|
#font(number-type: "different")
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 17-22 expected array of strings or dictionary mapping tags to integers, found boolean
|
// Error: 17-22 expected array of strings or dictionary mapping tags to integers, found boolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user