Allocate native PNG transparency and palette objects
This commit is contained in:
1 parent
51451813dc
commit
342bedf9b4
9 files changed
+215
-29
No files matched your search
@@ -2297,7 +2297,7 @@ fn write_pdf(
|
||||
// retains its measured source image and can precede that registration.
|
||||
let declarations = paint_lists.iter().flat_map(|list| &list.items).filter_map(|item| {
|
||||
if let DisplayItem::PdfImageObject(object) = item {
|
||||
Some((object.image.as_ref(), object.attributes.as_slice(), object.compression))
|
||||
Some((object.image.as_ref(), object.attributes.as_slice(), object.compression, object.png_auxiliary))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -2306,7 +2306,7 @@ fn write_pdf(
|
||||
let compression = list.pdf.as_ref().map_or(0, |pdf| pdf.stream_compression);
|
||||
list.items.iter().filter_map(move |item| {
|
||||
if let DisplayItem::PdfImage { image, .. } = item {
|
||||
Some((image.as_ref(), &[][..], compression))
|
||||
Some((image.as_ref(), &[][..], compression, None))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -2321,7 +2321,7 @@ fn write_pdf(
|
||||
let mut type1_plans = type1_fonts::FontPlans::default();
|
||||
// pdfTeX collects included font descriptors as it writes forms. The
|
||||
// TeX font dictionaries and their glyph marks are finalized afterward.
|
||||
for (image, _, _) in &images {
|
||||
for (image, ..) in &images {
|
||||
for font in image.image.mapped_type1_fonts() {
|
||||
type1_plans.include(font);
|
||||
}
|
||||
@@ -2547,6 +2547,16 @@ fn write_pdf(
|
||||
objects.push(Vec::new());
|
||||
device_objects.insert(number, objects.len() as u32);
|
||||
}
|
||||
const PNG_GROUP: &[u8] = b"<< /Type /Group /S /Transparency /CS /DeviceRGB /I true >>";
|
||||
if let Some(registry) = registry {
|
||||
for number in registry.png_object_numbers() {
|
||||
objects.push(Vec::new());
|
||||
device_objects.insert(number, objects.len() as u32);
|
||||
}
|
||||
if let Some(group) = registry.written_png_group() {
|
||||
objects[device_objects[&group] as usize - 1] = PNG_GROUP.to_vec();
|
||||
}
|
||||
}
|
||||
let parents: BTreeSet<_> = pages.iter().filter_map(|page| {
|
||||
page.pdf_resources.objects.map(|allocation| allocation.parent)
|
||||
}).collect();
|
||||
@@ -2590,8 +2600,12 @@ fn write_pdf(
|
||||
.and_then(|page| page.pdf.as_ref())
|
||||
.map_or((1, 4), |pdf| (pdf.file.major, i32::from(pdf.file.minor)));
|
||||
let mut unwritten_color_spaces = BTreeMap::new();
|
||||
let form_ids: BTreeMap<_, _> = images.into_iter().map(|(image, attributes, compression)| {
|
||||
let target = image.pdf_object_number.map(|number| device_objects[&number] as usize);
|
||||
let form_ids: BTreeMap<_, _> = images.into_iter().map(|(image, attributes, compression, auxiliary)| {
|
||||
let physical = |number: u32| device_objects[&number] as usize;
|
||||
let targets = crate::pdf_image::PdfImageTargets {
|
||||
image: image.pdf_object_number.map(physical),
|
||||
png_auxiliary: auxiliary.map(physical),
|
||||
};
|
||||
let color_space = image.image.color_space.map(|number| {
|
||||
let Ok(reference) = u32::try_from(number) else {
|
||||
return i64::from(number);
|
||||
@@ -2607,7 +2621,7 @@ fn write_pdf(
|
||||
})
|
||||
});
|
||||
let object = image.image.append_to(
|
||||
&mut objects, attributes, compression, pdf_version, &type1_references, color_space, target,
|
||||
&mut objects, attributes, compression, pdf_version, &type1_references, color_space, targets,
|
||||
);
|
||||
(image.id, object)
|
||||
}).collect();
|
||||
@@ -2714,14 +2728,17 @@ fn write_pdf(
|
||||
}
|
||||
let mut png_group = None;
|
||||
for (page_index, list) in pages.iter().enumerate() {
|
||||
let png_group_ref = if !list.pdf_resources.has_page_group
|
||||
let png_group_ref = if let Some(page) = list.pdf_resources.objects {
|
||||
page.png_group.map(|group| format!(" /Group {} 0 R", device_objects[&group]))
|
||||
.unwrap_or_default()
|
||||
} else if !list.pdf_resources.has_page_group
|
||||
&& list.items.iter().any(|item| {
|
||||
matches!(item, DisplayItem::PdfImage { image, .. }
|
||||
if image.image.png_transparency(pdf_version))
|
||||
})
|
||||
{
|
||||
let id = *png_group.get_or_insert_with(|| {
|
||||
objects.push(b"<< /Type /Group /S /Transparency /CS /DeviceRGB /I true >>".to_vec());
|
||||
objects.push(PNG_GROUP.to_vec());
|
||||
objects.len()
|
||||
});
|
||||
format!(" /Group {id} 0 R")
|
||||
|
||||
Reference in new issue
Block a user