mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Rename some library arguments
- font - color -> fill - shorthands for families and size - decoration functions - color -> stroke - strength -> thickness - position -> offset - invert offsets: now positive goes downwards just like the rest of typst
This commit is contained in:
parent
551e3af9d0
commit
7e2c217cbc
@ -165,17 +165,17 @@ impl Default for FontState {
|
|||||||
/// Describes a line that could be positioned over, under or on top of text.
|
/// Describes a line that could be positioned over, under or on top of text.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Hash)]
|
||||||
pub struct LineState {
|
pub struct LineState {
|
||||||
|
/// Stroke color of the line. Defaults to the text color if `None`.
|
||||||
|
pub stroke: Option<Fill>,
|
||||||
/// Thickness of the line's stroke. Calling functions should attempt to
|
/// Thickness of the line's stroke. Calling functions should attempt to
|
||||||
/// read this value from the appropriate font tables if this is `None`.
|
/// read this value from the appropriate font tables if this is `None`.
|
||||||
pub strength: Option<Linear>,
|
pub thickness: Option<Linear>,
|
||||||
/// Position of the line relative to the baseline. Calling functions should
|
/// Position of the line relative to the baseline. Calling functions should
|
||||||
/// attempt to read this value from the appropriate font tables if this is
|
/// attempt to read this value from the appropriate font tables if this is
|
||||||
/// `None`.
|
/// `None`.
|
||||||
pub position: Option<Linear>,
|
pub offset: Option<Linear>,
|
||||||
/// Amount that the line will be longer or shorter than its associated text.
|
/// Amount that the line will be longer or shorter than its associated text.
|
||||||
pub extent: Linear,
|
pub extent: Linear,
|
||||||
/// Color of the line. Will default to text color if `None`.
|
|
||||||
pub fill: Option<Fill>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Font family definitions.
|
/// Font family definitions.
|
||||||
|
@ -396,23 +396,24 @@ fn decorate(
|
|||||||
let mut apply = |substate: &LineState, metrics: fn(&Face) -> &LineMetrics| {
|
let mut apply = |substate: &LineState, metrics: fn(&Face) -> &LineMetrics| {
|
||||||
let metrics = metrics(&ctx.cache.font.get(face_id));
|
let metrics = metrics(&ctx.cache.font.get(face_id));
|
||||||
|
|
||||||
let strength = substate
|
let stroke = substate.stroke.unwrap_or(state.fill);
|
||||||
.strength
|
|
||||||
|
let thickness = substate
|
||||||
|
.thickness
|
||||||
.map(|s| s.resolve(state.size))
|
.map(|s| s.resolve(state.size))
|
||||||
.unwrap_or(metrics.strength.to_length(state.size));
|
.unwrap_or(metrics.strength.to_length(state.size));
|
||||||
|
|
||||||
let position = substate
|
let offset = substate
|
||||||
.position
|
.offset
|
||||||
.map(|s| s.resolve(state.size))
|
.map(|s| s.resolve(state.size))
|
||||||
.unwrap_or(metrics.position.to_length(state.size));
|
.unwrap_or(-metrics.position.to_length(state.size));
|
||||||
|
|
||||||
let extent = substate.extent.resolve(state.size);
|
let extent = substate.extent.resolve(state.size);
|
||||||
let fill = substate.fill.unwrap_or(state.fill);
|
|
||||||
|
|
||||||
let pos = Point::new(pos.x - extent, pos.y - position);
|
let pos = Point::new(pos.x - extent, pos.y + offset);
|
||||||
let target = Point::new(width + 2.0 * extent, Length::zero());
|
let target = Point::new(width + 2.0 * extent, Length::zero());
|
||||||
let shape = Shape::Line(target, strength);
|
let shape = Shape::Line(target, thickness);
|
||||||
let element = Element::Geometry(shape, fill);
|
let element = Element::Geometry(shape, stroke);
|
||||||
|
|
||||||
frame.push(pos, element);
|
frame.push(pos, element);
|
||||||
};
|
};
|
||||||
|
@ -6,14 +6,20 @@ use super::*;
|
|||||||
|
|
||||||
/// `font`: Configure the font.
|
/// `font`: Configure the font.
|
||||||
pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||||
let list = args.named(ctx, "family");
|
let families = args.all(ctx);
|
||||||
let size = args.named::<Linear>(ctx, "size");
|
let list = if families.is_empty() {
|
||||||
|
args.named(ctx, "family")
|
||||||
|
} else {
|
||||||
|
Some(FontDef(families))
|
||||||
|
};
|
||||||
|
|
||||||
|
let size = args.eat(ctx).or_else(|| args.named::<Linear>(ctx, "size"));
|
||||||
let style = args.named(ctx, "style");
|
let style = args.named(ctx, "style");
|
||||||
let weight = args.named(ctx, "weight");
|
let weight = args.named(ctx, "weight");
|
||||||
let stretch = args.named(ctx, "stretch");
|
let stretch = args.named(ctx, "stretch");
|
||||||
let top_edge = args.named(ctx, "top-edge");
|
let top_edge = args.named(ctx, "top-edge");
|
||||||
let bottom_edge = args.named(ctx, "bottom-edge");
|
let bottom_edge = args.named(ctx, "bottom-edge");
|
||||||
let color = args.named(ctx, "color");
|
let fill = args.named(ctx, "fill");
|
||||||
let serif = args.named(ctx, "serif");
|
let serif = args.named(ctx, "serif");
|
||||||
let sans_serif = args.named(ctx, "sans-serif");
|
let sans_serif = args.named(ctx, "sans-serif");
|
||||||
let monospace = args.named(ctx, "monospace");
|
let monospace = args.named(ctx, "monospace");
|
||||||
@ -50,8 +56,8 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
|||||||
font.bottom_edge = bottom_edge;
|
font.bottom_edge = bottom_edge;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(color) = color {
|
if let Some(fill) = fill {
|
||||||
font.fill = Fill::Color(color);
|
font.fill = Fill::Color(fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(FamilyDef(serif)) = &serif {
|
if let Some(FamilyDef(serif)) = &serif {
|
||||||
@ -229,19 +235,19 @@ fn line_impl(
|
|||||||
args: &mut FuncArgs,
|
args: &mut FuncArgs,
|
||||||
substate: fn(&mut FontState) -> &mut Option<Rc<LineState>>,
|
substate: fn(&mut FontState) -> &mut Option<Rc<LineState>>,
|
||||||
) -> Value {
|
) -> Value {
|
||||||
let color = args.named(ctx, "color");
|
let stroke = args.eat(ctx).or_else(|| args.named(ctx, "stroke"));
|
||||||
let position = args.named(ctx, "position");
|
let thickness = args.eat(ctx).or_else(|| args.named::<Linear>(ctx, "thickness"));
|
||||||
let strength = args.named::<Linear>(ctx, "strength");
|
let offset = args.named(ctx, "offset");
|
||||||
let extent = args.named(ctx, "extent").unwrap_or_default();
|
let extent = args.named(ctx, "extent").unwrap_or_default();
|
||||||
let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default();
|
let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default();
|
||||||
|
|
||||||
// Suppress any existing strikethrough if strength is explicitly zero.
|
// Suppress any existing strikethrough if strength is explicitly zero.
|
||||||
let state = strength.map_or(true, |s| !s.is_zero()).then(|| {
|
let state = thickness.map_or(true, |s| !s.is_zero()).then(|| {
|
||||||
Rc::new(LineState {
|
Rc::new(LineState {
|
||||||
strength,
|
stroke: stroke.map(Fill::Color),
|
||||||
position,
|
thickness,
|
||||||
|
offset,
|
||||||
extent,
|
extent,
|
||||||
fill: color.map(Fill::Color),
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 11 KiB |
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
// Test multiple wide calls in separate expressions.
|
// Test multiple wide calls in separate expressions.
|
||||||
#font!(color: eastern) - First
|
#font!(fill: eastern) - First
|
||||||
#font!(color: forest) - Second
|
#font!(fill: forest) - Second
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test in heading.
|
// Test in heading.
|
||||||
|
@ -30,7 +30,7 @@ Expanded by height.
|
|||||||
// Test relative sizing.
|
// Test relative sizing.
|
||||||
#rect(width: 100%, height: 50pt, fill: rgb("aaa"))[
|
#rect(width: 100%, height: 50pt, fill: rgb("aaa"))[
|
||||||
#align!(center, center)
|
#align!(center, center)
|
||||||
#font!(color: white)
|
#font!(fill: white)
|
||||||
#circle(radius: 10pt, fill: eastern)[A]
|
#circle(radius: 10pt, fill: eastern)[A]
|
||||||
#circle(height: 60%, fill: eastern)[B]
|
#circle(height: 60%, fill: eastern)[B]
|
||||||
#circle(width: 20% + 20pt, fill: eastern)[C]
|
#circle(width: 20% + 20pt, fill: eastern)[C]
|
||||||
|
@ -5,7 +5,7 @@ Auto-sized square. \
|
|||||||
#square(fill: eastern)[
|
#square(fill: eastern)[
|
||||||
#align!(center)
|
#align!(center)
|
||||||
#pad!(5pt)
|
#pad!(5pt)
|
||||||
#font!(color: white, weight: bold)
|
#font!(fill: white, weight: bold)
|
||||||
Typst
|
Typst
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
---
|
---
|
||||||
// Test reordering with different top-level paragraph directions.
|
// Test reordering with different top-level paragraph directions.
|
||||||
#let text = [Text טֶקסט]
|
#let text = [Text טֶקסט]
|
||||||
#font!(family: ("EB Garamond", "Noto Serif Hebrew"))
|
#font!("EB Garamond", "Noto Serif Hebrew")
|
||||||
#lang!("he") {text}
|
#lang!("he") {text}
|
||||||
#lang!("de") {text}
|
#lang!("de") {text}
|
||||||
|
|
||||||
@ -11,7 +11,7 @@
|
|||||||
// Test that consecutive, embedded LTR runs stay LTR.
|
// Test that consecutive, embedded LTR runs stay LTR.
|
||||||
// Here, we have two runs: "A" and italic "B".
|
// Here, we have two runs: "A" and italic "B".
|
||||||
#let text = [أنت A_B_مطرC]
|
#let text = [أنت A_B_مطرC]
|
||||||
#font!(family: ("EB Garamond", "Noto Sans Arabic"))
|
#font!("EB Garamond", "Noto Sans Arabic")
|
||||||
#lang!("ar") {text}
|
#lang!("ar") {text}
|
||||||
#lang!("de") {text}
|
#lang!("de") {text}
|
||||||
|
|
||||||
@ -19,32 +19,32 @@
|
|||||||
// Test that consecutive, embedded RTL runs stay RTL.
|
// Test that consecutive, embedded RTL runs stay RTL.
|
||||||
// Here, we have three runs: "גֶ", bold "שֶׁ", and "ם".
|
// Here, we have three runs: "גֶ", bold "שֶׁ", and "ם".
|
||||||
#let text = [Aגֶ*שֶׁ*םB]
|
#let text = [Aגֶ*שֶׁ*םB]
|
||||||
#font!(family: ("EB Garamond", "Noto Serif Hebrew"))
|
#font!("EB Garamond", "Noto Serif Hebrew")
|
||||||
#lang!("he") {text}
|
#lang!("he") {text}
|
||||||
#lang!("de") {text}
|
#lang!("de") {text}
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test embedding up to level 4 with isolates.
|
// Test embedding up to level 4 with isolates.
|
||||||
#font!(family: ("EB Garamond", "Noto Serif Hebrew", "Twitter Color Emoji"))
|
#font!("EB Garamond", "Noto Serif Hebrew", "Twitter Color Emoji")
|
||||||
#lang!(dir: rtl)
|
#lang!(dir: rtl)
|
||||||
א\u{2066}A\u{2067}Bב\u{2069}?
|
א\u{2066}A\u{2067}Bב\u{2069}?
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test hard line break (leads to two paragraphs in unicode-bidi).
|
// Test hard line break (leads to two paragraphs in unicode-bidi).
|
||||||
#font!(family: ("Noto Sans Arabic", "EB Garamond"))
|
#font!("Noto Sans Arabic", "EB Garamond")
|
||||||
#lang!("ar")
|
#lang!("ar")
|
||||||
Life المطر هو الحياة \
|
Life المطر هو الحياة \
|
||||||
الحياة تمطر is rain.
|
الحياة تمطر is rain.
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test spacing.
|
// Test spacing.
|
||||||
#font!(family: ("EB Garamond", "Noto Serif Hebrew"))
|
#font!("EB Garamond", "Noto Serif Hebrew")
|
||||||
L #h(1cm) ריווחR \
|
L #h(1cm) ריווחR \
|
||||||
Lריווח #h(1cm) R
|
Lריווח #h(1cm) R
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test inline object.
|
// Test inline object.
|
||||||
#font!(family: ("Noto Serif Hebrew", "EB Garamond"))
|
#font!("Noto Serif Hebrew", "EB Garamond")
|
||||||
#lang!("he")
|
#lang!("he")
|
||||||
קרנפיםRh#image("../../res/rhino.png", height: 11pt)inoחיים
|
קרנפיםRh#image("../../res/rhino.png", height: 11pt)inoחיים
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Test chinese text from Wikipedia.
|
// Test chinese text from Wikipedia.
|
||||||
|
|
||||||
---
|
---
|
||||||
#font!(family: "Noto Serif CJK SC")
|
#font!("Noto Serif CJK SC")
|
||||||
|
|
||||||
是美国广播公司电视剧《迷失》第3季的第22和23集,也是全剧的第71集和72集
|
是美国广播公司电视剧《迷失》第3季的第22和23集,也是全剧的第71集和72集
|
||||||
由执行制作人戴蒙·林道夫和卡尔顿·库斯编剧,导演则是另一名执行制作人杰克·本德
|
由执行制作人戴蒙·林道夫和卡尔顿·库斯编剧,导演则是另一名执行制作人杰克·本德
|
||||||
|
@ -3,14 +3,17 @@
|
|||||||
---
|
---
|
||||||
#strike[Statements dreamt up by the utterly deranged.]
|
#strike[Statements dreamt up by the utterly deranged.]
|
||||||
|
|
||||||
Sometimes, we work #strike(extent: 5%, strength: 10pt)[in secret]. There might
|
Sometimes, we work #strike(10pt, extent: 5%)[in secret].
|
||||||
be #strike(extent: 5%, strength: 10pt, color: rgb("abcdef88"))[redacted] things.
|
There might be #strike(stroke: rgb("abcdef88"), thickness: 10pt, extent: 5%)[redacted]
|
||||||
|
things.
|
||||||
|
|
||||||
|
#underline(offset: 5pt)[Further below.]
|
||||||
|
|
||||||
---
|
---
|
||||||
#underline(color: rgb("fc0030"))[Critical information is conveyed here.]
|
#underline(rgb("fc0030"))[Critical information is conveyed here.]
|
||||||
#underline[Still important, but not #underline(strength: 0pt)[mission ]critical.]
|
#underline[Still important, but not #underline(0pt)[mission ]critical.]
|
||||||
|
|
||||||
#font(color: rgb("fc0030"), underline[Change with the wind.])
|
#font(fill: rgb("fc0030"), underline[Change with the wind.])
|
||||||
|
|
||||||
---
|
---
|
||||||
#overline(underline[Running amongst the wolves.])
|
#overline(underline[Running amongst the wolves.])
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
// Set same font size in three different ways.
|
// Set same font size in three different ways.
|
||||||
#font(size: 22pt)[A]
|
#font(22pt)[A]
|
||||||
#font(size: 200%)[A]
|
#font(200%)[A]
|
||||||
#font(size: 16.5pt + 50%)[A]
|
#font(size: 16.5pt + 50%)[A]
|
||||||
|
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
@ -25,12 +25,12 @@
|
|||||||
Emoji: 🐪, 🌋, 🏞
|
Emoji: 🐪, 🌋, 🏞
|
||||||
|
|
||||||
// Math.
|
// Math.
|
||||||
#font(family: "Latin Modern Math")[
|
#font("Latin Modern Math")[
|
||||||
∫ 𝛼 + 3𝛽 d𝑡
|
∫ 𝛼 + 3𝛽 d𝑡
|
||||||
]
|
]
|
||||||
|
|
||||||
// Colors.
|
// Colors.
|
||||||
#font(color: eastern)[This is #font(color: rgb("FA644B"))[way more] colorful.]
|
#font(fill: eastern)[This is #font(fill: rgb("FA644B"))[way more] colorful.]
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test top and bottom edge.
|
// Test top and bottom edge.
|
||||||
@ -50,8 +50,8 @@ Emoji: 🐪, 🌋, 🏞
|
|||||||
// Test class definitions.
|
// Test class definitions.
|
||||||
#font!(sans-serif: "PT Sans")
|
#font!(sans-serif: "PT Sans")
|
||||||
#font(family: sans-serif)[Sans-serif.] \
|
#font(family: sans-serif)[Sans-serif.] \
|
||||||
#font(family: monospace)[Monospace.] \
|
#font(monospace)[Monospace.] \
|
||||||
#font(family: monospace, monospace: ("Nope", "Latin Modern Math"))[Math.]
|
#font(monospace, monospace: ("Nope", "Latin Modern Math"))[Math.]
|
||||||
|
|
||||||
---
|
---
|
||||||
// Ref: false
|
// Ref: false
|
||||||
@ -72,3 +72,9 @@ Emoji: 🐪, 🌋, 🏞
|
|||||||
|
|
||||||
// Error: 7-27 unexpected argument
|
// Error: 7-27 unexpected argument
|
||||||
#font(something: "invalid")[]
|
#font(something: "invalid")[]
|
||||||
|
|
||||||
|
// Error: 13-23 unexpected argument
|
||||||
|
#font(12pt, size: 10pt)[]
|
||||||
|
|
||||||
|
// Error: 16-35 unexpected argument
|
||||||
|
#font("Arial", family: "Helvetica")[]
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
Le fira
|
Le fira
|
||||||
|
|
||||||
// This should just shape nicely.
|
// This should just shape nicely.
|
||||||
#font!(family: "Noto Sans Arabic")
|
#font!("Noto Sans Arabic")
|
||||||
دع النص يمطر عليك
|
دع النص يمطر عليك
|
||||||
|
|
||||||
// This should form a three-member family.
|
// This should form a three-member family.
|
||||||
#font!(family: "Twitter Color Emoji")
|
#font!("Twitter Color Emoji")
|
||||||
👩👩👦 🤚🏿
|
👩👩👦 🤚🏿
|
||||||
|
|
||||||
// These two shouldn't be affected by a zero-width joiner.
|
// These two shouldn't be affected by a zero-width joiner.
|
||||||
@ -20,7 +20,7 @@ Le fira
|
|||||||
---
|
---
|
||||||
// Test font fallback.
|
// Test font fallback.
|
||||||
|
|
||||||
#font!(family: ("EB Garamond", "Noto Sans Arabic", "Twitter Color Emoji"))
|
#font!("EB Garamond", "Noto Sans Arabic", "Twitter Color Emoji")
|
||||||
|
|
||||||
// Font fallback for emoji.
|
// Font fallback for emoji.
|
||||||
A😀B
|
A😀B
|
||||||
@ -40,6 +40,6 @@ A🐈中文B
|
|||||||
---
|
---
|
||||||
// Test reshaping.
|
// Test reshaping.
|
||||||
|
|
||||||
#font!(family: "Noto Serif Hebrew")
|
#font!("Noto Serif Hebrew")
|
||||||
#lang!("he")
|
#lang!("he")
|
||||||
ס \ טֶ
|
ס \ טֶ
|
||||||
|
@ -36,11 +36,11 @@ A #for _ in (none,) {"B"}C
|
|||||||
|
|
||||||
---
|
---
|
||||||
// Test that a run consisting only of whitespace isn't trimmed.
|
// Test that a run consisting only of whitespace isn't trimmed.
|
||||||
A#font(family: "PT Sans")[ ]B
|
A#font("PT Sans")[ ]B
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test font change after space.
|
// Test font change after space.
|
||||||
Left #font(family: "PT Sans")[Right].
|
Left #font("PT Sans")[Right].
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test that space at start of line is not trimmed.
|
// Test that space at start of line is not trimmed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user