Fix inline math formula frame size

This commit is contained in:
Laurenz 2022-06-13 14:06:41 +02:00
parent 7660978ee5
commit 2fe549c1ec
6 changed files with 19 additions and 9 deletions

View File

@ -43,6 +43,12 @@ impl RawAlign {
}
}
impl From<Align> for RawAlign {
fn from(align: Align) -> Self {
Self::Specific(align)
}
}
impl Debug for RawAlign {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {

View File

@ -56,7 +56,7 @@ impl Show for MathNode {
};
Ok(if self.display {
Content::block(node)
Content::block(node.pack().aligned(Spec::with_x(Some(Align::Center.into()))))
} else {
Content::inline(node)
})

View File

@ -58,19 +58,24 @@ impl Layout for RexNode {
// Determine the metrics.
let (x0, y0, x1, y1) = renderer.size(&layout);
let width = Length::pt(x1 - x0);
let height = Length::pt(y1 - y0);
let size = Size::new(width, height);
let baseline = Length::pt(y1);
let mut top = Length::pt(y1);
let mut bottom = Length::pt(-y0);
if !self.display {
let metrics = face.metrics();
top = styles.get(TextNode::TOP_EDGE).resolve(styles, metrics);
bottom = -styles.get(TextNode::BOTTOM_EDGE).resolve(styles, metrics);
};
// Prepare a frame rendering backend.
let size = Size::new(width, top + bottom);
let mut backend = FrameBackend {
frame: {
let mut frame = Frame::new(size);
frame.set_baseline(baseline);
frame.set_baseline(top);
frame.apply_role(Role::Formula);
frame
},
baseline,
baseline: top,
face_id,
fill: styles.get(TextNode::FILL),
lang: styles.get(TextNode::LANG),

View File

@ -19,10 +19,9 @@ use crate::Context;
/// A node that can be layouted into a sequence of regions.
///
/// Layout return one frame per used region alongside constraints that define
/// whether the result is reusable in other regions.
/// Layouting return one frame per used region.
pub trait Layout: 'static {
/// Layout this node into the given regions, producing constrained frames.
/// Layout this node into the given regions, producing frames.
fn layout(
&self,
ctx: &mut Context,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 29 KiB