60 lines
2.0 KiB
Rust
60 lines
2.0 KiB
Rust
use super::{
|
|
boxes::{PackSpec, dimensions_fit, vpack},
|
|
math::Converter,
|
|
*,
|
|
};
|
|
use crate::{math_engine_tex::MathStyle, provenance::Derivation};
|
|
|
|
impl Converter<'_> {
|
|
pub(super) fn rule_noad(
|
|
&self,
|
|
noad: &Noad,
|
|
position: MathRulePosition,
|
|
style: MathStyle,
|
|
) -> Result<NativeBox, String> {
|
|
let thickness = i32::try_from(self.params(style)?.rule_thickness)
|
|
.map_err(|_| "native math rule thickness overflow")?;
|
|
let clearance = thickness
|
|
.checked_mul(3)
|
|
.ok_or("native math rule clearance overflow")?;
|
|
let nucleus_style = match position {
|
|
MathRulePosition::Over => style.cramped_style(),
|
|
MathRulePosition::Under => style,
|
|
};
|
|
let box_ = self.owned_field(&noad.nucleus, nucleus_style, &noad.source.nucleus)?;
|
|
let height = box_.height;
|
|
let nucleus = NativeVerticalNode::Box(Box::new(box_));
|
|
let bar = NativeVerticalNode::Rule(NativeRule {
|
|
span: noad.span,
|
|
origin: noad.source.operator.tokens.first().copied(),
|
|
derivation: Some(Derivation::MathRule),
|
|
width: None,
|
|
height: Some(thickness),
|
|
depth: Some(0),
|
|
});
|
|
let clearance = NativeVerticalNode::ImplicitKern(clearance);
|
|
let nodes = match position {
|
|
MathRulePosition::Over => vec![
|
|
NativeVerticalNode::ImplicitKern(thickness),
|
|
bar,
|
|
clearance,
|
|
nucleus,
|
|
],
|
|
MathRulePosition::Under => vec![nucleus, clearance, bar],
|
|
};
|
|
let mut box_ = vpack(
|
|
nodes,
|
|
PackSpec::Natural,
|
|
i32::MAX,
|
|
BoxKind::Vertical,
|
|
noad.span,
|
|
)?;
|
|
if position == MathRulePosition::Under {
|
|
box_.depth = box_.height + box_.depth + i64::from(thickness) - height;
|
|
box_.height = height;
|
|
dimensions_fit(box_.width, box_.height, box_.depth)?;
|
|
}
|
|
Ok(box_)
|
|
}
|
|
}
|