Center delimiters vertically about the axis (#1756)

This commit is contained in:
damaxwell 2023-07-20 02:50:12 -08:00 committed by GitHub
parent 6a396ae214
commit c72952b512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 30 additions and 17 deletions

View File

@ -185,8 +185,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
glyph.into_variant()
};
// TeXbook p 155. Large operators are always vertically centered on the axis.
let h = variant.frame.height();
variant.frame.set_baseline(h / 2.0 + scaled!(self, axis_height));
variant.center_on_axis(self);
variant.into()
} else {
glyph.into()

View File

@ -95,9 +95,10 @@ fn scale(
};
let short_fall = DELIM_SHORT_FALL.scaled(ctx);
*fragment =
MathFragment::Variant(glyph.stretch_vertical(ctx, height, short_fall));
let mut stretched = glyph.stretch_vertical(ctx, height, short_fall);
stretched.center_on_axis(ctx);
*fragment = MathFragment::Variant(stretched);
if let Some(class) = apply {
fragment.set_class(class);
}

View File

@ -122,13 +122,15 @@ fn layout(
frame.push_frame(denom_pos, denom);
if binom {
ctx.push(
GlyphFragment::new(ctx, '(', span).stretch_vertical(ctx, height, short_fall),
);
let mut left =
GlyphFragment::new(ctx, '(', span).stretch_vertical(ctx, height, short_fall);
left.center_on_axis(ctx);
ctx.push(left);
ctx.push(FrameFragment::new(ctx, frame));
ctx.push(
GlyphFragment::new(ctx, ')', span).stretch_vertical(ctx, height, short_fall),
);
let mut right =
GlyphFragment::new(ctx, ')', span).stretch_vertical(ctx, height, short_fall);
right.center_on_axis(ctx);
ctx.push(right);
} else {
frame.push(
line_pos,

View File

@ -353,6 +353,15 @@ pub struct VariantFragment {
pub limits: Limits,
}
impl VariantFragment {
/// Vertically adjust the fragment's frame so that it is centered
/// on the axis.
pub fn center_on_axis(&mut self, ctx: &MathContext) {
let h = self.frame.height();
self.frame.set_baseline(h / 2.0 + scaled!(ctx, axis_height));
}
}
impl Debug for VariantFragment {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "VariantFragment({:?})", self.c)

View File

@ -295,18 +295,19 @@ fn layout_delimiters(
frame.set_baseline(height / 2.0 + axis);
if let Some(left) = left {
ctx.push(
GlyphFragment::new(ctx, left, span).stretch_vertical(ctx, target, short_fall),
);
let mut left =
GlyphFragment::new(ctx, left, span).stretch_vertical(ctx, target, short_fall);
left.center_on_axis(ctx);
ctx.push(left);
}
ctx.push(FrameFragment::new(ctx, frame));
if let Some(right) = right {
ctx.push(
GlyphFragment::new(ctx, right, span)
.stretch_vertical(ctx, target, short_fall),
);
let mut right = GlyphFragment::new(ctx, right, span)
.stretch_vertical(ctx, target, short_fall);
right.center_on_axis(ctx);
ctx.push(right);
}
Ok(())

View File

@ -48,6 +48,7 @@ fn prepare(stream: TokenStream, item: &syn::ItemFn) -> Result<Func> {
let mut params = vec![];
for input in &sig.inputs {
let syn::FnArg::Typed(typed) = input else {
println!("option a");
bail!(input, "self is not allowed here");
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB