Share pdfTeX image and page object numbers

This commit is contained in:
gloamxun committed 2026-11-27 15:54:24 +08:00
1 parent 57a7097857
commit d12c4b034b
11 files changed
+321 -62

No files matched your search

+9 -3
View File
@@ -184,8 +184,9 @@ impl SampledImage {
compression: u8,
pdf_version: (i32, i32),
color_space: Option<i64>,
target: Option<usize>,
) -> usize {
let id = pdf.len() + 1;
let id = target.unwrap_or(pdf.len() + 1);
let [width, height] = self.size;
let mut color = match (color_space, &self.color) {
(Some(id), _) => format!("{id} 0 R"),
@@ -202,7 +203,8 @@ impl SampledImage {
};
let has_alpha = self.has_alpha(pdf_version);
if has_alpha {
write!(color, " /SMask {} 0 R", id + 1).expect("writing to a string");
let mask = pdf.len() + 1 + usize::from(target.is_none());
write!(color, " /SMask {mask} 0 R").expect("writing to a string");
}
let strip_16 = pdf_version < (1, 5) && self.depth == 16;
let reduced;
@@ -221,7 +223,11 @@ impl SampledImage {
// Image attributes are TeX printer bytes and may be non-UTF-8.
stream.splice(3..3, attributes.iter().copied().chain([b'\n']));
}
pdf.push(stream);
if target.is_some() {
pdf[id - 1] = stream;
} else {
pdf.push(stream);
}
if has_alpha {
pdf.push(objects::stream(
&format!(