Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,114 @@
|
||||
//! TeX make_fraction: clean/rebox actual fields, then retain the vlist and delimiters.
|
||||
use super::{math::*, *};
|
||||
use crate::{math_engine_tex::MathStyle, provenance::PaintSource};
|
||||
|
||||
impl Converter<'_> {
|
||||
pub(super) fn fraction(
|
||||
&self,
|
||||
numerator: &[MathNode],
|
||||
denominator: &[MathNode],
|
||||
spec: &FractionSpec,
|
||||
style: MathStyle,
|
||||
span: Span,
|
||||
source: &PaintSource,
|
||||
) -> Result<NativeBox, String> {
|
||||
let params = self.params(style)?;
|
||||
let thickness = spec.thickness.map_or(params.rule_thickness, i64::from);
|
||||
let mut upper = self.pack_field(self.convert(numerator, style.numerator(), false)?.0)?;
|
||||
let mut lower =
|
||||
self.pack_field(self.convert(denominator, style.denominator(), false)?.0)?;
|
||||
if upper.width < lower.width {
|
||||
upper = self.rebox_math(upper, lower.width)?;
|
||||
} else {
|
||||
lower = self.rebox_math(lower, upper.width)?;
|
||||
}
|
||||
let mut up = if style.display() {
|
||||
params.num1
|
||||
} else if thickness != 0 {
|
||||
params.num2
|
||||
} else {
|
||||
params.num3
|
||||
};
|
||||
let mut down = if style.display() {
|
||||
params.denom1
|
||||
} else {
|
||||
params.denom2
|
||||
};
|
||||
let half = (thickness + 1).div_euclid(2);
|
||||
if thickness == 0 {
|
||||
let clearance = if style.display() { 7 } else { 3 } * params.rule_thickness;
|
||||
let delta =
|
||||
(clearance - ((up - upper.depth) - (lower.height - down)) + 1).div_euclid(2);
|
||||
if delta > 0 {
|
||||
up += delta;
|
||||
down += delta;
|
||||
}
|
||||
} else {
|
||||
let clearance = if style.display() {
|
||||
3 * thickness
|
||||
} else {
|
||||
thickness
|
||||
};
|
||||
up = up.max(upper.depth + params.axis_height + half + clearance);
|
||||
down = down.max(lower.height - params.axis_height + half + clearance);
|
||||
}
|
||||
let width = upper.width;
|
||||
let height = up + upper.height;
|
||||
let depth = lower.depth + down;
|
||||
let kern = |n: i64| -> Result<NativeVerticalNode, String> {
|
||||
Ok(NativeVerticalNode::ImplicitKern(
|
||||
i32::try_from(n).map_err(|_| "native fraction kern overflow")?,
|
||||
))
|
||||
};
|
||||
let mut nodes = Vec::new();
|
||||
let upper_bottom = up - upper.depth;
|
||||
let lower_top = lower.height - down;
|
||||
nodes.push(NativeVerticalNode::Box(Box::new(upper)));
|
||||
if thickness == 0 {
|
||||
nodes.push(kern(upper_bottom - lower_top)?);
|
||||
} else {
|
||||
nodes.push(kern(upper_bottom - (params.axis_height + half))?);
|
||||
nodes.push(NativeVerticalNode::Rule(NativeRule {
|
||||
span,
|
||||
origin: source.tokens.first().copied(),
|
||||
derivation: Some(crate::provenance::Derivation::Fraction),
|
||||
width: None,
|
||||
height: Some(
|
||||
i32::try_from(thickness).map_err(|_| "native fraction thickness overflow")?,
|
||||
),
|
||||
depth: Some(0),
|
||||
}));
|
||||
nodes.push(kern((params.axis_height - half) - lower_top)?);
|
||||
}
|
||||
nodes.push(NativeVerticalNode::Box(Box::new(lower)));
|
||||
// make_fraction declares these dimensions directly; odd thickness can
|
||||
// place the denominator one sp above its declared baseline/depth.
|
||||
let body = NativeBox {
|
||||
kind: BoxKind::Vertical,
|
||||
display: false,
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
shift: 0,
|
||||
content: BoxContent::Vertical(nodes),
|
||||
diagnostic: Vec::new(),
|
||||
setting: GlueSetting::default(),
|
||||
badness: 0,
|
||||
diagnostic_eligible: false,
|
||||
excess: 0,
|
||||
span,
|
||||
};
|
||||
let target = if style.display() {
|
||||
params.delim1
|
||||
} else {
|
||||
params.delim2
|
||||
};
|
||||
let left = self.delimiter(spec.left, style, target, &spec.left_source)?;
|
||||
let right = self.delimiter(spec.right, style, target, &spec.right_source)?;
|
||||
self.measure(&[
|
||||
TextNode::Box(left.horizontal_item()),
|
||||
TextNode::Box(body.horizontal_item()),
|
||||
TextNode::Box(right.horizontal_item()),
|
||||
])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user