Add a math atom box model

This commit is contained in:
gloamxun committed 2026-10-20 12:52:33 +08:00
1 parent 9a7404c717
commit cd6baba53f
3 files changed
+167 -1

No files matched your search

+17
View File
@@ -1,4 +1,5 @@
pub mod cmr10;
pub mod math;
pub mod paragraph;
pub use cmr10::Cmr10Metrics;
@@ -232,6 +233,22 @@ impl Unit {
}
}
/// Build a unit from a math atom using CMR10 metrics.
pub fn math(
id: UnitId,
atom: crate::math::MathAtom,
font: &crate::cmr10::Cmr10Metrics,
) -> Self {
let math_box = math::layout_math(&atom, font);
Self::vertical(
id,
vec![VerticalItem::Box(VerticalBox {
width: math_box.width,
height: math_box.height + math_box.depth,
})],
)
}
/// Build a unit from arbitrary vertical material.
pub fn vertical(id: UnitId, items: Vec<VerticalItem>) -> Self {
Self {