-
-
Notifications
You must be signed in to change notification settings - Fork 793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An AlignPointElem
has a non-zero height
#4187
Comments
This is because in In a line with |
I think ascent and descent should be clamped to zero there. |
Clamping to zero may lead to unintended results, because a glyph's lowest point could indeed be higher than the baseline, and therefore having a negative descent. For example, if pub fn descent(&self) -> Abs {
self.iter()
- .map(MathFragment::descent)
+ .map(|e| e.descent().max(Abs::zero()))
.max()
.unwrap_or_default()
} |
Instead, I suggest this change below (all tests passing). The idea is that some diff --git a/crates/typst/src/math/fragment.rs b/crates/typst/src/math/fragment.rs
index ef865b38..596c3c16 100644
--- a/crates/typst/src/math/fragment.rs
+++ b/crates/typst/src/math/fragment.rs
@@ -139,6 +139,10 @@ impl MathFragment {
}
}
+ pub fn is_shapeless(&self) -> bool {
+ matches!(self, MathFragment::Align | MathFragment::Linebreak)
+ }
+
pub fn italics_correction(&self) -> Abs {
match self {
Self::Glyph(glyph) => glyph.italics_correction,
diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs
index 6454f491..6577abf5 100644
--- a/crates/typst/src/math/row.rs
+++ b/crates/typst/src/math/row.rs
@@ -117,11 +117,17 @@ impl MathRun {
}
pub fn ascent(&self) -> Abs {
- self.iter().map(MathFragment::ascent).max().unwrap_or_default()
+ self.iter()
+ .filter_map(|e| (!e.is_shapeless()).then(|| e.ascent()))
+ .max()
+ .unwrap_or_default()
}
pub fn descent(&self) -> Abs {
- self.iter().map(MathFragment::descent).max().unwrap_or_default()
+ self.iter()
+ .filter_map(|e| (!e.is_shapeless()).then(|| e.descent()))
+ .max()
+ .unwrap_or_default()
} Edit: Alternatively, following the same idea of control fragments being "shapeless"/"sizeless", a better change is letting |
Description
A line of
- -
should have a very small height, as shown in the left two boxes' rendering; but after inserting&
to this line, the line gains a visible height, as shown in the right two boxes.However, the height of a
MathFragment::Align
(inserted byimpl LayoutMath for Packed<AlignPointElem>
) is supposed to be zero, according totypst/crates/typst/src/math/fragment.rs
Lines 45 to 52 in 4f8bbb0
Reproduction URL
No response
Operating system
Web app, Linux
Typst version
The text was updated successfully, but these errors were encountered: