Restore XeTeX picture boxes at native shipout
This commit is contained in:
1 parent
c2f18f50dc
commit
9da2ee41cd
7 files changed
+305
-32
No files matched your search
@@ -413,6 +413,7 @@ impl Executor {
|
|||||||
let mut has_explicit_space = false;
|
let mut has_explicit_space = false;
|
||||||
let mut pdf_objects = Vec::new();
|
let mut pdf_objects = Vec::new();
|
||||||
let mut xdv_annotations = std::collections::BTreeMap::new();
|
let mut xdv_annotations = std::collections::BTreeMap::new();
|
||||||
|
let mut reopened_images = false;
|
||||||
for (index, output) in outputs.into_iter().enumerate() {
|
for (index, output) in outputs.into_iter().enumerate() {
|
||||||
while font_uses.peek().is_some_and(|usage| usage.before_output == index) {
|
while font_uses.peek().is_some_and(|usage| usage.before_output == index) {
|
||||||
self.current = current;
|
self.current = current;
|
||||||
@@ -604,6 +605,9 @@ impl Executor {
|
|||||||
LinkNode::Running(_) | LinkNode::Destination { .. } => {}
|
LinkNode::Running(_) | LinkNode::Destination { .. } => {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if let OutputOperation::PdfImage { image, .. } = &output.operation {
|
||||||
|
reopened_images |= image.xdv.is_some() && image.image.is_metadata_only();
|
||||||
|
}
|
||||||
self.output_node(output, files)?;
|
self.output_node(output, files)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -650,6 +654,9 @@ impl Executor {
|
|||||||
links.xdv_destinations = std::mem::take(&mut shipout.pdf_links.xdv_destinations);
|
links.xdv_destinations = std::mem::take(&mut shipout.pdf_links.xdv_destinations);
|
||||||
shipout.pdf_links = links;
|
shipout.pdf_links = links;
|
||||||
}
|
}
|
||||||
|
if reopened_images {
|
||||||
|
self.rebind_shipped_format_images(&mut shipout.box_node)?;
|
||||||
|
}
|
||||||
if xdv && (!xdv_annotations.is_empty() || self.xdv_annotations.is_active()) {
|
if xdv && (!xdv_annotations.is_empty() || self.xdv_annotations.is_active()) {
|
||||||
shipout.pdf_links.xdv_annotations = self.ship_xdv_annotations(&shipout, &xdv_annotations, files)?;
|
shipout.pdf_links.xdv_annotations = self.ship_xdv_annotations(&shipout, &xdv_annotations, files)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub(super) struct RegisteredImage {
|
|||||||
image: Arc<PdfImageUse>,
|
image: Arc<PdfImageUse>,
|
||||||
attributes: Option<Vec<Token>>,
|
attributes: Option<Vec<Token>>,
|
||||||
saved: Option<FormatPdfImage>,
|
saved: Option<FormatPdfImage>,
|
||||||
|
pending_xdv: Option<FormatImageKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Executor {
|
impl Executor {
|
||||||
@@ -23,8 +24,10 @@ impl Executor {
|
|||||||
self.pdf_images = definitions.iter().zip(images).map(|(saved, image)| {
|
self.pdf_images = definitions.iter().zip(images).map(|(saved, image)| {
|
||||||
RegisteredImage {
|
RegisteredImage {
|
||||||
image,
|
image,
|
||||||
attributes: Some(saved.attributes.clone()),
|
attributes: (!matches!(saved.kind, FormatImageKind::XdvShippedSpecial))
|
||||||
|
.then(|| saved.attributes.clone()),
|
||||||
saved: None,
|
saved: None,
|
||||||
|
pending_xdv: (!saved.kind.reads_at_load()).then_some(saved.kind),
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
self.format_image_warnings = warnings;
|
self.format_image_warnings = warnings;
|
||||||
@@ -34,7 +37,7 @@ impl Executor {
|
|||||||
pub(super) fn ensure_format_pdf_images(&self) -> Result<(), Error> {
|
pub(super) fn ensure_format_pdf_images(&self) -> Result<(), Error> {
|
||||||
for image in &self.pdf_images {
|
for image in &self.pdf_images {
|
||||||
if image.saved.is_none() {
|
if image.saved.is_none() {
|
||||||
return self.fail("cannot dump a format with XeTeX image objects");
|
return self.fail("cannot dump a format with an unrecorded image object");
|
||||||
}
|
}
|
||||||
if image.image.image.color_space.is_some() {
|
if image.image.image.color_space.is_some() {
|
||||||
return self.fail("cannot dump a format with image color-space object references");
|
return self.fail("cannot dump a format with image color-space object references");
|
||||||
@@ -230,6 +233,7 @@ impl Executor {
|
|||||||
image: Arc::new(image),
|
image: Arc::new(image),
|
||||||
attributes: Some(attributes),
|
attributes: Some(attributes),
|
||||||
saved,
|
saved,
|
||||||
|
pending_xdv: None,
|
||||||
});
|
});
|
||||||
if immediate {
|
if immediate {
|
||||||
self.declare_pdf_image(id, files)?;
|
self.declare_pdf_image(id, files)?;
|
||||||
@@ -341,7 +345,7 @@ impl Executor {
|
|||||||
return self.fail("XeTeX image is illegal in math mode");
|
return self.fail("XeTeX image is illegal in math mode");
|
||||||
}
|
}
|
||||||
let (name, from) = self.xdv_image_filename(token, files)?;
|
let (name, from) = self.xdv_image_filename(token, files)?;
|
||||||
let (image, source_origin, page) = if pdf {
|
let (image, source_origin, page, format_kind) = if pdf {
|
||||||
let page = if self.keyword("page", files)? {
|
let page = if self.keyword("page", files)? {
|
||||||
self.integer(files)?
|
self.integer(files)?
|
||||||
} else {
|
} else {
|
||||||
@@ -361,13 +365,16 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let resource = files
|
let resource = files
|
||||||
.resource(ResourceKind::Tex, &name, &from)
|
.resource(ResourceKind::PdfImage, &name, &from)
|
||||||
.map_err(|message| self.error(message, token.span))?;
|
.map_err(|message| self.error(message, token.span))?;
|
||||||
let (image, source_origin) = PdfImage::read_xdv(resource, page, box_type)
|
let (image, source_origin) = PdfImage::read_xdv(resource, page, box_type)
|
||||||
.map_err(|message| self.error(message, token.span))?;
|
.map_err(|message| self.error(message, token.span))?;
|
||||||
(Arc::new(image), source_origin, page)
|
(Arc::new(image), source_origin, page, FormatImageKind::XdvPdf { page_box: box_type })
|
||||||
} else {
|
} else {
|
||||||
(self.xdv_raster_source(&name, &from, token.span, files)?, [0.0; 2], 0)
|
(
|
||||||
|
self.xdv_raster_source(&name, &from, token.span, files)?,
|
||||||
|
[0.0; 2], 0, FormatImageKind::XdvRaster,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
let mut placement = XdvImagePlacement::new(&image, source_origin);
|
let mut placement = XdvImagePlacement::new(&image, source_origin);
|
||||||
loop {
|
loop {
|
||||||
@@ -399,10 +406,12 @@ impl Executor {
|
|||||||
let image = PdfImageUse::new_xdv(self.pdf_images.len() + 1, image, placement, page)
|
let image = PdfImageUse::new_xdv(self.pdf_images.len() + 1, image, placement, page)
|
||||||
.map_err(|message| self.error(message, token.span))?;
|
.map_err(|message| self.error(message, token.span))?;
|
||||||
let image = Arc::new(image);
|
let image = Arc::new(image);
|
||||||
|
let saved = self.state.is_initex().then(|| FormatPdfImage::capture(&image, &[], format_kind));
|
||||||
self.pdf_images.push(RegisteredImage {
|
self.pdf_images.push(RegisteredImage {
|
||||||
image: image.clone(),
|
image: image.clone(),
|
||||||
attributes: Some(Vec::new()),
|
attributes: Some(Vec::new()),
|
||||||
saved: None,
|
saved,
|
||||||
|
pending_xdv: None,
|
||||||
});
|
});
|
||||||
self.defer_image(image, token)
|
self.defer_image(image, token)
|
||||||
}
|
}
|
||||||
@@ -415,7 +424,7 @@ impl Executor {
|
|||||||
files: &mut impl SourceProvider,
|
files: &mut impl SourceProvider,
|
||||||
) -> Result<Arc<PdfImage>, Error> {
|
) -> Result<Arc<PdfImage>, Error> {
|
||||||
let resource = files
|
let resource = files
|
||||||
.resource(ResourceKind::Tex, name, from)
|
.resource(ResourceKind::PdfImage, name, from)
|
||||||
.map_err(|message| self.error(message, span))?;
|
.map_err(|message| self.error(message, span))?;
|
||||||
// A layout measurement and later shipout share the decoded pixels
|
// A layout measurement and later shipout share the decoded pixels
|
||||||
// only if the resource provider returns the same version.
|
// only if the resource provider returns the same version.
|
||||||
@@ -460,10 +469,14 @@ impl Executor {
|
|||||||
let image = special.place(self.pdf_images.len() + 1, resource)
|
let image = special.place(self.pdf_images.len() + 1, resource)
|
||||||
.map_err(|error| self.error(error, span))?;
|
.map_err(|error| self.error(error, span))?;
|
||||||
let image = Arc::new(image);
|
let image = Arc::new(image);
|
||||||
|
let saved = self.state.is_initex().then(|| {
|
||||||
|
FormatPdfImage::capture(&image, &[], FormatImageKind::XdvShippedSpecial)
|
||||||
|
});
|
||||||
self.pdf_images.push(RegisteredImage {
|
self.pdf_images.push(RegisteredImage {
|
||||||
image: image.clone(),
|
image: image.clone(),
|
||||||
attributes: None,
|
attributes: None,
|
||||||
saved: None,
|
saved,
|
||||||
|
pending_xdv: None,
|
||||||
});
|
});
|
||||||
let hidden = special.hidden;
|
let hidden = special.hidden;
|
||||||
self.emit_pdf_image_object(image.clone(), special.attributes);
|
self.emit_pdf_image_object(image.clone(), special.attributes);
|
||||||
@@ -476,6 +489,9 @@ impl Executor {
|
|||||||
pub(super) fn declare_pdf_image(
|
pub(super) fn declare_pdf_image(
|
||||||
&mut self, id: usize, files: &mut impl SourceProvider,
|
&mut self, id: usize, files: &mut impl SourceProvider,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
if let Some(kind) = self.pdf_images[id - 1].pending_xdv {
|
||||||
|
self.open_format_xdv_image(id, kind, files)?;
|
||||||
|
}
|
||||||
let registered = &mut self.pdf_images[id - 1];
|
let registered = &mut self.pdf_images[id - 1];
|
||||||
let Some(tokens) = registered.attributes.take() else {
|
let Some(tokens) = registered.attributes.take() else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -519,6 +535,42 @@ impl Executor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_format_xdv_image(
|
||||||
|
&mut self,
|
||||||
|
id: usize,
|
||||||
|
kind: FormatImageKind,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let saved = &self.pdf_images[id - 1].image;
|
||||||
|
let path = saved.image.version.path.to_string_lossy();
|
||||||
|
let from = self.source_name(self.current);
|
||||||
|
self.reads.insert(Dependency::FileLookup {
|
||||||
|
name: path.to_string(),
|
||||||
|
from: from.clone(),
|
||||||
|
});
|
||||||
|
let resource = files.resource(ResourceKind::PdfImage, &path, &from)
|
||||||
|
.map_err(|message| self.error(message, self.current))?;
|
||||||
|
let page = saved.xdv.as_ref().expect("registered XDV placement").page_request;
|
||||||
|
let actual = match kind {
|
||||||
|
FormatImageKind::XdvPdf { page_box } => {
|
||||||
|
PdfImage::read_xdv(resource, page, page_box).map(|(image, _)| image)
|
||||||
|
}
|
||||||
|
FormatImageKind::XdvRaster => PdfImage::read_xdv_raster(resource),
|
||||||
|
_ => return self.fail("missing saved XDV image declaration"),
|
||||||
|
}.map_err(|message| self.error(message, self.current))?;
|
||||||
|
let placed = Arc::new(saved.with_current_xdv_image(actual));
|
||||||
|
let registered = &mut self.pdf_images[id - 1];
|
||||||
|
registered.image = placed;
|
||||||
|
registered.pending_xdv = None;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn rebind_shipped_format_images(&self, b: &mut NativeBox) -> Result<(), Error> {
|
||||||
|
let images: Vec<_> = self.pdf_images.iter().map(|entry| entry.image.clone()).collect();
|
||||||
|
crate::execution::format_image::boxes::rebind(b, &images)
|
||||||
|
.map_err(|message| self.error(message, b.span))
|
||||||
|
}
|
||||||
|
|
||||||
fn emit_pdf_image_object(&mut self, image: Arc<PdfImageUse>, attributes: Vec<u8>) {
|
fn emit_pdf_image_object(&mut self, image: Arc<PdfImageUse>, attributes: Vec<u8>) {
|
||||||
let compression = self
|
let compression = self
|
||||||
.read_parameter(Parameter::Pdfcompresslevel)
|
.read_parameter(Parameter::Pdfcompresslevel)
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ use std::{
|
|||||||
sync::{Arc, Mutex, OnceLock, Weak},
|
sync::{Arc, Mutex, OnceLock, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCHEMA: u32 = 83;
|
const SCHEMA: u32 = 84;
|
||||||
const COMPATIBLE_SCHEMAS: [u32; 50] = [
|
const COMPATIBLE_SCHEMAS: [u32; 51] = [
|
||||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, SCHEMA,
|
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, SCHEMA,
|
||||||
];
|
];
|
||||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
@@ -191,17 +191,22 @@ impl FormatImage {
|
|||||||
Parameter::Pdfoptionalwaysusepdfpagebox,
|
Parameter::Pdfoptionalwaysusepdfpagebox,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if !image.pdf_images.is_empty() && (image.schema < 83
|
for (index, saved) in image.pdf_images.iter().enumerate() {
|
||||||
|| image.state.input_profile() != InputProfile::TeX8Bit
|
let valid_profile = if saved.kind.reads_at_load() {
|
||||||
|| image.pdf_images.iter().enumerate().any(|(index, saved)| {
|
image.schema >= 83 && image.state.input_profile() == InputProfile::TeX8Bit
|
||||||
saved.image.id != index + 1
|
&& saved.image.xdv.is_none()
|
||||||
|| saved.image.xdv.is_some()
|
} else {
|
||||||
|
image.schema >= 84 && image.state.input_profile() == InputProfile::XeTeX
|
||||||
|
&& saved.image.xdv.is_some()
|
||||||
|
};
|
||||||
|
if !valid_profile
|
||||||
|
|| saved.image.id != index + 1
|
||||||
|| saved.image.image.color_space.is_some()
|
|| saved.image.image.color_space.is_some()
|
||||||
|| saved.image.image.version.path.as_os_str().is_empty()
|
|| saved.path().as_os_str().is_empty()
|
||||||
}))
|
|
||||||
{
|
{
|
||||||
return Err("invalid native format image registry".into());
|
return Err("invalid native format image registry".into());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
image.schema = SCHEMA;
|
image.schema = SCHEMA;
|
||||||
Ok(image)
|
Ok(image)
|
||||||
}
|
}
|
||||||
@@ -304,6 +309,10 @@ impl FormatImage {
|
|||||||
let mut images = Vec::with_capacity(self.pdf_images.len());
|
let mut images = Vec::with_capacity(self.pdf_images.len());
|
||||||
let mut warnings = Vec::new();
|
let mut warnings = Vec::new();
|
||||||
for saved in &self.pdf_images {
|
for saved in &self.pdf_images {
|
||||||
|
if !saved.kind.reads_at_load() {
|
||||||
|
images.push(saved.image.clone());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let path = saved.path();
|
let path = saved.path();
|
||||||
let bytes = read(files, path).map_err(|error| image_read_error(path, error))?;
|
let bytes = read(files, path).map_err(|error| image_read_error(path, error))?;
|
||||||
let image = saved.restore(&self.state, bytes.as_ref(), &mut warnings)
|
let image = saved.restore(&self.state, bytes.as_ref(), &mut warnings)
|
||||||
@@ -363,7 +372,7 @@ impl FormatImage {
|
|||||||
// Include each current image version in the host's checkpoint guard.
|
// Include each current image version in the host's checkpoint guard.
|
||||||
// The checkpoint owns the decoded payload and can only be reused when
|
// The checkpoint owns the decoded payload and can only be reused when
|
||||||
// that guard accepts these actual reads.
|
// that guard accepts these actual reads.
|
||||||
for saved in &self.pdf_images {
|
for saved in self.pdf_images.iter().filter(|saved| saved.kind.reads_at_load()) {
|
||||||
let path = saved.path();
|
let path = saved.path();
|
||||||
read(files, path).map_err(|error| image_read_error(path, error))?;
|
read(files, path).map_err(|error| image_read_error(path, error))?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,28 @@
|
|||||||
use super::digest;
|
use super::digest;
|
||||||
use crate::{
|
use crate::{
|
||||||
execution::{Parameter, State, Token},
|
execution::{Parameter, State, Token},
|
||||||
pdf_image::{PdfImage, PdfImageUse},
|
pdf_image::{PageBox, PdfImage, PdfImageUse},
|
||||||
resources::{LoadedResource, ResourceVersion},
|
resources::{LoadedResource, ResourceVersion},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{path::Path, sync::Arc};
|
use std::{path::Path, sync::Arc};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub(in crate::execution) enum FormatImageKind {
|
pub(in crate::execution) enum FormatImageKind {
|
||||||
Pdf { page_box: i32, remap_type1: bool },
|
Pdf { page_box: i32, remap_type1: bool },
|
||||||
Png,
|
Png,
|
||||||
Jpeg,
|
Jpeg,
|
||||||
|
XdvPdf { page_box: PageBox },
|
||||||
|
XdvRaster,
|
||||||
|
// An earlier shipout may have allocated a device slot. Its original
|
||||||
|
// special remains a special in saved boxes and runs again if shipped.
|
||||||
|
XdvShippedSpecial,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FormatImageKind {
|
||||||
|
pub(in crate::execution) fn reads_at_load(self) -> bool {
|
||||||
|
matches!(self, Self::Pdf { .. } | Self::Png | Self::Jpeg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
@@ -87,6 +98,8 @@ impl FormatPdfImage {
|
|||||||
}
|
}
|
||||||
image
|
image
|
||||||
}
|
}
|
||||||
|
FormatImageKind::XdvPdf { .. } | FormatImageKind::XdvRaster
|
||||||
|
| FormatImageKind::XdvShippedSpecial => return Err("XDV images require shipout".into()),
|
||||||
};
|
};
|
||||||
Ok(Arc::new(PdfImageUse {
|
Ok(Arc::new(PdfImageUse {
|
||||||
image: Arc::new(image),
|
image: Arc::new(image),
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub(crate) enum PageSelection {
|
|||||||
Named(Vec<u8>),
|
Named(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
pub(crate) enum PageBox {
|
pub(crate) enum PageBox {
|
||||||
Media = 1,
|
Media = 1,
|
||||||
@@ -72,6 +72,8 @@ pub(crate) struct XdvPdfPlacement {
|
|||||||
pub(crate) page_request: i32,
|
pub(crate) page_request: i32,
|
||||||
matrix: [u64; 6],
|
matrix: [u64; 6],
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
raster_source_matrix: Option<[u64; 6]>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
clip: Option<[u64; 4]>,
|
clip: Option<[u64; 4]>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
annotation_box: Option<[u64; 4]>,
|
annotation_box: Option<[u64; 4]>,
|
||||||
@@ -174,15 +176,10 @@ impl PdfImageUse {
|
|||||||
.parse()
|
.parse()
|
||||||
.expect("printed 16.16 value")
|
.expect("printed 16.16 value")
|
||||||
});
|
});
|
||||||
let matrix = if image.raster_frame().is_some() {
|
let raster_source_matrix = image.raster_frame().is_some().then_some(matrix);
|
||||||
let [width, height] = image.extent();
|
let matrix = raster_source_matrix.map_or(matrix, |matrix| {
|
||||||
Affine(matrix)
|
Self::scale_xdv_raster(matrix, image.extent())
|
||||||
.concatenate(Affine([width, 0.0, 0.0, height, 0.0, 0.0]))
|
});
|
||||||
.0
|
|
||||||
.map(|value| (value * 100_000.0).round() / 100_000.0)
|
|
||||||
} else {
|
|
||||||
matrix
|
|
||||||
};
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
image,
|
image,
|
||||||
@@ -192,6 +189,7 @@ impl PdfImageUse {
|
|||||||
xdv: Some(XdvPdfPlacement {
|
xdv: Some(XdvPdfPlacement {
|
||||||
page_request,
|
page_request,
|
||||||
matrix: matrix.map(f64::to_bits),
|
matrix: matrix.map(f64::to_bits),
|
||||||
|
raster_source_matrix: raster_source_matrix.map(|matrix| matrix.map(f64::to_bits)),
|
||||||
clip: None,
|
clip: None,
|
||||||
annotation_box: None,
|
annotation_box: None,
|
||||||
layout_offset: [0, 0],
|
layout_offset: [0, 0],
|
||||||
@@ -237,6 +235,7 @@ impl PdfImageUse {
|
|||||||
xdv: Some(XdvPdfPlacement {
|
xdv: Some(XdvPdfPlacement {
|
||||||
page_request: 0,
|
page_request: 0,
|
||||||
matrix: matrix.map(f64::to_bits),
|
matrix: matrix.map(f64::to_bits),
|
||||||
|
raster_source_matrix: None,
|
||||||
clip: clip.map(|rect| rect.map(f64::to_bits)),
|
clip: clip.map(|rect| rect.map(f64::to_bits)),
|
||||||
annotation_box: annotation_box.map(|rect| rect.map(f64::to_bits)),
|
annotation_box: annotation_box.map(|rect| rect.map(f64::to_bits)),
|
||||||
layout_offset: [left as i64, bottom as i64],
|
layout_offset: [left as i64, bottom as i64],
|
||||||
@@ -244,6 +243,25 @@ impl PdfImageUse {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn scale_xdv_raster(matrix: [f64; 6], [width, height]: [f64; 2]) -> [f64; 6] {
|
||||||
|
Affine(matrix)
|
||||||
|
.concatenate(Affine([width, 0.0, 0.0, height, 0.0, 0.0]))
|
||||||
|
.0
|
||||||
|
.map(|value| (value * 100_000.0).round() / 100_000.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn with_current_xdv_image(&self, image: PdfImage) -> Self {
|
||||||
|
let mut placed = self.clone();
|
||||||
|
if let Some(placement) = &mut placed.xdv
|
||||||
|
&& let Some(matrix) = placement.raster_source_matrix
|
||||||
|
{
|
||||||
|
placement.matrix = Self::scale_xdv_raster(matrix.map(f64::from_bits), image.extent())
|
||||||
|
.map(f64::to_bits);
|
||||||
|
}
|
||||||
|
placed.image = Arc::new(image);
|
||||||
|
placed
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn dimensions(&self) -> (i64, i64, i64) {
|
pub(crate) fn dimensions(&self) -> (i64, i64, i64) {
|
||||||
(self.width, self.height, self.depth)
|
(self.width, self.height, self.depth)
|
||||||
}
|
}
|
||||||
@@ -356,6 +374,10 @@ pub(crate) fn real(value: f64) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PdfImage {
|
impl PdfImage {
|
||||||
|
pub(crate) fn is_metadata_only(&self) -> bool {
|
||||||
|
self.objects.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn without_payload(&self) -> Self {
|
pub(crate) fn without_payload(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
version: self.version.clone(),
|
version: self.version.clone(),
|
||||||
|
|||||||
@@ -689,6 +689,29 @@ xdvipdfmx 生成两页 PDF。原生停在转储。另一个确实加载了 OpenT
|
|||||||
并装箱文字的原版 INITEX 作业拒绝转储。两组独立记录分别保存在
|
并装箱文字的原版 INITEX 作业拒绝转储。两组独立记录分别保存在
|
||||||
`target/p3-format-images/next-xetex-image` 和 `next-xetex-font`。
|
`target/p3-format-images/next-xetex-image` 和 `next-xetex-font`。
|
||||||
|
|
||||||
|
### XeTeX 格式图像盒在实际发页时读取
|
||||||
|
|
||||||
|
schema84 保存图像盒原尺寸、数字页选择、页框和实际 XDV 放置变换。
|
||||||
|
发页使用该盒时才从宿主读取当前图像,镜像重载无需打开未用的图像。
|
||||||
|
栅格图替换后按当前图片的尺寸还原缩放后的绘制矩阵,盒子的 TeX 尺寸
|
||||||
|
保持转储值。已在转储作业发页的显式图片指令只保留所属登记槽位,
|
||||||
|
保存盒子里的同类指令在新作业发页时实际执行。旧 schema83 实例重新
|
||||||
|
加载并生成两页。
|
||||||
|
|
||||||
|
用 XeTeX 0.999998 与 xdvipdfmx 对照真实转储和重开。四个用例的七页
|
||||||
|
原始图像、替换 PDF、改变 PNG 像素尺寸以及未使用图像缺失,连同嵌套盒、
|
||||||
|
leaders 和转储前已发页的图像指令三个用例,共十页 144 DPI 灰度图逐
|
||||||
|
像素相同。另一用例删除实际发页的图片,原版驱动和原生发页均失败。
|
||||||
|
原生项目会话在图片修改后仍从未读取图片的前缀续跑,只更新第二页,
|
||||||
|
PDF、SVG 和逐页来源映射与独立全量相同。六项图像回归通过。
|
||||||
|
|
||||||
|
附带 `pdf:pagesize` 的首次探测保留实际的设备指令缺口。图像专项独立使用
|
||||||
|
默认纸张。原版另已验证相对图片路径随作业目录迁移,原生格式继续按实际
|
||||||
|
已解析路径校验和读取,跨目录格式迁移仍待实现。正式出版模板矩阵与
|
||||||
|
分规模实时性能按功能接齐后统一验收。
|
||||||
|
|
||||||
|
回执 `target/p3-format-xdv-images/receipt.json` 的 SHA-256 为 `152fe604aefb4a47e52d41e556cb674e7e19e7388447f18338840898afc3495a`。
|
||||||
|
|
||||||
### PDF 预览按实际页面资源复用
|
### PDF 预览按实际页面资源复用
|
||||||
|
|
||||||
编译会话的 SVG 缓存采用预览读取器解析出的页面、有效页框、旋转和资源。
|
编译会话的 SVG 缓存采用预览读取器解析出的页面、有效页框、旋转和资源。
|
||||||
|
|||||||
@@ -585,3 +585,150 @@ fn format_image_resource_edits_invalidate_checkpoints_and_update_the_picture_pag
|
|||||||
);
|
);
|
||||||
fs::remove_dir_all(root).unwrap();
|
fs::remove_dir_all(root).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn xetex_format_reads_only_shipped_images_and_reuses_the_unaffected_prefix() {
|
||||||
|
use image::ImageEncoder;
|
||||||
|
use texrra_engine::native::dump_format;
|
||||||
|
use texrra_tex_core::{
|
||||||
|
execution::{Cancellation, InputProfile},
|
||||||
|
render::DisplayItem,
|
||||||
|
};
|
||||||
|
|
||||||
|
let root = std::env::temp_dir().join(format!("texrra-xdv-format-image-{}", std::process::id()));
|
||||||
|
fs::create_dir(&root).unwrap();
|
||||||
|
let root = root.canonicalize().unwrap();
|
||||||
|
let seed = root.join("seed.tex");
|
||||||
|
let format = root.join("seed.tfx");
|
||||||
|
let entry = root.join("entry.tex");
|
||||||
|
let used = root.join("used.png");
|
||||||
|
let unused = root.join("unused.png");
|
||||||
|
|
||||||
|
let encode = |w: u32, h: u32, color: u8| -> Arc<[u8]> {
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
image::codecs::png::PngEncoder::new(&mut bytes)
|
||||||
|
.write_image(&vec![color; (w * h) as usize], w, h, image::ColorType::L8)
|
||||||
|
.unwrap();
|
||||||
|
bytes.into()
|
||||||
|
};
|
||||||
|
let original = encode(2, 1, 35);
|
||||||
|
fs::write(&used, &original).unwrap();
|
||||||
|
fs::write(&unused, &original).unwrap();
|
||||||
|
fs::write(
|
||||||
|
&seed,
|
||||||
|
r#"\catcode123=1 \catcode125=2
|
||||||
|
\setbox0=\hbox{\XeTeXpicfile "used.png" width 40pt}
|
||||||
|
\setbox1=\hbox{\XeTeXpicfile "unused.png" width 25pt}
|
||||||
|
\dump
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let world = WorldConfig::new(&root);
|
||||||
|
let time = JobTime::new(2026, 11, 27, 0).unwrap();
|
||||||
|
let mut request = CompileRequest::new(world.clone(), &seed, &format, time);
|
||||||
|
request.entry = Entry::Initex;
|
||||||
|
request.input_profile = InputProfile::XeTeX;
|
||||||
|
request.etex = true;
|
||||||
|
dump_format(request, Cancellation::default()).unwrap();
|
||||||
|
fs::remove_file(&unused).unwrap();
|
||||||
|
|
||||||
|
let prefix = "\\shipout\\hbox{\\vrule width10pt height4pt}\n";
|
||||||
|
let padding = format!("{}\n", "\\relax ".repeat(32)).repeat(48);
|
||||||
|
let source = format!("{prefix}{padding}\\shipout\\copy0\\end\n");
|
||||||
|
let snapshot = ProjectSnapshot::new(ProjectDefinition {
|
||||||
|
configuration: world.clone(),
|
||||||
|
revision: 1,
|
||||||
|
roots: [root.clone()].into(),
|
||||||
|
files: [
|
||||||
|
(seed.clone(), fs::read(seed).unwrap().into()),
|
||||||
|
(format.clone(), fs::read(&format).unwrap().into()),
|
||||||
|
(entry.clone(), source.into_bytes().into()),
|
||||||
|
(used.clone(), original),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
|
directories: Default::default(),
|
||||||
|
aliases: Default::default(),
|
||||||
|
generated_roots: [root.clone()].into(),
|
||||||
|
generated: Default::default(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let mut request = CompileRequest::new(world, entry, "entry.pdf", time);
|
||||||
|
request.entry = Entry::Format(format);
|
||||||
|
request.input_profile = InputProfile::XeTeX;
|
||||||
|
request.etex = true;
|
||||||
|
let compiler = NativeCompiler::default().with_entry_checkpoints(prefix.len() + 60);
|
||||||
|
let first = compiler
|
||||||
|
.compile(request.clone().with_project(snapshot.clone()))
|
||||||
|
.unwrap();
|
||||||
|
let snapshot = snapshot
|
||||||
|
.with_file_edits(2, [(used.clone(), encode(5, 3, 180))].into())
|
||||||
|
.unwrap();
|
||||||
|
let revised = request.with_project(snapshot);
|
||||||
|
let next = compiler.compile(revised.clone()).unwrap();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
next.entry_checkpoint_work.reused_steps > 0,
|
||||||
|
"{:?}",
|
||||||
|
next.entry_checkpoint_work
|
||||||
|
);
|
||||||
|
let delta = next.preview_since(Some(first.revision())).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
delta
|
||||||
|
.pages
|
||||||
|
.iter()
|
||||||
|
.map(|page| page.index)
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
[1]
|
||||||
|
);
|
||||||
|
for result in [&first, &next] {
|
||||||
|
let reads = &result.resources.trace.reads;
|
||||||
|
assert!(!reads.iter().any(|version| version.path == unused));
|
||||||
|
let image = result.pages[1]
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.find_map(|item| match item {
|
||||||
|
DisplayItem::PdfImage {
|
||||||
|
image,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
assert_eq!((*width, *height), (2_621_440, 1_310_720));
|
||||||
|
Some(image)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(image.image.version.path, used);
|
||||||
|
assert!(reads.contains(&image.image.version));
|
||||||
|
}
|
||||||
|
assert_ne!(first.pdf, next.pdf);
|
||||||
|
let pdf = Document::load_mem(next.pdf.as_deref().unwrap()).unwrap();
|
||||||
|
assert!(
|
||||||
|
pdf.objects
|
||||||
|
.values()
|
||||||
|
.filter_map(|object| object.as_stream().ok())
|
||||||
|
.any(|image| {
|
||||||
|
image
|
||||||
|
.dict
|
||||||
|
.get(b"Width")
|
||||||
|
.ok()
|
||||||
|
.and_then(|value| value.as_i64().ok())
|
||||||
|
== Some(5)
|
||||||
|
&& image
|
||||||
|
.dict
|
||||||
|
.get(b"Height")
|
||||||
|
.ok()
|
||||||
|
.and_then(|value| value.as_i64().ok())
|
||||||
|
== Some(3)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
let full = NativeCompiler::default().compile(revised).unwrap();
|
||||||
|
assert_eq!(next.pdf, full.pdf);
|
||||||
|
assert_eq!(next.source_map.pages, full.source_map.pages);
|
||||||
|
assert_eq!(
|
||||||
|
next.preview_since(None).unwrap().pages,
|
||||||
|
full.preview_since(None).unwrap().pages
|
||||||
|
);
|
||||||
|
fs::remove_dir_all(root).unwrap();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user