Expose stored left and right margin kerns from native boxes

This commit is contained in:
gloamxun committed 2026-11-21 02:13:39 +08:00
1 parent 432c1d2ba7
commit d46d6d79a8
9 files changed
+104 -31

No files matched your search

@@ -43,32 +43,7 @@ impl Edge {
}) if boxed.width == 0 && boxed.height == 0 && boxed.depth == 0 => Self::Skip,
_ => Self::Solid,
},
TextNode::Language(_)
| TextNode::Mark(_)
| TextNode::Adjustment(_)
| TextNode::Insertion(_)
| TextNode::Penalty(_)
| TextNode::Indent(0)
| TextNode::AccentKern(0)
| TextNode::MathBoundary { width: 0, .. }
| TextNode::Kern {
explicit: false, ..
}
| TextNode::Kern { width: 0, .. } => Self::Skip,
TextNode::Output(node) if node.dimensions().is_none() => Self::Skip,
TextNode::Glue(glue)
| TextNode::NamedGlue(glue, _)
| TextNode::Leaders(LeaderGlue { glue, .. })
if glue.canonical_zero =>
{
Self::Skip
}
TextNode::Discretionary {
pre_break,
post_break,
replacement_count: 0,
..
} if pre_break.is_empty() && post_break.is_empty() => Self::Skip,
_ if skippable(node) => Self::Skip,
_ => Self::character(node),
}
}
@@ -107,6 +82,58 @@ impl Edge {
}
}
fn skippable(node: &TextNode) -> bool {
match node {
TextNode::Box(boxed) => matches!(
boxed.native_box.as_deref(),
Some(NativeBox { content: BoxContent::Horizontal(nodes), .. })
if nodes.is_empty() && boxed.width == 0 && boxed.height == 0 && boxed.depth == 0
),
TextNode::Language(_)
| TextNode::Mark(_)
| TextNode::Adjustment(_)
| TextNode::Insertion(_)
| TextNode::Penalty(_)
| TextNode::Indent(0)
| TextNode::AccentKern(0)
| TextNode::MathBoundary { width: 0, .. }
| TextNode::Kern { explicit: false, .. }
| TextNode::Kern { width: 0, .. } => true,
TextNode::Output(node) => node.dimensions().is_none(),
TextNode::Glue(glue)
| TextNode::NamedGlue(glue, _)
| TextNode::Leaders(LeaderGlue { glue, .. }) => glue.canonical_zero,
TextNode::Discretionary {
pre_break,
post_break,
replacement_count: 0,
..
} => pre_break.is_empty() && post_break.is_empty(),
_ => false,
}
}
pub(in crate::execution) fn stored_margin_kern(nodes: &[TextNode], right: bool) -> i32 {
let side_skip = if right { Parameter::Rightskip } else { Parameter::Leftskip };
let non_skippable = |node: &&TextNode| {
!matches!(node, TextNode::NamedGlue(_, parameter) if *parameter == side_skip)
&& !skippable(node)
};
// The query walks only the stored hlist. It does not descend into a nested
// box or recalculate protrusion using the current font codes.
let edge = if right {
nodes.iter().rev().find(non_skippable)
} else {
nodes.iter().find(non_skippable)
};
match edge {
Some(TextNode::MarginKern { width, right: actual_side, .. }) if *actual_side == right => {
*width
}
_ => 0,
}
}
pub(super) fn margin_kern(
state: &State,
nodes: &[TextNode],