Center delimiters vertically about the axis (#1756)
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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(())
|
||||
|
@ -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");
|
||||
};
|
||||
|
||||
|
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 |