Resolve FitR destinations using shipped box geometry
This commit is contained in:
1 parent
22154b53a6
commit
003d5d8726
8 files changed
+123
-40
No files matched your search
@@ -6,7 +6,7 @@ use crate::pdf_device::{
|
||||
PageDestination, PageLinks,
|
||||
},
|
||||
};
|
||||
use crate::execution::boxes::{BoxPaint, RowLayout};
|
||||
use crate::execution::boxes::{BoxPaint, BoxLayout};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Segment {
|
||||
@@ -51,7 +51,7 @@ impl ActiveLink {
|
||||
fn start_segment(
|
||||
&mut self,
|
||||
output: &mut PageLinks,
|
||||
row: RowLayout,
|
||||
row: BoxLayout,
|
||||
point: [i64; 2],
|
||||
transform: (Affine, bool),
|
||||
margin: i64,
|
||||
@@ -102,6 +102,23 @@ impl ActiveLink {
|
||||
}
|
||||
|
||||
impl Executor {
|
||||
fn scan_pdf_rule(&mut self, files: &mut impl SourceProvider) -> Result<[Option<i32>; 3], Error> {
|
||||
let mut dimensions = [None; 3];
|
||||
loop {
|
||||
let index = if self.keyword("width", files)? {
|
||||
0
|
||||
} else if self.keyword("height", files)? {
|
||||
1
|
||||
} else if self.keyword("depth", files)? {
|
||||
2
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
dimensions[index] = Some(self.dimension(false, false, files)?.amount);
|
||||
}
|
||||
Ok(dimensions)
|
||||
}
|
||||
|
||||
pub(super) fn scan_pdf_link(
|
||||
&mut self,
|
||||
command: Primitive,
|
||||
@@ -130,19 +147,7 @@ impl Executor {
|
||||
.get_or_insert_with(Default::default)
|
||||
.reserve_link(self.limits.tokens)
|
||||
.map_err(|error| self.error(error, self.current))?;
|
||||
let (mut width, mut height, mut depth) = (None, None, None);
|
||||
loop {
|
||||
let target = if self.keyword("width", files)? {
|
||||
&mut width
|
||||
} else if self.keyword("height", files)? {
|
||||
&mut height
|
||||
} else if self.keyword("depth", files)? {
|
||||
&mut depth
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
*target = Some(self.dimension(false, false, files)?.amount);
|
||||
}
|
||||
let [width, height, depth] = self.scan_pdf_rule(files)?;
|
||||
let attributes = if self.keyword("attr", files)? {
|
||||
self.scan_pdf_tokens(files)?
|
||||
} else {
|
||||
@@ -191,6 +196,8 @@ impl Executor {
|
||||
None
|
||||
};
|
||||
DestinationView::Xyz(zoom)
|
||||
} else if self.keyword("fitr", files)? {
|
||||
DestinationView::FitR(self.scan_pdf_rule(files)?)
|
||||
} else {
|
||||
let mut view = None;
|
||||
for (name, candidate) in [
|
||||
@@ -237,7 +244,7 @@ impl Executor {
|
||||
b.walk_pdf_links(&mut |x, y, item| {
|
||||
if failure.is_some() { return; }
|
||||
let (x, y) = (x + origin_x, y + origin_y);
|
||||
let absolute_row = |mut row: RowLayout| {
|
||||
let absolute_row = |mut row: BoxLayout| {
|
||||
row.left += origin_x;
|
||||
row.baseline += origin_y;
|
||||
row
|
||||
@@ -264,15 +271,16 @@ impl Executor {
|
||||
link.start_segment(&mut output, absolute_row(row), [x, y], transform, margin);
|
||||
}
|
||||
}
|
||||
BoxPaint::PdfLink(node, row) => {
|
||||
BoxPaint::PdfLink(node, container) => {
|
||||
let container = absolute_row(container);
|
||||
self.current = node.span;
|
||||
let OutputOperation::PdfLink(link) = &node.operation else { unreachable!() };
|
||||
match link {
|
||||
LinkNode::Start(layout) => {
|
||||
let Some(row) = row.map(absolute_row) else {
|
||||
if !container.horizontal {
|
||||
failure = Some(self.error("PDF link start arrived outside a horizontal list", node.span));
|
||||
return;
|
||||
};
|
||||
}
|
||||
let attributes = self.token_list_text(&layout.attributes);
|
||||
let action = match &layout.action {
|
||||
LinkAction::User(tokens) => AnnotationAction::User(self.token_list_text(tokens)),
|
||||
@@ -280,8 +288,8 @@ impl Executor {
|
||||
LinkAction::Catalog(action) => AnnotationAction::Catalog(action.clone()),
|
||||
};
|
||||
let mut start = ActiveLink { layout: layout.clone(), attributes,
|
||||
action, level: row.level, segment: None };
|
||||
start.start_segment(&mut output, row, [x, y], transform, margin);
|
||||
action, level: container.level, segment: None };
|
||||
start.start_segment(&mut output, container, [x, y], transform, margin);
|
||||
// The scan-time object number belongs only to the
|
||||
// initial annotation, never to a continuation row.
|
||||
output.annotations.last_mut().unwrap().object_number = layout.object_number;
|
||||
@@ -292,7 +300,7 @@ impl Executor {
|
||||
failure = Some(self.error("\\pdfendlink used without \\pdfstartlink", node.span));
|
||||
return;
|
||||
};
|
||||
if row.is_none_or(|r| r.level != link.level) {
|
||||
if !container.horizontal || container.level != link.level {
|
||||
let result = files.observe_diagnostic(WriteDestination::TerminalAndLog,
|
||||
"pdfTeX warning: pdftex: \\pdfendlink ended up in different nesting level than \\pdfstartlink\n");
|
||||
if let Err(error) = result {
|
||||
@@ -308,8 +316,19 @@ impl Executor {
|
||||
DestinationId::Name(tokens) => DestinationId::Name(self.token_list_text(tokens)),
|
||||
DestinationId::Number(number) => DestinationId::Number(*number),
|
||||
};
|
||||
let view = view.map_rectangle(|[width, height, depth]| {
|
||||
let margin = i64::from(self.read_parameter(Parameter::Pdfdestmargin).width());
|
||||
let top = height.map_or(container.baseline - container.height, |h| y - i64::from(h));
|
||||
let right = width.map_or(container.left + container.width, |w| x + i64::from(w));
|
||||
let bottom = depth.map_or(container.baseline + container.depth, |d| y + i64::from(d));
|
||||
if transform.1 {
|
||||
link_rect([x, top, right, bottom], transform.0, margin)
|
||||
} else {
|
||||
[x - margin, top - margin, right + margin, bottom + margin]
|
||||
}
|
||||
});
|
||||
output.destinations.push(PageDestination {
|
||||
destination, point: map_point(transform.0, x, y), view: *view,
|
||||
destination, point: map_point(transform.0, x, y), view,
|
||||
structure: *structure,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user