mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Fix panic in attachment layout
This commit is contained in:
parent
017027bf39
commit
3eb1f31e90
@ -57,25 +57,24 @@ impl LayoutMath for AttachElem {
|
|||||||
#[tracing::instrument(skip(ctx))]
|
#[tracing::instrument(skip(ctx))]
|
||||||
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
|
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
|
||||||
type GetAttachment = fn(&AttachElem, styles: StyleChain) -> Option<Content>;
|
type GetAttachment = fn(&AttachElem, styles: StyleChain) -> Option<Content>;
|
||||||
let getarg = |ctx: &mut MathContext, getter: GetAttachment| {
|
let layout_attachment = |ctx: &mut MathContext, getter: GetAttachment| {
|
||||||
getter(self, ctx.styles())
|
getter(self, ctx.styles())
|
||||||
.map(|elem| ctx.layout_fragment(&elem))
|
.map(|elem| ctx.layout_fragment(&elem))
|
||||||
.transpose()
|
.transpose()
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let base = ctx.layout_fragment(&self.base())?;
|
let base = ctx.layout_fragment(&self.base())?;
|
||||||
|
|
||||||
ctx.style(ctx.style.for_superscript());
|
ctx.style(ctx.style.for_superscript());
|
||||||
let arg_tl = getarg(ctx, Self::tl);
|
let tl = layout_attachment(ctx, Self::tl)?;
|
||||||
let arg_tr = getarg(ctx, Self::tr);
|
let tr = layout_attachment(ctx, Self::tr)?;
|
||||||
let arg_t = getarg(ctx, Self::t);
|
let t = layout_attachment(ctx, Self::t)?;
|
||||||
ctx.unstyle();
|
ctx.unstyle();
|
||||||
|
|
||||||
ctx.style(ctx.style.for_subscript());
|
ctx.style(ctx.style.for_subscript());
|
||||||
let arg_bl = getarg(ctx, Self::bl);
|
let bl = layout_attachment(ctx, Self::bl)?;
|
||||||
let arg_br = getarg(ctx, Self::br);
|
let br = layout_attachment(ctx, Self::br)?;
|
||||||
let arg_b = getarg(ctx, Self::b);
|
let b = layout_attachment(ctx, Self::b)?;
|
||||||
ctx.unstyle();
|
ctx.unstyle();
|
||||||
|
|
||||||
let as_limits = self.base().is::<LimitsElem>()
|
let as_limits = self.base().is::<LimitsElem>()
|
||||||
@ -88,12 +87,9 @@ impl LayoutMath for AttachElem {
|
|||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let (t, tr) =
|
let (t, tr) = if as_limits || tr.is_some() { (t, tr) } else { (None, t) };
|
||||||
if as_limits || arg_tr.is_some() { (arg_t, arg_tr) } else { (None, arg_t) };
|
let (b, br) = if as_limits || br.is_some() { (b, br) } else { (None, b) };
|
||||||
let (b, br) =
|
layout_attachments(ctx, base, [tl, t, tr, bl, b, br])
|
||||||
if as_limits || arg_br.is_some() { (arg_b, arg_br) } else { (None, arg_b) };
|
|
||||||
|
|
||||||
layout_attachments(ctx, base, [arg_tl, t, tr, arg_bl, b, br])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user