mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Configurable paragraph alignment
This commit is contained in:
parent
095fa52be5
commit
d9c529347d
@ -15,17 +15,26 @@ pub fn par(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
let spacing = args.named("spacing")?;
|
let spacing = args.named("spacing")?;
|
||||||
let leading = args.named("leading")?;
|
let leading = args.named("leading")?;
|
||||||
|
|
||||||
let mut dir = args.named::<EcoString>("lang")?.map(|iso| {
|
let mut dir =
|
||||||
match iso.to_ascii_lowercase().as_str() {
|
args.named("lang")?
|
||||||
"ar" | "he" | "fa" | "ur" | "ps" | "yi" => Dir::RTL,
|
.map(|iso: EcoString| match iso.to_lowercase().as_str() {
|
||||||
"en" | "fr" | "de" => Dir::LTR,
|
"ar" | "he" | "fa" | "ur" | "ps" | "yi" => Dir::RTL,
|
||||||
_ => Dir::LTR,
|
"en" | "fr" | "de" => Dir::LTR,
|
||||||
}
|
_ => Dir::LTR,
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(Spanned { v, span }) = args.named::<Spanned<Dir>>("dir")? {
|
if let Some(Spanned { v, span }) = args.named::<Spanned<Dir>>("dir")? {
|
||||||
if v.axis() == SpecAxis::Horizontal {
|
if v.axis() == SpecAxis::Horizontal {
|
||||||
dir = Some(v)
|
dir = Some(v);
|
||||||
|
} else {
|
||||||
|
bail!(span, "must be horizontal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut align = None;
|
||||||
|
if let Some(Spanned { v, span }) = args.named::<Spanned<Align>>("align")? {
|
||||||
|
if matches!(v.axis(), None | Some(SpecAxis::Horizontal)) {
|
||||||
|
align = Some(v);
|
||||||
} else {
|
} else {
|
||||||
bail!(span, "must be horizontal");
|
bail!(span, "must be horizontal");
|
||||||
}
|
}
|
||||||
@ -39,6 +48,10 @@ pub fn par(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
|||||||
par.align = if dir == Dir::LTR { Align::Left } else { Align::Right };
|
par.align = if dir == Dir::LTR { Align::Left } else { Align::Right };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(align) = align {
|
||||||
|
par.align = align;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(leading) = leading {
|
if let Some(leading) = leading {
|
||||||
par.leading = leading;
|
par.leading = leading;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 5.6 KiB |
@ -1,8 +1,17 @@
|
|||||||
// Test configuring paragraph properties.
|
// Test configuring paragraph properties.
|
||||||
|
|
||||||
---
|
---
|
||||||
#par(spacing: 100%, leading: 0pt)
|
// Test ragged-left.
|
||||||
|
#par(align: right)
|
||||||
|
To the right! Where the sunlight peeks behind the mountain.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test weird metrics.
|
||||||
|
#par(spacing: 100%, leading: 0pt)
|
||||||
But, soft! what light through yonder window breaks?
|
But, soft! what light through yonder window breaks?
|
||||||
|
|
||||||
It is the east, and Juliet is the sun.
|
It is the east, and Juliet is the sun.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Error: 13-16 must be horizontal
|
||||||
|
#par(align: top)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user