summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/math
diff options
context:
space:
mode:
authorEric Biedert <github@ericbiedert.de>2023-09-18 14:51:34 +0200
committerGitHub <noreply@github.com>2023-09-18 14:51:34 +0200
commitb10f9ae7b7f5a15c797441d4d67ea69d2ab9b617 (patch)
tree61a2851dbc9656a633b893d0daed1f381465d900 /crates/typst-library/src/math
parente55348dbc090b797a94fe69fc87d45c6de92d97f (diff)
Fix "set align" for block equations (#2157)
Diffstat (limited to 'crates/typst-library/src/math')
-rw-r--r--crates/typst-library/src/math/mod.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs
index 3ae3f23a..df3beb7f 100644
--- a/crates/typst-library/src/math/mod.rs
+++ b/crates/typst-library/src/math/mod.rs
@@ -43,7 +43,7 @@ use self::ctx::*;
use self::fragment::*;
use self::row::*;
use self::spacing::*;
-use crate::layout::{BoxElem, HElem, ParElem, Spacing};
+use crate::layout::{AlignElem, BoxElem, HElem, ParElem, Spacing};
use crate::meta::Supplement;
use crate::meta::{
Count, Counter, CounterUpdate, LocalName, Numbering, Outlinable, Refable,
@@ -200,14 +200,18 @@ impl Show for EquationElem {
fn show(&self, _: &mut Vt, styles: StyleChain) -> SourceResult<Content> {
let mut realized = self.clone().pack().guarded(Guard::Base(Self::elem()));
if self.block(styles) {
- realized = realized.aligned(Align::CENTER);
+ realized = AlignElem::new(realized).pack();
}
Ok(realized)
}
}
impl Finalize for EquationElem {
- fn finalize(&self, realized: Content, _: StyleChain) -> Content {
+ fn finalize(&self, realized: Content, style: StyleChain) -> Content {
+ let mut realized = realized;
+ if self.block(style) {
+ realized = realized.styled(AlignElem::set_alignment(Align::CENTER));
+ }
realized
.styled(TextElem::set_weight(FontWeight::from_number(450)))
.styled(TextElem::set_font(FontList(vec![FontFamily::new(
@@ -251,17 +255,26 @@ impl Layout for EquationElem {
.layout(vt, styles, pod)?
.into_frame();
+ let full_counter_width = counter.width() + NUMBER_GUTTER.resolve(styles);
let width = if regions.size.x.is_finite() {
regions.size.x
} else {
- frame.width()
- + 2.0 * (counter.width() + NUMBER_GUTTER.resolve(styles))
+ frame.width() + 2.0 * full_counter_width
};
let height = frame.height().max(counter.height());
- frame.resize(Size::new(width, height), Axes::splat(FixedAlign::Center));
+ let align = AlignElem::alignment_in(styles).resolve(styles).x;
+ frame.resize(Size::new(width, height), Axes::splat(align));
+
+ let dir = TextElem::dir_in(styles);
+ let offset = match (align, dir) {
+ (FixedAlign::Start, Dir::RTL) => full_counter_width,
+ (FixedAlign::End, Dir::LTR) => -full_counter_width,
+ _ => Abs::zero(),
+ };
+ frame.translate(Point::with_x(offset));
- let x = if TextElem::dir_in(styles).is_positive() {
+ let x = if dir.is_positive() {
frame.width() - counter.width()
} else {
Abs::zero()