Write native XDV PDF versions and compact object streams

This commit is contained in:
gloamxun committed 2026-11-29 05:21:01 +08:00
1 parent 48d42052b8
commit b37856eeb0
7 files changed
+102 -20

No files matched your search

@@ -11,6 +11,8 @@ pub(crate) struct Setup {
major: Option<i32>,
minor: Option<u8>,
pub(crate) keep_destinations: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
no_object_streams: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) outline_open_depth: Option<usize>,
#[serde(default, skip_serializing_if = "super::xdv_paper::Paper::is_default")]
@@ -76,23 +78,28 @@ impl Setup {
};
let flags =
u32::from_str_radix(digits, radix).map_err(|_| "invalid XDV configuration flags")?;
if flags & !0x10 != 0 {
const KEEP_DESTINATIONS: u32 = 0x10;
const NO_OBJECT_STREAMS: u32 = 0x40;
if flags & !(KEEP_DESTINATIONS | NO_OBJECT_STREAMS) != 0 {
return Err("unsupported XDV configuration flags".into());
}
if (sign < 0 && flags != 0) || flags & 0x10 != 0 {
self.keep_destinations = flags & 0x10 != 0;
if sign < 0 && flags != 0 {
self.keep_destinations = false;
self.no_object_streams = false;
}
self.keep_destinations |= flags & KEEP_DESTINATIONS != 0;
self.no_object_streams |= flags & NO_OBJECT_STREAMS != 0;
Ok(())
}
pub(crate) fn apply_version(&self, options: &mut PdfFileOptions) {
pub(crate) fn apply_file_options(&self, options: &mut PdfFileOptions) {
if let Some(value) = self.major {
options.major = value;
}
if let Some(value) = self.minor {
options.minor = value;
}
if options.major == 1 && options.minor < 5 {
if self.no_object_streams || (options.major == 1 && options.minor < 5) {
options.object_compression = 0;
}
}