Ship XDV annotations from measured page ranges

This commit is contained in:
gloamxun committed 2026-11-25 21:12:44 +08:00
1 parent 515dbe6181
commit 20986b2fd5
16 files changed
+873 -54

No files matched your search

+27 -1
View File
@@ -164,6 +164,8 @@ pub(super) enum BoxPaint<'a> {
PdfGraphics,
PdfTextSpace(crate::pdf_device::text_spaces::SpaceOperation),
RowStart(BoxLayout),
ScopeStart(usize),
ScopeEnd(usize),
PdfLink(&'a OutputNode, BoxLayout),
Output(&'a OutputNode),
}
@@ -172,6 +174,7 @@ struct WalkBudget<'a> {
remaining: usize,
cancellation: Option<&'a Cancellation>,
leader_depth: usize,
xdv_annotations: bool,
}
impl WalkBudget<'_> {
@@ -180,6 +183,7 @@ impl WalkBudget<'_> {
remaining: usize::MAX,
cancellation: None,
leader_depth: 0,
xdv_annotations: false,
}
}
@@ -284,6 +288,7 @@ impl NativeBox {
remaining: limit,
cancellation,
leader_depth: 0,
xdv_annotations: false,
};
self.walk_at(0, 0, 0, false, false, &mut budget, &mut |x, y, item| {
if let BoxPaint::Output(o) = item {
@@ -782,7 +787,8 @@ impl NativeBox {
emit(GeometryItem::Output);
return;
}
BoxPaint::RowStart(_) | BoxPaint::PdfLink(_, _) => return,
BoxPaint::RowStart(_) | BoxPaint::ScopeStart(_) | BoxPaint::ScopeEnd(_)
| BoxPaint::PdfLink(_, _) => return,
};
if let Some(child) = &b.math_geometry {
for p in &child.items {
@@ -851,6 +857,19 @@ impl NativeBox {
.expect("link traversal of an already measured list");
}
pub(super) fn walk_xdv_annotations(
&self,
cancellation: Option<&Cancellation>,
emit: &mut dyn FnMut(i64, i64, BoxPaint<'_>),
) -> Result<(), &'static str> {
let mut budget = WalkBudget {
cancellation,
xdv_annotations: true,
..WalkBudget::for_geometry()
};
self.walk_at(0, 0, 0, false, false, &mut budget, emit)
}
fn walk_at(
&self,
x: i64,
@@ -864,6 +883,10 @@ impl NativeBox {
if self.kind.is_unset() {
return Ok(());
}
if budget.xdv_annotations {
budget.charge(1)?;
emit(x, y, BoxPaint::ScopeStart(level));
}
match &self.content {
BoxContent::Horizontal(nodes) => {
budget.inside_leader(nodes.len())?;
@@ -975,6 +998,9 @@ impl NativeBox {
}
}
}
if budget.xdv_annotations {
emit(x, y, BoxPaint::ScopeEnd(level));
}
Ok(())
}