Carry XDV device advances through packed box scopes
This commit is contained in:
1 parent
9da75c82f5
commit
9efededf6d
14 files changed
+252
-83
No files matched your search
@@ -48,6 +48,7 @@ enum XdvOutput {
|
||||
index: usize,
|
||||
graphics_step: usize,
|
||||
point: [i64; 2],
|
||||
device_position: [i64; 2],
|
||||
origin: Option<TokenOrigin>,
|
||||
content_origin: Option<[i64; 2]>,
|
||||
text: Option<crate::pdf_device::xdv_document::TextEncoding>,
|
||||
@@ -544,13 +545,13 @@ impl Executor {
|
||||
});
|
||||
self.begin_pdf_link_shipout(b, device, thread_rows)
|
||||
});
|
||||
let mut output_positions = if let Some(effects) = &leader_effects {
|
||||
effects.output_positions.clone().into_iter()
|
||||
let mut output_positions = if let Some(effects) = &leader_effects && !xdv {
|
||||
effects.output_positions.iter().map(|&point| (point, 0)).collect()
|
||||
} else if outputs.iter().any(|node| node.needs_shipout_position()) {
|
||||
b.positioned_outputs().into_iter()
|
||||
b.positioned_outputs(xdv)
|
||||
} else {
|
||||
Vec::new().into_iter()
|
||||
};
|
||||
Vec::new()
|
||||
}.into_iter();
|
||||
let mut font_uses = if device.pdf.is_some() {
|
||||
shipout.virtual_glyphs = Some(VirtualGlyphs::new());
|
||||
shipout_font_uses(b, &self.pdf_virtual_fonts, &self.state.fonts).map_err(|e| self.error(e, b.span))?
|
||||
@@ -577,7 +578,7 @@ impl Executor {
|
||||
layout.advance(self, (index, usage.before_paint), &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
}
|
||||
self.current = current;
|
||||
self.prepare_virtual_glyph(shipout.virtual_glyphs.as_mut().unwrap(), usage, files)?;
|
||||
self.prepare_virtual_glyph(shipout.virtual_glyphs.as_mut().unwrap(), usage, xdv, files)?;
|
||||
}
|
||||
if let Some(layout) = &mut pdf_link_shipout {
|
||||
layout.advance(self, (index, usize::MAX), &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
@@ -596,12 +597,13 @@ impl Executor {
|
||||
self.current = output.span;
|
||||
self.probe_pdf_space_font(&shipout, Some(index), files)?;
|
||||
}
|
||||
let position = if output.needs_shipout_position() {
|
||||
Some(output_positions.next().ok_or_else(|| {
|
||||
let (position, xdv_shift) = if output.needs_shipout_position() {
|
||||
let (position, shift) = output_positions.next().ok_or_else(|| {
|
||||
self.error("missing positioned native output node", output.span)
|
||||
})?)
|
||||
})?;
|
||||
(Some(position), shift)
|
||||
} else {
|
||||
None
|
||||
(None, 0)
|
||||
};
|
||||
if let OutputOperation::PdfObject(number) = output.operation {
|
||||
self.current = output.span;
|
||||
@@ -634,6 +636,8 @@ impl Executor {
|
||||
let special = self.resolve_special(
|
||||
output, position.expect("special needs a shipout position"), files,
|
||||
)?;
|
||||
let [x, y] = special.position;
|
||||
let device_position = [x + xdv_shift, y];
|
||||
let graphics_step = shipout.pdf_graphics_steps.len();
|
||||
let graphics = if let Some(pdf) = &device.pdf {
|
||||
if xdv && crate::pdf_device::xdv_color::ColorState::recognizes(&special.bytes) {
|
||||
@@ -647,14 +651,15 @@ impl Executor {
|
||||
None
|
||||
} else if xdv && let Some((kind, _)) = super::specials::xdv_navigation_operand(&special.bytes) {
|
||||
let point = xdv_transform.point(
|
||||
(special.position[0] + horizontal_origin) as f64,
|
||||
(special.position[1] + vertical_origin + b.height) as f64,
|
||||
(device_position[0] + horizontal_origin) as f64,
|
||||
(device_position[1] + vertical_origin + b.height) as f64,
|
||||
).map(|coordinate| coordinate.round() as i64);
|
||||
let text = matches!(kind, b"docview" | b"outline").then(|| self.xdv_text.clone());
|
||||
xdv_output.push(XdvOutput::Navigation {
|
||||
index: shipout.specials.len(),
|
||||
graphics_step,
|
||||
point,
|
||||
device_position,
|
||||
origin: *origin,
|
||||
content_origin: content_origins.last().copied(),
|
||||
text,
|
||||
@@ -671,7 +676,7 @@ impl Executor {
|
||||
use crate::pdf_device::{PdfGraphics, PdfLiteralMode};
|
||||
if let Some(PdfGraphics::Literal { mode, .. }) = &graphics {
|
||||
match mode {
|
||||
PdfLiteralMode::XdvBeginContent => content_origins.push(special.position),
|
||||
PdfLiteralMode::XdvBeginContent => content_origins.push(device_position),
|
||||
PdfLiteralMode::XdvEndContent => { content_origins.pop(); }
|
||||
_ => {}
|
||||
}
|
||||
@@ -686,7 +691,7 @@ impl Executor {
|
||||
xdv_graphics_stack.push((special.span, xdv_transform));
|
||||
xdv_output.push(XdvOutput::SaveColor);
|
||||
}
|
||||
let [x, y] = special.position;
|
||||
let [x, y] = device_position;
|
||||
let pivot = matrix.about(
|
||||
(x + horizontal_origin) as f64,
|
||||
(y + vertical_origin + b.height) as f64,
|
||||
@@ -805,7 +810,7 @@ impl Executor {
|
||||
if let Some(layout) = &mut pdf_link_shipout {
|
||||
layout.advance(self, (output_count, usage.before_paint), &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
}
|
||||
self.prepare_virtual_glyph(shipout.virtual_glyphs.as_mut().unwrap(), usage, files)?;
|
||||
self.prepare_virtual_glyph(shipout.virtual_glyphs.as_mut().unwrap(), usage, xdv, files)?;
|
||||
}
|
||||
if let Some(layout) = pdf_link_shipout {
|
||||
let mut links = layout.finish(self, &outputs, &shipout.pdf_graphics_steps, files)?;
|
||||
@@ -877,7 +882,7 @@ impl Executor {
|
||||
];
|
||||
let mut saved_colors = Vec::new();
|
||||
for operation in xdv_output {
|
||||
let (index, graphics_step, [x, y], origin, content_origin, text) = match operation {
|
||||
let (index, graphics_step, [x, y], device_position, origin, content_origin, text) = match operation {
|
||||
XdvOutput::SaveColor => {
|
||||
saved_colors.push(self.xdv_colors.current());
|
||||
continue;
|
||||
@@ -907,8 +912,8 @@ impl Executor {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
XdvOutput::Navigation { index, graphics_step, point, origin, content_origin, text } => {
|
||||
(index, graphics_step, point, origin, content_origin, text)
|
||||
XdvOutput::Navigation { index, graphics_step, point, device_position, origin, content_origin, text } => {
|
||||
(index, graphics_step, point, device_position, origin, content_origin, text)
|
||||
}
|
||||
};
|
||||
let special = &shipout.specials[index];
|
||||
@@ -934,7 +939,7 @@ impl Executor {
|
||||
}
|
||||
} else {
|
||||
let [left, top] = content_origin.unwrap_or(default_content_origin);
|
||||
let [x, y] = special.position;
|
||||
let [x, y] = device_position;
|
||||
let capture_origin = [x - left, top - y]
|
||||
.map(|coordinate| crate::render::DisplayUnits::TeX.bp(coordinate));
|
||||
if let Some(operation) = self.ship_xdv_navigation(
|
||||
@@ -1040,7 +1045,7 @@ impl Executor {
|
||||
}
|
||||
|
||||
fn prepare_virtual_glyph(
|
||||
&mut self, glyphs: &mut VirtualGlyphs, usage: ShipoutFontUse,
|
||||
&mut self, glyphs: &mut VirtualGlyphs, usage: ShipoutFontUse, xdv: bool,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
self.check_cancellation()?;
|
||||
@@ -1052,7 +1057,7 @@ impl Executor {
|
||||
}
|
||||
let defaults = self.font_defaults();
|
||||
let (packet, work) = Arc::make_mut(&mut self.pdf_virtual_fonts).glyph(
|
||||
&mut self.state.fonts, defaults, files, usage.font.clone(), usage.slot,
|
||||
&mut self.state.fonts, defaults, files, usage.font.clone(), usage.slot, xdv,
|
||||
self.limits.steps.saturating_sub(self.steps), self.cancellation.as_ref(),
|
||||
).map_err(|e| self.error(e, self.current))?;
|
||||
self.steps += work;
|
||||
|
||||
@@ -39,11 +39,11 @@ impl Executor {
|
||||
let mut failure = None;
|
||||
shipout
|
||||
.box_node
|
||||
.walk_xdv_annotations(self.cancellation.as_ref(), &mut |x, y, node| {
|
||||
.walk_device(self.cancellation.as_ref(), true, &mut |x, y, node, shift| {
|
||||
if failure.is_some() {
|
||||
return;
|
||||
}
|
||||
let point = [(x + origin[0]) as f64, (y + origin[1]) as f64];
|
||||
let point = [(x + origin[0] + shift) as f64, (y + origin[1]) as f64];
|
||||
let result = match node {
|
||||
BoxPaint::ScopeStart(level) => {
|
||||
page.enter(level);
|
||||
@@ -238,8 +238,12 @@ impl Frame {
|
||||
items: &[PositionedItem],
|
||||
virtuals: Option<&VirtualGlyphs>,
|
||||
) -> Result<(), String> {
|
||||
let mut shift = 0;
|
||||
for item in items {
|
||||
let [x, y] = [origin_x + item.x as f64, origin_y + item.y as f64];
|
||||
let [x, y] = [origin_x + (item.x + shift) as f64, origin_y + item.y as f64];
|
||||
if virtuals.is_some() {
|
||||
shift += super::super::boxes::xdv_width_difference(&item.item);
|
||||
}
|
||||
match &item.item {
|
||||
MathItem::NativeGlyph { font, slot, .. } => {
|
||||
if let Some(packet) = virtuals
|
||||
@@ -253,7 +257,7 @@ impl Frame {
|
||||
self.expand(
|
||||
page,
|
||||
[x, y],
|
||||
font.advance(*slot),
|
||||
font.xdv_advance(*slot),
|
||||
metrics.height(character),
|
||||
metrics.depth(character),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user