Allocate indirect PDF import objects during native writes
This commit is contained in:
1 parent
5a2df6781a
commit
861c9dbfc9
14 files changed
+588
-32
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
use crate::{
|
||||
execution::format_image::{FormatImageKind, FormatPdfImage},
|
||||
pdf_image::{PageBox, PageSelection, PdfImage, PdfImageObject, PdfImageUse, XdvImagePlacement},
|
||||
pdf_image::{ImportWrite, PageBox, PageSelection, PdfImage, PdfImageObject, PdfImageUse, XdvImagePlacement},
|
||||
resources::ResourceKind,
|
||||
};
|
||||
|
||||
@@ -238,6 +238,15 @@ impl Executor {
|
||||
let mut image = PdfImageUse::new(id, image, dimensions)
|
||||
.map_err(|error| self.error(error, token.span))?;
|
||||
image.pdf_object_number = object_number;
|
||||
if pdftex && image.image.has_source_graph() {
|
||||
image.pdftex_file_name = Some(if std::path::Path::new(&filename).is_absolute()
|
||||
|| filename.starts_with("./") || filename.starts_with("../")
|
||||
{
|
||||
filename
|
||||
} else {
|
||||
format!("./{filename}")
|
||||
});
|
||||
}
|
||||
if let Some(header) = header {
|
||||
if image.image.reserves_png_group((header.major, i32::from(header.minor))) {
|
||||
image.png_group = Some(self.state.pdf_objects.as_deref_mut().expect("registered image")
|
||||
@@ -496,7 +505,7 @@ impl Executor {
|
||||
pending_xdv: None,
|
||||
});
|
||||
let hidden = special.hidden;
|
||||
self.emit_pdf_image_object(image.clone(), special.attributes, None);
|
||||
self.emit_pdf_image_object(image.clone(), special.attributes, None, None);
|
||||
Ok((!hidden).then_some(image))
|
||||
}
|
||||
|
||||
@@ -562,7 +571,24 @@ impl Executor {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.emit_pdf_image_object(image, attributes, png_auxiliary);
|
||||
let imports = if self.state.input_profile() == InputProfile::TeX8Bit
|
||||
&& let Some(header) = self.state.pdf_header_options
|
||||
&& image.image.has_source_graph()
|
||||
{
|
||||
let suppress = self.read_parameter(Parameter::Pdfsuppressptexinfo).width();
|
||||
let underscore = self.read_parameter(Parameter::Pdfptexuseunderscore).width() != 0;
|
||||
let file_name = image.pdftex_file_name.as_deref().map(std::borrow::Cow::Borrowed)
|
||||
.unwrap_or_else(|| image.image.version.path.to_string_lossy());
|
||||
self.reads.insert(Dependency::PdfObjects);
|
||||
Some(image.image.write_import(
|
||||
&file_name, suppress, underscore,
|
||||
self.state.pdf_objects.get_or_insert_with(Default::default),
|
||||
header.object_compression, self.limits.tokens,
|
||||
).map_err(|error| self.error(error, self.current))?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.emit_pdf_image_object(image, attributes, png_auxiliary, imports);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -604,6 +630,7 @@ impl Executor {
|
||||
|
||||
fn emit_pdf_image_object(
|
||||
&mut self, image: Arc<PdfImageUse>, attributes: Vec<u8>, png_auxiliary: Option<u32>,
|
||||
imports: Option<ImportWrite>,
|
||||
) {
|
||||
let compression = self
|
||||
.read_parameter(Parameter::Pdfcompresslevel)
|
||||
@@ -614,6 +641,7 @@ impl Executor {
|
||||
attributes,
|
||||
compression,
|
||||
png_auxiliary,
|
||||
imports,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 90;
|
||||
const SCHEMA: u32 = 91;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 57] = [
|
||||
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, 84, 85, 86, 87, 88, 89, SCHEMA,
|
||||
];
|
||||
@@ -194,6 +194,12 @@ impl FormatImage {
|
||||
if image.schema < 90 {
|
||||
image.state.restore_legacy_pdf_parameters(&[Parameter::Pdfdraftmode]);
|
||||
}
|
||||
if image.schema < 91 {
|
||||
image.state.restore_legacy_pdf_parameters(&[
|
||||
Parameter::Pdfsuppressptexinfo,
|
||||
Parameter::Pdfptexuseunderscore,
|
||||
]);
|
||||
}
|
||||
let pdf_objects = image.state.pdf_objects.as_deref();
|
||||
let mut numbered_images = 0;
|
||||
for (index, saved) in image.pdf_images.iter().enumerate() {
|
||||
|
||||
@@ -141,6 +141,8 @@ pub enum Parameter {
|
||||
XeTeXlinebreakpenalty,
|
||||
XeTeXinputnormalization,
|
||||
Pdfdraftmode,
|
||||
Pdfsuppressptexinfo,
|
||||
Pdfptexuseunderscore,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ParameterValue {
|
||||
@@ -157,6 +159,8 @@ impl Parameter {
|
||||
| Self::Pdfobjcompresslevel
|
||||
| Self::Pdfcompresslevel
|
||||
| Self::Pdfdraftmode
|
||||
| Self::Pdfsuppressptexinfo
|
||||
| Self::Pdfptexuseunderscore
|
||||
| Self::Pdfdecimaldigits
|
||||
| Self::Pdfpkresolution
|
||||
| Self::Pdfimageresolution
|
||||
@@ -204,6 +208,8 @@ impl Parameter {
|
||||
Self::Pdfobjcompresslevel,
|
||||
Self::Pdfcompresslevel,
|
||||
Self::Pdfdraftmode,
|
||||
Self::Pdfsuppressptexinfo,
|
||||
Self::Pdfptexuseunderscore,
|
||||
Self::Pdfdecimaldigits,
|
||||
Self::Pdfpkresolution,
|
||||
Self::Pdfimageresolution,
|
||||
|
||||
@@ -1765,6 +1765,9 @@ impl State {
|
||||
generate_unicode: self.parameter(Parameter::Pdfgentounicode).width(),
|
||||
omit_charset: self.parameter(Parameter::Pdfomitcharset).width() != 0,
|
||||
omit_info: self.parameter(Parameter::Pdfomitinfodict).width() != 0,
|
||||
ptex_banner_separator: (self.input_profile == super::InputProfile::TeX8Bit
|
||||
&& self.parameter(Parameter::Pdfsuppressptexinfo).width() & 1 == 0)
|
||||
.then(|| if self.parameter(Parameter::Pdfptexuseunderscore).width() == 0 { '.' } else { '_' }),
|
||||
glyph_unicode: &self.glyph_unicode,
|
||||
fonts: &self.fonts,
|
||||
page_tree_attributes: &self.pdf_pages_attributes,
|
||||
|
||||
Reference in new issue
Block a user