Emit native PDF page resources and named transparency states
This commit is contained in:
1 parent
2bced813a2
commit
4f4a4567ea
23 files changed
+791
-37
No files matched your search
@@ -1098,6 +1098,7 @@ pub fn display_lists_to_pdf_with_paper(
|
||||
&PdfMetadata::default(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&mut Vec::new(),
|
||||
)
|
||||
}
|
||||
@@ -1130,6 +1131,7 @@ pub fn display_lists_to_pdf_with_cm_type1(
|
||||
&PdfMetadata::default(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&mut Vec::new(),
|
||||
)
|
||||
}
|
||||
@@ -1249,6 +1251,24 @@ fn native_pdf(
|
||||
{
|
||||
return Err("invalid native PDF final stream compression level".into());
|
||||
}
|
||||
let raw_objects = unicode.and_then(|options| options.objects);
|
||||
let resources = if raw_objects.is_some()
|
||||
|| pages.iter().any(|page| !page.pdf_resources.entries.is_empty())
|
||||
{
|
||||
let (catalog, info) = if raw_objects.is_some() {
|
||||
(
|
||||
unicode.and_then(|options| options.catalog).map(|catalog| catalog.entries.as_slice()),
|
||||
unicode.map(|options| options.info.entries),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
Some(crate::pdf_device::page_resources::ResourceOutput::prepare(
|
||||
pages, raw_objects, catalog, info,
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut diagnostics = Vec::new();
|
||||
let bytes = write_pdf(
|
||||
pages,
|
||||
@@ -1259,6 +1279,7 @@ fn native_pdf(
|
||||
&PdfMetadata::default(),
|
||||
final_compression,
|
||||
unicode,
|
||||
resources,
|
||||
&mut diagnostics,
|
||||
);
|
||||
Ok(NativePdfDocument { bytes, diagnostics })
|
||||
@@ -1281,6 +1302,7 @@ pub fn display_lists_to_pdf_with_truetype_and_metadata(
|
||||
metadata,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&mut Vec::new(),
|
||||
)
|
||||
}
|
||||
@@ -1302,6 +1324,7 @@ pub fn display_lists_to_pdf_with_cm_type1_and_metadata(
|
||||
metadata,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&mut Vec::new(),
|
||||
)
|
||||
}
|
||||
@@ -1745,6 +1768,7 @@ fn write_pdf(
|
||||
metadata: &PdfMetadata,
|
||||
final_compression: Option<i32>,
|
||||
unicode: Option<crate::pdf_unicode::PdfFinalOptions<'_>>,
|
||||
resources: Option<crate::pdf_device::page_resources::ResourceOutput>,
|
||||
diagnostics: &mut Vec<String>,
|
||||
) -> Vec<u8> {
|
||||
let width = page_width;
|
||||
@@ -1991,6 +2015,7 @@ fn write_pdf(
|
||||
font_ids[slot] = write_type0_font(&mut objects, face, slot, &used_chars[slot]);
|
||||
}
|
||||
|
||||
let remapped = resources.map(|resources| resources.append(&mut objects));
|
||||
let mut kids = Vec::new();
|
||||
let mut page_ids: Vec<usize> = Vec::new();
|
||||
let mut destinations = BTreeMap::new();
|
||||
@@ -2017,7 +2042,7 @@ fn write_pdf(
|
||||
}
|
||||
}
|
||||
}
|
||||
for list in pages {
|
||||
for (page_index, list) in pages.iter().enumerate() {
|
||||
let width = if final_compression.is_some() {
|
||||
list.width
|
||||
} else {
|
||||
@@ -2118,14 +2143,21 @@ fn write_pdf(
|
||||
};
|
||||
page_ids.push(page_id);
|
||||
kids.push(format!("{page_id} 0 R"));
|
||||
objects.push(
|
||||
format!(
|
||||
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 {} {}] /Resources {resources}{annots} /Contents {content_id} 0 R >>",
|
||||
physical(width),
|
||||
physical(height)
|
||||
)
|
||||
.into_bytes(),
|
||||
);
|
||||
let mut page = format!(
|
||||
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 {} {}] /Resources ",
|
||||
physical(width), physical(height),
|
||||
).into_bytes();
|
||||
if let Some(additional) = remapped.as_ref().map(|resources| &resources.pages[page_index])
|
||||
&& !additional.is_empty()
|
||||
{
|
||||
page.extend_from_slice(&resources.as_bytes()[..resources.len() - 2]);
|
||||
page.extend_from_slice(additional);
|
||||
page.extend_from_slice(b" >>");
|
||||
} else {
|
||||
page.extend_from_slice(resources.as_bytes());
|
||||
}
|
||||
page.extend_from_slice(format!("{annots} /Contents {content_id} 0 R >>").as_bytes());
|
||||
objects.push(page);
|
||||
|
||||
let mut names = BTreeMap::new();
|
||||
for (index, slot) in &used {
|
||||
@@ -2352,9 +2384,11 @@ fn write_pdf(
|
||||
}
|
||||
let mut catalog = catalog.into_bytes();
|
||||
if let Some(extra) = extra {
|
||||
if !extra.entries.is_empty() {
|
||||
let entries = remapped.as_ref().and_then(|resources| resources.catalog.as_deref())
|
||||
.unwrap_or(&extra.entries);
|
||||
if !entries.is_empty() {
|
||||
catalog.push(b'\n');
|
||||
catalog.extend_from_slice(&extra.entries);
|
||||
catalog.extend_from_slice(entries);
|
||||
catalog.push(b'\n');
|
||||
}
|
||||
if let Some(id) = action {
|
||||
@@ -2366,7 +2400,11 @@ fn write_pdf(
|
||||
|
||||
if let Some(level) = final_compression {
|
||||
let info = match unicode {
|
||||
Some(options) => native_information_dictionary(options.info),
|
||||
Some(options) => native_information_dictionary(crate::pdf_device::PdfInfo {
|
||||
entries: remapped.as_ref().and_then(|resources| resources.info.as_deref())
|
||||
.unwrap_or(options.info.entries),
|
||||
date: options.info.date,
|
||||
}),
|
||||
None => metadata_object(metadata)
|
||||
.map(String::into_bytes)
|
||||
.unwrap_or_else(|| b"<< /Producer (texrra Route-D native) >>".to_vec()),
|
||||
|
||||
Reference in new issue
Block a user