Integrate native repeat boxes and PDF bookmarks

This commit is contained in:
gloamxun committed 2026-11-19 16:06:28 +08:00
1 parent 5163fc9854
commit 38e4822370
33 files changed
+1208 -143

No files matched your search

@@ -53,6 +53,7 @@ pub enum TextNode {
},
Glue(Glue),
NamedGlue(Glue, Parameter),
Leaders(LeaderGlue),
Kern {
width: i32,
explicit: bool,
@@ -365,6 +366,7 @@ fn discardable(n: &TextNode) -> bool {
n,
TextNode::Glue(_)
| TextNode::NamedGlue(_, _)
| TextNode::Leaders(_)
| TextNode::Kern { .. }
| TextNode::MathBoundary { .. }
| TextNode::Penalty(_)
@@ -375,7 +377,9 @@ fn width(n: &TextNode) -> i64 {
TextNode::Glyph { glyph, .. } | TextNode::Box(glyph) | TextNode::MathChar(glyph) => {
glyph.width
}
TextNode::Glue(g) | TextNode::NamedGlue(g, _) => g.width as i64,
TextNode::Glue(g)
| TextNode::NamedGlue(g, _)
| TextNode::Leaders(LeaderGlue { glue: g, .. }) => g.width as i64,
TextNode::Rule(r) => r.dimensions().0,
TextNode::Output(node) => node.dimensions().map_or(0, |(width, _, _)| width),
TextNode::Kern { width: n, .. }
@@ -516,7 +520,10 @@ fn metrics(nodes: &[TextNode], left: Glue, right: Glue) -> (i64, [i64; 4], i64)
let mut shrink = 0;
for g in std::iter::once(left)
.chain(nodes.iter().filter_map(|n| {
if let TextNode::Glue(g) | TextNode::NamedGlue(g, _) = n {
if let TextNode::Glue(g)
| TextNode::NamedGlue(g, _)
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
{
Some(*g)
} else {
None
@@ -530,7 +537,12 @@ fn metrics(nodes: &[TextNode], left: Glue, right: Glue) -> (i64, [i64; 4], i64)
}
natural += nodes
.iter()
.filter(|n| !matches!(n, TextNode::Glue(_) | TextNode::NamedGlue(_, _)))
.filter(|n| {
!matches!(
n,
TextNode::Glue(_) | TextNode::NamedGlue(_, _) | TextNode::Leaders(_)
)
})
.map(width)
.sum::<i64>();
(natural, stretch, shrink)
@@ -968,7 +980,10 @@ fn pre_display_line_size(
| TextNode::Indent(_)
| TextNode::Rule(_)
);
if let TextNode::Glue(g) | TextNode::NamedGlue(g, _) = n {
if let TextNode::Glue(g)
| TextNode::NamedGlue(g, _)
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
{
let f = if set.sign > 0 { g.stretch } else { g.shrink };
if set.sign != 0 && f.order == set.order && f.amount != 0 {
v = 1073741823;
@@ -996,10 +1011,12 @@ pub(super) fn finish(
cache: Option<&LineBreakCache>,
) -> Result<NativeParagraph, String> {
b.finish_text(true)?;
if b.nodes
.last()
.is_some_and(|n| matches!(n, TextNode::Glue(_) | TextNode::NamedGlue(_, _)))
{
if b.nodes.last().is_some_and(|n| {
matches!(
n,
TextNode::Glue(_) | TextNode::NamedGlue(_, _) | TextNode::Leaders(_)
)
}) {
b.nodes.pop();
}
for n in &b.nodes {
@@ -1020,7 +1037,9 @@ pub(super) fn finish(
.collect();
let shape = state.paragraph_shape();
for n in &b.nodes {
if let TextNode::Glue(g) | TextNode::NamedGlue(g, _) = n
if let TextNode::Glue(g)
| TextNode::NamedGlue(g, _)
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
&& g.shrink.order != 0
&& g.shrink.amount != 0
{
@@ -1260,7 +1279,12 @@ fn add_hyphens(
.is_some_and(|c| state.case_code(super::CaseCode::Lower, c) != 0),
_ => true,
})
.is_some_and(|n| matches!(n, TextNode::Glue(_) | TextNode::NamedGlue(_, _)))
.is_some_and(|n| {
matches!(
n,
TextNode::Glue(_) | TextNode::NamedGlue(_, _) | TextNode::Leaders(_)
)
})
&& !word.is_empty()
&& (state.parameter(Parameter::Uchyph).width() > 0
|| word
@@ -1290,6 +1314,7 @@ fn add_hyphens(
| TextNode::Output(_)
| TextNode::Glue(_)
| TextNode::NamedGlue(_, _)
| TextNode::Leaders(_)
| TextNode::Penalty(_)
| TextNode::Kern { explicit: true, .. }
)