Files
texrra-engine/crates/texrra-tex-core/src/execution/rule.rs
T

68 lines
2.3 KiB
Rust

//! Original rule dimensions. None is TeX's running dimension, resolved by the
//! actual containing box at output, not by the current font or paragraph size.
use crate::{
HorizontalBox,
math::MathBox,
math_engine_tex::{MathGeometry, MathItem, PositionedItem},
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct NativeRule {
pub span: super::Span,
/// None for engine-generated diagnostic paint, never a guessed box span.
pub origin: Option<super::TokenOrigin>,
/// The generating operation belongs to this rule, including saved boxes.
pub derivation: Option<crate::provenance::Derivation>,
pub width: Option<i32>,
pub height: Option<i32>,
pub depth: Option<i32>,
}
impl NativeRule {
pub const RUNNING: i32 = -1073741824;
pub(super) fn dimensions(self) -> (i64, i64, i64) {
(
i64::from(self.width.unwrap_or(Self::RUNNING)),
i64::from(self.height.unwrap_or(Self::RUNNING)),
i64::from(self.depth.unwrap_or(Self::RUNNING)),
)
}
pub(super) fn horizontal_item(self, width: i64, height: i64, depth: i64) -> HorizontalBox {
let (width, height, depth) = (
self.width.map_or(width, i64::from),
self.height.map_or(height, i64::from),
self.depth.map_or(depth, i64::from),
);
let metrics = MathBox {
width,
height,
depth,
};
let mut source = self
.origin
.map(crate::provenance::PaintSource::token)
.unwrap_or_default();
if let Some(derivation) = self.derivation {
source = source.derived(derivation);
}
let items = if width > 0 && height + depth > 0 {
vec![PositionedItem {
source,
x: 0,
y: -height,
item: MathItem::Rule {
width,
height: height + depth,
},
}]
} else {
Vec::new()
};
HorizontalBox {
width,
height,
depth,
math_geometry: Some(Box::new(MathGeometry { metrics, items })),
..HorizontalBox::default()
}
}
}