mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix inline math formula frame size
This commit is contained in:
parent
7660978ee5
commit
2fe549c1ec
@ -43,6 +43,12 @@ impl RawAlign {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Align> for RawAlign {
|
||||||
|
fn from(align: Align) -> Self {
|
||||||
|
Self::Specific(align)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Debug for RawAlign {
|
impl Debug for RawAlign {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -56,7 +56,7 @@ impl Show for MathNode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(if self.display {
|
Ok(if self.display {
|
||||||
Content::block(node)
|
Content::block(node.pack().aligned(Spec::with_x(Some(Align::Center.into()))))
|
||||||
} else {
|
} else {
|
||||||
Content::inline(node)
|
Content::inline(node)
|
||||||
})
|
})
|
||||||
|
@ -58,19 +58,24 @@ impl Layout for RexNode {
|
|||||||
// Determine the metrics.
|
// Determine the metrics.
|
||||||
let (x0, y0, x1, y1) = renderer.size(&layout);
|
let (x0, y0, x1, y1) = renderer.size(&layout);
|
||||||
let width = Length::pt(x1 - x0);
|
let width = Length::pt(x1 - x0);
|
||||||
let height = Length::pt(y1 - y0);
|
let mut top = Length::pt(y1);
|
||||||
let size = Size::new(width, height);
|
let mut bottom = Length::pt(-y0);
|
||||||
let baseline = Length::pt(y1);
|
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.
|
// Prepare a frame rendering backend.
|
||||||
|
let size = Size::new(width, top + bottom);
|
||||||
let mut backend = FrameBackend {
|
let mut backend = FrameBackend {
|
||||||
frame: {
|
frame: {
|
||||||
let mut frame = Frame::new(size);
|
let mut frame = Frame::new(size);
|
||||||
frame.set_baseline(baseline);
|
frame.set_baseline(top);
|
||||||
frame.apply_role(Role::Formula);
|
frame.apply_role(Role::Formula);
|
||||||
frame
|
frame
|
||||||
},
|
},
|
||||||
baseline,
|
baseline: top,
|
||||||
face_id,
|
face_id,
|
||||||
fill: styles.get(TextNode::FILL),
|
fill: styles.get(TextNode::FILL),
|
||||||
lang: styles.get(TextNode::LANG),
|
lang: styles.get(TextNode::LANG),
|
||||||
|
@ -19,10 +19,9 @@ use crate::Context;
|
|||||||
|
|
||||||
/// A node that can be layouted into a sequence of regions.
|
/// A node that can be layouted into a sequence of regions.
|
||||||
///
|
///
|
||||||
/// Layout return one frame per used region alongside constraints that define
|
/// Layouting return one frame per used region.
|
||||||
/// whether the result is reusable in other regions.
|
|
||||||
pub trait Layout: 'static {
|
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(
|
fn layout(
|
||||||
&self,
|
&self,
|
||||||
ctx: &mut Context,
|
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 |
Loading…
x
Reference in New Issue
Block a user