Promote verified native PDF and box capacity support
This commit is contained in:
1 parent
3706afa483
commit
72ed779749
31 files changed
+1042
-78
No files matched your search
@@ -850,13 +850,19 @@ fn page_content(
|
||||
height: image_height,
|
||||
image,
|
||||
} => {
|
||||
let [sx, sy] = if list.units == crate::render::DisplayUnits::TeX {
|
||||
let [sx, sy] = if image.image.jpeg_frame().is_some()
|
||||
&& list.units == crate::render::DisplayUnits::TeX
|
||||
{
|
||||
[
|
||||
crate::pdf_device::print_sp(*width, 4),
|
||||
crate::pdf_device::print_sp(*image_height, 4),
|
||||
]
|
||||
} else if list.units == crate::render::DisplayUnits::TeX {
|
||||
let [natural_width, natural_height] = image.image.natural;
|
||||
// pdfTeX out_image prints a six-decimal ratio of scaled
|
||||
// dimensions, while translation follows pdfdecimaldigits.
|
||||
let scale = |placed, natural| {
|
||||
let (coefficient, _) =
|
||||
crate::pdf_device::divide_scaled(placed, i64::from(natural), 6);
|
||||
let (coefficient, _) = crate::pdf_device::divide_scaled(placed, natural, 6);
|
||||
crate::pdf_device::print_decimal(coefficient, 6)
|
||||
};
|
||||
[
|
||||
@@ -1007,6 +1013,36 @@ fn metadata_object(metadata: &PdfMetadata) -> Option<String> {
|
||||
Some(format!("<< {} >>", fields.join(" ")))
|
||||
}
|
||||
|
||||
fn native_information_dictionary(info: crate::pdf_device::PdfInfo<'_>) -> Vec<u8> {
|
||||
// pdfTeX suppresses defaults based on the raw byte spelling anywhere in
|
||||
// the expanded list. Preserve the supplied PDF syntax verbatim.
|
||||
let supplied = |key: &[u8]| info.entries.windows(key.len()).any(|value| value == key);
|
||||
let mut object = b"<<\n".to_vec();
|
||||
if !supplied(b"/Producer") {
|
||||
object.extend_from_slice(b"/Producer (texrra Route-D native)\n");
|
||||
}
|
||||
if !info.entries.is_empty() {
|
||||
object.extend_from_slice(info.entries);
|
||||
object.push(b'\n');
|
||||
}
|
||||
if !supplied(b"/Creator") {
|
||||
object.extend_from_slice(b"/Creator (TeX)\n");
|
||||
}
|
||||
if let Some(date) = info.date {
|
||||
for key in ["CreationDate", "ModDate"] {
|
||||
let name = format!("/{key}");
|
||||
if !supplied(name.as_bytes()) {
|
||||
writeln!(&mut object, "{name} ({date})").unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
if !supplied(b"/Trapped") {
|
||||
object.extend_from_slice(b"/Trapped /False\n");
|
||||
}
|
||||
object.extend_from_slice(b">>");
|
||||
object
|
||||
}
|
||||
|
||||
/// Write several display lists as a multi-page PDF at the default page origin.
|
||||
pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec<u8> {
|
||||
display_lists_to_pdf_with_origin(pages, page_height, PageOrigin::default())
|
||||
@@ -2207,6 +2243,22 @@ fn write_pdf(
|
||||
catalog.extend_from_slice(b" >>");
|
||||
objects[0] = catalog;
|
||||
|
||||
if let Some(level) = final_compression {
|
||||
let info = match unicode {
|
||||
Some(options) => native_information_dictionary(options.info),
|
||||
None => metadata_object(metadata)
|
||||
.map(String::into_bytes)
|
||||
.unwrap_or_else(|| b"<< /Producer (texrra Route-D native) >>".to_vec()),
|
||||
};
|
||||
objects.push(info);
|
||||
let options = &pages[0]
|
||||
.pdf
|
||||
.as_ref()
|
||||
.expect("validated native PDF options")
|
||||
.file;
|
||||
return objects::serialize(&objects, Some(objects.len()), options, level.max(0).min(9) as u8);
|
||||
}
|
||||
|
||||
let info_ref = match metadata_object(metadata) {
|
||||
Some(object) => {
|
||||
objects.push(object.into_bytes());
|
||||
@@ -2214,22 +2266,6 @@ fn write_pdf(
|
||||
}
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
if let Some(level) = final_compression {
|
||||
let info = if info_ref.is_empty() {
|
||||
objects.push(b"<< /Producer (texrra Route-D native) >>".to_vec());
|
||||
Some(objects.len())
|
||||
} else {
|
||||
Some(objects.len())
|
||||
};
|
||||
let options = &pages[0]
|
||||
.pdf
|
||||
.as_ref()
|
||||
.expect("validated native PDF options")
|
||||
.file;
|
||||
return objects::serialize(&objects, info, options, level.max(0).min(9) as u8);
|
||||
}
|
||||
|
||||
let mut pdf: Vec<u8> = b"%PDF-1.4\n".to_vec();
|
||||
let mut offsets = Vec::new();
|
||||
for (index, object) in objects.iter().enumerate() {
|
||||
|
||||
Reference in new issue
Block a user