Do not force math.mid
elements to have the Large math class (#5980)
@ -45,12 +45,12 @@ 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, one, relative_to, height, None),
|
[one] => scale_if_delimiter(ctx, one, relative_to, height, None),
|
||||||
[first, .., last] => {
|
[first, .., last] => {
|
||||||
scale(ctx, first, relative_to, height, Some(MathClass::Opening));
|
scale_if_delimiter(ctx, first, relative_to, height, Some(MathClass::Opening));
|
||||||
scale(ctx, last, relative_to, height, Some(MathClass::Closing));
|
scale_if_delimiter(ctx, last, relative_to, height, Some(MathClass::Closing));
|
||||||
}
|
}
|
||||||
_ => {}
|
[] => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle MathFragment::Glyph fragments that should be scaled up.
|
// Handle MathFragment::Glyph fragments that should be scaled up.
|
||||||
@ -58,7 +58,7 @@ pub fn layout_lr(
|
|||||||
if let MathFragment::Glyph(ref mut glyph) = fragment {
|
if let MathFragment::Glyph(ref mut glyph) = fragment {
|
||||||
if glyph.mid_stretched == Some(false) {
|
if glyph.mid_stretched == Some(false) {
|
||||||
glyph.mid_stretched = Some(true);
|
glyph.mid_stretched = Some(true);
|
||||||
scale(ctx, fragment, relative_to, height, Some(MathClass::Large));
|
scale(ctx, fragment, relative_to, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ pub fn layout_mid(
|
|||||||
for fragment in &mut fragments {
|
for fragment in &mut fragments {
|
||||||
if let MathFragment::Glyph(ref mut glyph) = fragment {
|
if let MathFragment::Glyph(ref mut glyph) = fragment {
|
||||||
glyph.mid_stretched = Some(false);
|
glyph.mid_stretched = Some(false);
|
||||||
glyph.class = MathClass::Fence;
|
glyph.class = MathClass::Relation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,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,
|
||||||
fragment: &mut MathFragment,
|
fragment: &mut MathFragment,
|
||||||
relative_to: Abs,
|
relative_to: Abs,
|
||||||
@ -117,20 +121,23 @@ 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, 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,
|
|
||||||
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,
|
||||||
|
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, fragment, Some(Axis::Y), Some(relative_to), height, short_fall);
|
||||||
|
}
|
||||||
|
BIN
tests/ref/math-lr-mid-class.png
Normal file
After Width: | Height: | Size: 556 B |
Before Width: | Height: | Size: 900 B After Width: | Height: | Size: 920 B |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
@ -77,6 +77,14 @@ $ lr(body) quad
|
|||||||
lr(size: #1em, body) quad
|
lr(size: #1em, body) quad
|
||||||
lr(size: #(1em+20%), body) $
|
lr(size: #(1em+20%), body) $
|
||||||
|
|
||||||
|
--- math-lr-mid-class ---
|
||||||
|
// Test that `mid` creates a Relation, but that can be overridden.
|
||||||
|
$ (a | b) $
|
||||||
|
$ (a mid(|) b) $
|
||||||
|
$ (a class("unary", |) b) $
|
||||||
|
$ (a class("unary", mid(|)) b) $
|
||||||
|
$ (a mid(class("unary", |)) b) $
|
||||||
|
|
||||||
--- math-lr-unbalanced ---
|
--- math-lr-unbalanced ---
|
||||||
// Test unbalanced delimiters.
|
// Test unbalanced delimiters.
|
||||||
$ 1/(2 (x) $
|
$ 1/(2 (x) $
|
||||||
|