Read binary TeX inputs and render default ICC colors

This commit is contained in:
gloamxun committed 2026-11-29 02:55:37 +08:00
1 parent e9893a5c1b
commit 52db77885d
10 files changed
+379 -19

No files matched your search

@@ -786,6 +786,7 @@ pub struct PageResources {
pub(crate) has_page_group: bool,
pub(crate) opacity: BTreeMap<Vec<u8>, Transparency>,
pub(crate) needs_pdf_for_preview: bool,
pub(crate) has_default_color_spaces: bool,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
@@ -838,25 +839,27 @@ impl PageResources {
names: &BTreeSet<Vec<u8>>,
objects: &PdfObjects,
) -> Result<Self, String> {
if names.is_empty() {
return Ok(Self {
objects: allocation,
entries: bytes,
attributes,
..Self::default()
});
}
let entries = parse_entries(&bytes)?;
let definitions = entries
.get(b"ExtGState")
.map_err(|_| "PDF graphics state used without an ExtGState resource")?;
let definitions = resolve_dictionary(definitions.clone(), objects)?;
let mut resources = Self {
objects: allocation,
entries: bytes,
attributes,
..Self::default()
};
if let Ok(color_spaces) = entries.get(b"ColorSpace")
&& let Object::Dictionary(colors) = resolve_value(color_spaces.clone(), objects)?
{
resources.has_default_color_spaces = [b"DefaultGray".as_slice(), b"DefaultRGB", b"DefaultCMYK"]
.iter()
.any(|name| colors.get(name).is_ok_and(|value| !matches!(value, Object::Null)));
}
if names.is_empty() {
return Ok(resources);
}
let definitions = entries
.get(b"ExtGState")
.map_err(|_| "PDF graphics state used without an ExtGState resource")?;
let definitions = resolve_dictionary(definitions.clone(), objects)?;
for name in names {
let definition = definitions.get(name).map_err(|_| {
format!(