mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Default to Relation instead of Fence
This commit is contained in:
parent
1025419b5a
commit
337080445f
@ -45,12 +45,26 @@ pub fn layout_lr(
|
|||||||
|
|
||||||
// Scale up fragments at both ends.
|
// Scale up fragments at both ends.
|
||||||
match inner_fragments {
|
match inner_fragments {
|
||||||
[one] => scale(ctx, styles, one, relative_to, height, None),
|
[one] => scale_if_delimiter(ctx, styles, one, relative_to, height, None),
|
||||||
[first, .., last] => {
|
[first, .., last] => {
|
||||||
scale(ctx, styles, first, relative_to, height, Some(MathClass::Opening));
|
scale_if_delimiter(
|
||||||
scale(ctx, styles, last, relative_to, height, Some(MathClass::Closing));
|
ctx,
|
||||||
|
styles,
|
||||||
|
first,
|
||||||
|
relative_to,
|
||||||
|
height,
|
||||||
|
Some(MathClass::Opening),
|
||||||
|
);
|
||||||
|
scale_if_delimiter(
|
||||||
|
ctx,
|
||||||
|
styles,
|
||||||
|
last,
|
||||||
|
relative_to,
|
||||||
|
height,
|
||||||
|
Some(MathClass::Closing),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => {}
|
[] => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle MathFragment::Variant fragments that should be scaled up.
|
// Handle MathFragment::Variant fragments that should be scaled up.
|
||||||
@ -58,7 +72,7 @@ pub fn layout_lr(
|
|||||||
if let MathFragment::Variant(ref mut variant) = fragment {
|
if let MathFragment::Variant(ref mut variant) = fragment {
|
||||||
if variant.mid_stretched == Some(false) {
|
if variant.mid_stretched == Some(false) {
|
||||||
variant.mid_stretched = Some(true);
|
variant.mid_stretched = Some(true);
|
||||||
scale(ctx, styles, fragment, relative_to, height, None);
|
scale(ctx, styles, fragment, relative_to, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,12 +113,12 @@ pub fn layout_mid(
|
|||||||
MathFragment::Glyph(glyph) => {
|
MathFragment::Glyph(glyph) => {
|
||||||
let mut new = glyph.clone().into_variant();
|
let mut new = glyph.clone().into_variant();
|
||||||
new.mid_stretched = Some(false);
|
new.mid_stretched = Some(false);
|
||||||
new.class = MathClass::Fence;
|
new.class = MathClass::Relation;
|
||||||
*fragment = MathFragment::Variant(new);
|
*fragment = MathFragment::Variant(new);
|
||||||
}
|
}
|
||||||
MathFragment::Variant(variant) => {
|
MathFragment::Variant(variant) => {
|
||||||
variant.mid_stretched = Some(false);
|
variant.mid_stretched = Some(false);
|
||||||
variant.class = MathClass::Fence;
|
variant.class = MathClass::Relation;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -114,8 +128,12 @@ pub fn layout_mid(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scale a math fragment to a height.
|
/// Scales a math fragment to a height if it has the class Opening, Closing, or
|
||||||
fn scale(
|
/// Fence.
|
||||||
|
///
|
||||||
|
/// In case `apply` is `Some(class)`, `class` will be applied to the fragment if
|
||||||
|
/// it is a delimiter, in a way that cannot be overridden by the user.
|
||||||
|
fn scale_if_delimiter(
|
||||||
ctx: &mut MathContext,
|
ctx: &mut MathContext,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
fragment: &mut MathFragment,
|
fragment: &mut MathFragment,
|
||||||
@ -127,21 +145,32 @@ fn scale(
|
|||||||
fragment.class(),
|
fragment.class(),
|
||||||
MathClass::Opening | MathClass::Closing | MathClass::Fence
|
MathClass::Opening | MathClass::Closing | MathClass::Fence
|
||||||
) {
|
) {
|
||||||
// This unwrap doesn't really matter. If it is None, then the fragment
|
scale(ctx, styles, fragment, relative_to, height);
|
||||||
// won't be stretchable anyways.
|
|
||||||
let short_fall = DELIM_SHORT_FALL.at(fragment.font_size().unwrap_or_default());
|
|
||||||
stretch_fragment(
|
|
||||||
ctx,
|
|
||||||
styles,
|
|
||||||
fragment,
|
|
||||||
Some(Axis::Y),
|
|
||||||
Some(relative_to),
|
|
||||||
height,
|
|
||||||
short_fall,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(class) = apply {
|
if let Some(class) = apply {
|
||||||
fragment.set_class(class);
|
fragment.set_class(class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Scales a math fragment to a height.
|
||||||
|
fn scale(
|
||||||
|
ctx: &mut MathContext,
|
||||||
|
styles: StyleChain,
|
||||||
|
fragment: &mut MathFragment,
|
||||||
|
relative_to: Abs,
|
||||||
|
height: Rel<Abs>,
|
||||||
|
) {
|
||||||
|
// This unwrap doesn't really matter. If it is None, then the fragment
|
||||||
|
// won't be stretchable anyways.
|
||||||
|
let short_fall = DELIM_SHORT_FALL.at(fragment.font_size().unwrap_or_default());
|
||||||
|
stretch_fragment(
|
||||||
|
ctx,
|
||||||
|
styles,
|
||||||
|
fragment,
|
||||||
|
Some(Axis::Y),
|
||||||
|
Some(relative_to),
|
||||||
|
height,
|
||||||
|
short_fall,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 406 B |
@ -78,17 +78,10 @@ $ lr(body) quad
|
|||||||
lr(size: #(1em+20%), body) $
|
lr(size: #(1em+20%), body) $
|
||||||
|
|
||||||
--- math-lr-mid-class ---
|
--- math-lr-mid-class ---
|
||||||
// Test that `mid` keeps the original class.
|
// Test that `mid` creates a Relation, but that can be overridden.
|
||||||
$ (a |b) $
|
$ (a | b) $
|
||||||
$ (a mid(|)b) $
|
$ (a mid(|) b) $
|
||||||
--
|
$ (a class("unary", |) b) $
|
||||||
$ (a class("fence", |)b) $
|
|
||||||
$ (a mid(class("fence", |))b) $
|
|
||||||
$ (a class("fence", mid(|))b) $
|
|
||||||
--
|
|
||||||
$ (a class("binary", |)b) $
|
|
||||||
$ (a mid(class("binary", |))b) $
|
|
||||||
$ (a class("binary", mid(|))b) $
|
|
||||||
|
|
||||||
--- math-lr-unbalanced ---
|
--- math-lr-unbalanced ---
|
||||||
// Test unbalanced delimiters.
|
// Test unbalanced delimiters.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user