Match pdfTeX link rectangles in repeated leaders
This commit is contained in:
1 parent
aed7010cba
commit
5b9eca1d60
6 files changed
+178
-10
No files matched your search
@@ -172,7 +172,7 @@ pub(super) enum BoxPaint<'a> {
|
||||
RowStart(BoxLayout),
|
||||
ScopeStart(usize),
|
||||
ScopeEnd(usize),
|
||||
PdfLink(&'a OutputNode, BoxLayout),
|
||||
PdfLink(&'a OutputNode, BoxLayout, Option<usize>),
|
||||
Output(&'a OutputNode),
|
||||
}
|
||||
|
||||
@@ -180,6 +180,7 @@ struct WalkBudget<'a> {
|
||||
remaining: usize,
|
||||
cancellation: Option<&'a Cancellation>,
|
||||
leader_depth: usize,
|
||||
next_leader_link: usize,
|
||||
xdv_scopes: bool,
|
||||
}
|
||||
|
||||
@@ -189,6 +190,7 @@ impl WalkBudget<'_> {
|
||||
remaining: usize::MAX,
|
||||
cancellation: None,
|
||||
leader_depth: 0,
|
||||
next_leader_link: 0,
|
||||
xdv_scopes: false,
|
||||
}
|
||||
}
|
||||
@@ -296,6 +298,7 @@ impl NativeBox {
|
||||
remaining: limit,
|
||||
cancellation,
|
||||
leader_depth: 0,
|
||||
next_leader_link: 0,
|
||||
xdv_scopes: false,
|
||||
};
|
||||
self.walk_at(0, 0, 0, false, false, &mut budget, &mut |x, y, item| {
|
||||
@@ -890,7 +893,7 @@ impl NativeBox {
|
||||
return;
|
||||
}
|
||||
BoxPaint::RowStart(_) | BoxPaint::ScopeStart(_) | BoxPaint::ScopeEnd(_)
|
||||
| BoxPaint::PdfLink(_, _) => return,
|
||||
| BoxPaint::PdfLink(..) => return,
|
||||
};
|
||||
if let Some(child) = &b.math_geometry {
|
||||
for p in &child.items {
|
||||
@@ -1078,12 +1081,14 @@ impl NativeBox {
|
||||
+ self.setting.adjustment(g, &mut cumulative, &mut previous);
|
||||
match &leader.pattern {
|
||||
LeaderPattern::Box(b) => {
|
||||
let first_link = budget.next_leader_link;
|
||||
for pos in leader.positions(
|
||||
y - self.height,
|
||||
cursor,
|
||||
length,
|
||||
b.height + b.depth,
|
||||
) {
|
||||
budget.next_leader_link = first_link;
|
||||
b.walk_leader(
|
||||
if rtl { edge - b.shift - b.width } else { x + b.shift },
|
||||
pos + b.height,
|
||||
@@ -1118,7 +1123,7 @@ impl NativeBox {
|
||||
cursor += b.depth;
|
||||
}
|
||||
NativeVerticalNode::Output(node) => {
|
||||
walk_output(node, edge, cursor, container, links, emit);
|
||||
walk_output(node, edge, cursor, container, links, budget, emit);
|
||||
if let Some(image) = node.image_box() {
|
||||
cursor += image.height;
|
||||
emit(if rtl { edge - image.width } else { x }, cursor, BoxPaint::Box(&image));
|
||||
@@ -1151,7 +1156,7 @@ impl NativeBox {
|
||||
let result = self.walk_at(x, y, level, rtl, links, budget, &mut |x, y, paint| {
|
||||
if !matches!(paint, BoxPaint::Output(o) if matches!(o.operation,
|
||||
OutputOperation::Open { .. } | OutputOperation::Write { .. } | OutputOperation::Close { .. }))
|
||||
&& !matches!(paint, BoxPaint::PdfLink(node, _) if matches!(
|
||||
&& !matches!(paint, BoxPaint::PdfLink(node, ..) if matches!(
|
||||
node.operation,
|
||||
OutputOperation::PdfLink(crate::pdf_device::links::LinkNode::Destination { .. }
|
||||
| crate::pdf_device::links::LinkNode::Annotation { .. }
|
||||
@@ -1207,7 +1212,9 @@ fn walk_row(
|
||||
PackedHorizontal::Leaders(leader, width) => {
|
||||
match &leader.pattern {
|
||||
LeaderPattern::Box(b) => {
|
||||
let first_link = budget.next_leader_link;
|
||||
for pos in leader.positions(row.left, x, *width, b.width) {
|
||||
budget.next_leader_link = first_link;
|
||||
b.walk_leader(pos, y + b.shift, row.level + 1, *rtl, links, budget, emit)?;
|
||||
}
|
||||
}
|
||||
@@ -1224,7 +1231,7 @@ fn walk_row(
|
||||
x += width;
|
||||
}
|
||||
PackedHorizontal::Output(node) => {
|
||||
walk_output(node, x, y, row, links, emit);
|
||||
walk_output(node, x, y, row, links, budget, emit);
|
||||
if let Some(image) = node.image_box() {
|
||||
emit(x, y, BoxPaint::Box(&image));
|
||||
x += image.width;
|
||||
@@ -1242,6 +1249,7 @@ fn walk_output(
|
||||
y: i64,
|
||||
container: BoxLayout,
|
||||
links: bool,
|
||||
budget: &mut WalkBudget<'_>,
|
||||
emit: &mut dyn FnMut(i64, i64, BoxPaint<'_>),
|
||||
) {
|
||||
emit(x, y, BoxPaint::Output(node));
|
||||
@@ -1252,7 +1260,16 @@ fn walk_output(
|
||||
} else if let OutputOperation::PdfTextSpace(operation) = node.operation {
|
||||
emit(x, y, BoxPaint::PdfTextSpace(operation));
|
||||
} else if links && node.is_pdf_link() {
|
||||
emit(x, y, BoxPaint::PdfLink(node, container));
|
||||
// Repeated tiles revisit the same node slots. Separate copies of a
|
||||
// box get separate slots even when Rust shares their backing list.
|
||||
let leader_link = (budget.leader_depth > 0 && matches!(
|
||||
node.operation, OutputOperation::PdfLink(crate::pdf_device::links::LinkNode::Start(_))
|
||||
)).then(|| {
|
||||
let slot = budget.next_leader_link;
|
||||
budget.next_leader_link += 1;
|
||||
slot
|
||||
});
|
||||
emit(x, y, BoxPaint::PdfLink(node, container, leader_link));
|
||||
}
|
||||
}
|
||||
pub(super) fn box_paragraph(mut b: NativeBox) -> Paragraph {
|
||||
|
||||
Reference in new issue
Block a user