Number style -> type

This commit is contained in:
Laurenz 2021-11-02 10:30:27 +01:00
parent 072e7c710c
commit c4a87e5e7c
3 changed files with 18 additions and 18 deletions

View File

@ -11,7 +11,7 @@ use crate::font::{
};
use crate::geom::{Dir, Em, Length, Point, Size};
use crate::style::{
FontFeatures, NumberPosition, NumberStyle, NumberWidth, Style, TextStyle,
FontFeatures, NumberPosition, NumberType, NumberWidth, Style, TextStyle,
};
use crate::util::SliceExt;
@ -103,7 +103,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
}
castable! {
NumberStyle: "auto or string",
NumberType: "auto or string",
Value::Auto => Self::Auto,
Value::Str(string) => match string.as_str() {
"lining" => Self::Lining,
@ -176,7 +176,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let ligatures = args.named("ligatures")?;
let discretionary_ligatures = args.named("discretionary-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_position = args.named("number-position")?;
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.discretionary => discretionary_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.position => number_position);
set!(text.features_mut().numbers.slashed_zero => slashed_zero);
@ -661,10 +661,10 @@ fn tags(features: &FontFeatures) -> Vec<Feature> {
feat(b"hilg", 1);
}
match features.numbers.style {
NumberStyle::Auto => {}
NumberStyle::Lining => feat(b"lnum", 1),
NumberStyle::OldStyle => feat(b"onum", 1),
match features.numbers.type_ {
NumberType::Auto => {}
NumberType::Lining => feat(b"lnum", 1),
NumberType::OldStyle => feat(b"onum", 1),
}
match features.numbers.width {

View File

@ -268,7 +268,7 @@ pub struct FontFeatures {
pub smallcaps: bool,
/// Whether to apply stylistic alternates. ("salt")
pub alternates: bool,
/// Which stylistic set to apply. ("ss00" - "ss20")
/// Which stylistic set to apply. ("ss01" - "ss20")
pub stylistic_set: Option<u8>,
/// Configuration of ligature features.
pub ligatures: LigatureFeatures,
@ -317,7 +317,7 @@ impl Default for LigatureFeatures {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct NumberFeatures {
/// Whether to use lining or old-style numbers.
pub style: NumberStyle,
pub type_: NumberType,
/// Whether to use proportional or tabular numbers.
pub width: NumberWidth,
/// How to position numbers vertically.
@ -331,7 +331,7 @@ pub struct NumberFeatures {
impl Default for NumberFeatures {
fn default() -> Self {
Self {
style: NumberStyle::Auto,
type_: NumberType::Auto,
width: NumberWidth::Auto,
position: NumberPosition::Normal,
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)]
pub enum NumberStyle {
pub enum NumberType {
/// Select the font's preference.
Auto,
/// Numbers that fit well with capital text. ("lnum")

View File

@ -21,10 +21,10 @@ a vs #font(alternates: true)[a] \
fi vs. #font(ligatures: false)[No fi] \
---
// Test number style.
// Test number type.
#font("Roboto")
#font(number-style: "old-style") 0123456789 \
#font(number-style: auto)[0123456789]
#font(number-type: "old-style") 0123456789 \
#font(number-type: auto)[0123456789]
---
// Test number width.
@ -57,8 +57,8 @@ fi vs. #font(features: (liga: 0))[No fi]
#font(stylistic-set: 25)
---
// Error: 21-32 expected "lining" or "old-style"
#font(number-style: "different")
// Error: 20-31 expected "lining" or "old-style"
#font(number-type: "different")
---
// Error: 17-22 expected array of strings or dictionary mapping tags to integers, found boolean