Center delimiters vertically about the axis (#1756)
@ -185,8 +185,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
|
|||||||
glyph.into_variant()
|
glyph.into_variant()
|
||||||
};
|
};
|
||||||
// TeXbook p 155. Large operators are always vertically centered on the axis.
|
// TeXbook p 155. Large operators are always vertically centered on the axis.
|
||||||
let h = variant.frame.height();
|
variant.center_on_axis(self);
|
||||||
variant.frame.set_baseline(h / 2.0 + scaled!(self, axis_height));
|
|
||||||
variant.into()
|
variant.into()
|
||||||
} else {
|
} else {
|
||||||
glyph.into()
|
glyph.into()
|
||||||
|
@ -95,9 +95,10 @@ fn scale(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let short_fall = DELIM_SHORT_FALL.scaled(ctx);
|
let short_fall = DELIM_SHORT_FALL.scaled(ctx);
|
||||||
*fragment =
|
let mut stretched = glyph.stretch_vertical(ctx, height, short_fall);
|
||||||
MathFragment::Variant(glyph.stretch_vertical(ctx, height, short_fall));
|
stretched.center_on_axis(ctx);
|
||||||
|
|
||||||
|
*fragment = MathFragment::Variant(stretched);
|
||||||
if let Some(class) = apply {
|
if let Some(class) = apply {
|
||||||
fragment.set_class(class);
|
fragment.set_class(class);
|
||||||
}
|
}
|
||||||
|
@ -122,13 +122,15 @@ fn layout(
|
|||||||
frame.push_frame(denom_pos, denom);
|
frame.push_frame(denom_pos, denom);
|
||||||
|
|
||||||
if binom {
|
if binom {
|
||||||
ctx.push(
|
let mut left =
|
||||||
GlyphFragment::new(ctx, '(', span).stretch_vertical(ctx, height, short_fall),
|
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(FrameFragment::new(ctx, frame));
|
||||||
ctx.push(
|
let mut right =
|
||||||
GlyphFragment::new(ctx, ')', span).stretch_vertical(ctx, height, short_fall),
|
GlyphFragment::new(ctx, ')', span).stretch_vertical(ctx, height, short_fall);
|
||||||
);
|
right.center_on_axis(ctx);
|
||||||
|
ctx.push(right);
|
||||||
} else {
|
} else {
|
||||||
frame.push(
|
frame.push(
|
||||||
line_pos,
|
line_pos,
|
||||||
|
@ -353,6 +353,15 @@ pub struct VariantFragment {
|
|||||||
pub limits: Limits,
|
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 {
|
impl Debug for VariantFragment {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "VariantFragment({:?})", self.c)
|
write!(f, "VariantFragment({:?})", self.c)
|
||||||
|
@ -295,18 +295,19 @@ fn layout_delimiters(
|
|||||||
frame.set_baseline(height / 2.0 + axis);
|
frame.set_baseline(height / 2.0 + axis);
|
||||||
|
|
||||||
if let Some(left) = left {
|
if let Some(left) = left {
|
||||||
ctx.push(
|
let mut left =
|
||||||
GlyphFragment::new(ctx, left, span).stretch_vertical(ctx, target, short_fall),
|
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));
|
ctx.push(FrameFragment::new(ctx, frame));
|
||||||
|
|
||||||
if let Some(right) = right {
|
if let Some(right) = right {
|
||||||
ctx.push(
|
let mut right = GlyphFragment::new(ctx, right, span)
|
||||||
GlyphFragment::new(ctx, right, span)
|
.stretch_vertical(ctx, target, short_fall);
|
||||||
.stretch_vertical(ctx, target, short_fall),
|
right.center_on_axis(ctx);
|
||||||
);
|
ctx.push(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -48,6 +48,7 @@ fn prepare(stream: TokenStream, item: &syn::ItemFn) -> Result<Func> {
|
|||||||
let mut params = vec![];
|
let mut params = vec![];
|
||||||
for input in &sig.inputs {
|
for input in &sig.inputs {
|
||||||
let syn::FnArg::Typed(typed) = input else {
|
let syn::FnArg::Typed(typed) = input else {
|
||||||
|
println!("option a");
|
||||||
bail!(input, "self is not allowed here");
|
bail!(input, "self is not allowed here");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |