From 9d0821ba8b4cddaf45ccdcf12666a577181cf5dd Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:06:35 +0800 Subject: [PATCH 01/12] M11: PDF/A verify reports transfer functions, halftones and rendering intents a graphics state may not use (6.2.5) A graphics state may not have /TR, may have /TR2 only as /Default, may use halftones of type 1 or 5 only and without /HalftoneName (also the colorant halftones of a type 5 one), and a rendering intent from ISO 32000-1 Table 70. Graphics states are read from every /ExtGState resource dictionary and from shading patterns. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/gstate.rs | 136 +++++++++++++++++++++++++++++++++ crates/preflight/src/lib.rs | 23 ++++++ crates/preflight/src/tests.rs | 49 ++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 crates/preflight/src/gstate.rs diff --git a/crates/preflight/src/gstate.rs b/crates/preflight/src/gstate.rs new file mode 100644 index 0000000000..e34b444079 --- /dev/null +++ b/crates/preflight/src/gstate.rs @@ -0,0 +1,136 @@ +//! PDF/A-2 6.2.5, the extended graphics state: device-dependent settings a conforming file may not +//! rely on. +//! +//! - no transfer function: no `/TR` entry, and `/TR2` only as `/Default` (ISO 32000-1 10.4); +//! - halftones of type 1 or 5 only, without a `/HalftoneName` (ISO 32000-1 10.5.5); the halftones +//! a type 5 halftone holds for its colorants are checked the same way; +//! - a rendering intent (`/RI`) that is one of the four of ISO 32000-1 8.6.5.8, Table 70. +//! +//! Graphics state dictionaries are found as the entries of every `/ExtGState` resource +//! dictionary, and as the `/ExtGState` of a shading pattern (ISO 32000-1 8.7.4.3, Table 76), +//! direct or by reference. + +use std::collections::BTreeSet; + +use pdfcraft_cos::{Dict, Document, ObjRef, Object}; + +/// How deep a direct object is followed: as deep as the parser nests them. +const MAX_DEPTH: u8 = 128; +/// The rendering intents of ISO 32000-1 Table 70. +const INTENTS: [&[u8]; 4] = [b"AbsoluteColorimetric", b"RelativeColorimetric", b"Saturation", b"Perceptual"]; +/// The entries of a type 5 halftone that aren't colorant halftones. +const HALFTONE_KEYS: [&[u8]; 3] = [b"Type", b"HalftoneType", b"HalftoneName"]; + +/// What the graphics states of a document break of 6.2.5. +#[derive(Debug, Default, PartialEq, Eq)] +pub(crate) struct Findings { + /// A graphics state has a `/TR` entry. + pub(crate) transfer: bool, + /// A graphics state has a `/TR2` other than `/Default`. + pub(crate) transfer2: bool, + /// Halftone types other than 1 and 5, in order. + pub(crate) halftone_types: BTreeSet, + /// A halftone has a `/HalftoneName`. + pub(crate) halftone_name: bool, + /// Rendering intents outside Table 70, in name order. + pub(crate) intents: BTreeSet, +} + +/// The 6.2.5 findings over the indirect objects `objs`. +pub(crate) fn check(doc: &Document, objs: &[(ObjRef, std::sync::Arc)]) -> Findings { + let mut scan = Scan { doc, findings: Findings::default() }; + for (_, o) in objs { + scan.walk(o, 0); + } + scan.findings +} + +struct Scan<'a> { + doc: &'a Document, + findings: Findings, +} + +impl Scan<'_> { + fn walk(&mut self, o: &Object, depth: u8) { + if depth > MAX_DEPTH { + return; + } + let entries: Box> = match o { + Object::Array(a) => Box::new(a.iter()), + Object::Dict(d) => { + self.dict(d); + Box::new(d.iter().map(|(_, v)| v)) + } + Object::Stream(s) => { + self.dict(&s.dict); + Box::new(s.dict.iter().map(|(_, v)| v)) + } + _ => return, + }; + for v in entries { + self.walk(v, depth.saturating_add(1)); + } + } + + /// A dictionary that holds graphics states: a shading pattern its one, resources by name. + fn dict(&mut self, d: &Dict) { + let Some(states) = d.get(b"ExtGState").map(|s| self.doc.resolve(s)) else { return }; + let Some(states) = states.as_dict() else { return }; + if d.get(b"PatternType").is_some() { + self.gstate(states); + return; + } + for (_, gs) in states.iter() { + if let Some(gs) = self.doc.resolve(gs).as_dict() { + self.gstate(gs); + } + } + } + + fn gstate(&mut self, gs: &Dict) { + let doc = self.doc; + let present = |k: &[u8]| gs.get(k).map(|v| doc.resolve(v)).filter(|v| !matches!(**v, Object::Null)); + if present(b"TR").is_some() { + self.findings.transfer = true; + } + if present(b"TR2").is_some_and(|f| f.as_name() != Some(b"Default")) { + self.findings.transfer2 = true; + } + if let Some(ht) = present(b"HT") + && let Some(ht) = ht.as_dict() + { + self.halftone(ht, true); + } + if let Some(ri) = present(b"RI") + && let Some(ri) = ri.as_name() + && !INTENTS.contains(&ri) + { + self.findings.intents.insert(String::from_utf8_lossy(ri).into_owned()); + } + } + + /// A halftone dictionary or stream; `top` when it isn't one a type 5 halftone holds, whose + /// own entries are halftones in turn. + fn halftone(&mut self, ht: &Dict, top: bool) { + let kind = ht.get(b"HalftoneType").and_then(|t| self.doc.resolve(t).as_int()); + if let Some(kind) = kind + && kind != 1 + && kind != 5 + { + self.findings.halftone_types.insert(kind); + } + if ht.get(b"HalftoneName").is_some() { + self.findings.halftone_name = true; + } + if top && kind == Some(5) { + for (k, v) in ht.iter() { + if HALFTONE_KEYS.contains(&k.as_slice()) { + continue; + } + if let Some(component) = self.doc.resolve(v).as_dict() { + self.halftone(component, false); + } + } + } + } +} diff --git a/crates/preflight/src/lib.rs b/crates/preflight/src/lib.rs index 1df39ebf05..10bbfca8a9 100644 --- a/crates/preflight/src/lib.rs +++ b/crates/preflight/src/lib.rs @@ -21,6 +21,7 @@ #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] +mod gstate; pub mod icc; mod xmp; @@ -121,6 +122,11 @@ pub const WORDINGS: &[&str] = &[ "DeviceRGB is used, but the PDF/A output intent isn't an RGB profile", "The document has additional actions (/AA)", "The document has document-level JavaScript", + "A graphics state has a transfer function (TR)", + "A graphics state has a transfer function (TR2) other than Default", + "A halftone has type {}: only types 1 and 5 are allowed", + "A halftone has a HalftoneName", + "A graphics state has the rendering intent {}, which isn't a standard one", "The form asks viewers to make appearances (NeedAppearances)", // Pages, actions, annotations and fields. "Page {} has additional actions", @@ -515,6 +521,23 @@ pub fn verify(doc: &Document, level: Level) -> Vec { } } check_objects(doc, level, &objs, &page_of, &mut issue); + // 6.2.5: the extended graphics state. + let gs = gstate::check(doc, &objs); + if gs.transfer { + issue("6.2.5", "A graphics state has a transfer function (TR)", None, None, false); + } + if gs.transfer2 { + issue("6.2.5", "A graphics state has a transfer function (TR2) other than Default", None, None, false); + } + for kind in gs.halftone_types { + issue("6.2.5", "A halftone has type {}: only types 1 and 5 are allowed", Some(kind.to_string()), None, false); + } + if gs.halftone_name { + issue("6.2.5", "A halftone has a HalftoneName", None, None, false); + } + for intent in gs.intents { + issue("6.2.5", "A graphics state has the rendering intent {}, which isn't a standard one", Some(intent), None, false); + } // One message per kind of problem is enough for repeated ones (as preflight summaries do). let mut seen = std::collections::HashSet::new(); out.retain(|i| seen.insert((i.clause, i.message.clone(), i.page))); diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index 52e6903e60..3285ebc35f 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -488,3 +488,52 @@ fn an_output_intent_profile_header_is_read_within_a_size_cap() { assert_eq!(pdfa_intent_profile(&doc), Some(n), "a {size}-byte profile"); } } + +/// PDF/A-2 6.2.5: a graphics state has no transfer function, halftones of type 1 or 5 without a +/// name, and a standard rendering intent, wherever it is kept. +#[test] +fn extended_graphics_states_are_checked() { + let gs = |states: &str| -> Vec { + let page = format!("<< /Type /Page /Parent 2 0 R /Resources << /ExtGState << {states} >> >> >>"); + let doc = build( + &[ + "<< /Type /Catalog /Pages 2 0 R >>", + "<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 200 200] >>", + &page, + "<< /FunctionType 2 /Domain [0 1] /C0 [0] /C1 [1] /N 1 >>", + "<< /HalftoneType 1 /Frequency 60 /Angle 45 /SpotFunction /Round >>", + "<< /TR 4 0 R >>", + "<< /Type /Halftone /HalftoneType 6 /Width 2 /Height 2 /Length 4 >>\nstream\nabcd\nendstream", + ], + "", + ); + verify(&doc, Level::A2b).into_iter().filter(|i| i.clause == "6.2.5").map(|i| i.message).collect() + }; + let tr = "A graphics state has a transfer function (TR)"; + let tr2 = "A graphics state has a transfer function (TR2) other than Default"; + let name = "A halftone has a HalftoneName"; + // What 6.2.5 allows. + assert!(gs("/A << /TR2 /Default /HT 5 0 R /RI /Perceptual >> /B << /HT /Default /RI /AbsoluteColorimetric >>").is_empty()); + assert!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Cyan 5 0 R >> /RI /Saturation >> /B << /TR null >>").is_empty()); + // Transfer functions. + assert_eq!(gs("/A << /TR 4 0 R >>"), [tr]); + assert_eq!(gs("/A << /TR /Identity >>"), [tr]); + assert_eq!(gs("/A 6 0 R"), [tr]); + assert_eq!(gs("/A << /TR2 4 0 R >>"), [tr2]); + assert_eq!(gs("/A << /TR2 /Identity >>"), [tr2]); + // Halftones: the type, also of a type 5 halftone's colorants and of a stream, and the name. + assert_eq!(gs("/A << /HT << /HalftoneType 6 >> >>"), ["A halftone has type 6: only types 1 and 5 are allowed"]); + assert_eq!(gs("/A << /HT 7 0 R >>"), ["A halftone has type 6: only types 1 and 5 are allowed"]); + assert_eq!( + gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Magenta << /HalftoneType 10 >> >> >>"), + ["A halftone has type 10: only types 1 and 5 are allowed"] + ); + assert_eq!(gs("/A << /HT << /HalftoneType 1 /HalftoneName (Screen) >> >>"), [name]); + assert_eq!(gs("/A << /HT << /HalftoneType 5 /Default << /HalftoneType 1 /HalftoneName (S) >> >> >>"), [name]); + // Rendering intents. + assert_eq!(gs("/A << /RI /Custom >>"), ["A graphics state has the rendering intent Custom, which isn't a standard one"]); + // A shading pattern holds one graphics state, not a dictionary of them. + let pattern = |gs: &str| format!("/A << /RI /Perceptual >> >> /Pattern << /P << /PatternType 2 /Shading << /ShadingType 2 >> /ExtGState {gs} >>"); + assert_eq!(gs(&pattern("<< /TR 4 0 R >>")), [tr]); + assert!(gs(&pattern("<< /HT << /HalftoneType 1 >> >>")).is_empty()); +} From 77ffebf7bd59389b4577ece8e197847c59d5f2a6 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:07:04 +0800 Subject: [PATCH 02/12] M11: parity: PDF/A verify checks graphics states (6.2.5) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- parity/acrobat-features.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 252fb43fd2..0acb1cba0b 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -7943,8 +7943,8 @@ milestone = "M11" status = "partial" commands = ["standards.pdfa"] tools = ["pdfa_verify"] -evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] -notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." +evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/preflight/src/tests.rs::extended_graphics_states_are_checked", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] +notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: transfer functions, halftones, rendering intents), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." [[feature]] id = "optimize.pdfa-convert" From 5874e5205572cc3a6d54a1f25bac1ff2d48299ff Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:11:58 +0800 Subject: [PATCH 03/12] M11: PDF/A verify reports a halftone phase (HTP) in a graphics state (6.2.5) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/gstate.rs | 6 ++++++ crates/preflight/src/lib.rs | 4 ++++ crates/preflight/src/tests.rs | 1 + 3 files changed, 11 insertions(+) diff --git a/crates/preflight/src/gstate.rs b/crates/preflight/src/gstate.rs index e34b444079..ea0f9e569f 100644 --- a/crates/preflight/src/gstate.rs +++ b/crates/preflight/src/gstate.rs @@ -2,6 +2,7 @@ //! rely on. //! //! - no transfer function: no `/TR` entry, and `/TR2` only as `/Default` (ISO 32000-1 10.4); +//! - no `/HTP` (halftone phase) entry, a PDF 1.2 key ISO 32000-1 no longer defines; //! - halftones of type 1 or 5 only, without a `/HalftoneName` (ISO 32000-1 10.5.5); the halftones //! a type 5 halftone holds for its colorants are checked the same way; //! - a rendering intent (`/RI`) that is one of the four of ISO 32000-1 8.6.5.8, Table 70. @@ -28,6 +29,8 @@ pub(crate) struct Findings { pub(crate) transfer: bool, /// A graphics state has a `/TR2` other than `/Default`. pub(crate) transfer2: bool, + /// A graphics state has an `/HTP`. + pub(crate) phase: bool, /// Halftone types other than 1 and 5, in order. pub(crate) halftone_types: BTreeSet, /// A halftone has a `/HalftoneName`. @@ -96,6 +99,9 @@ impl Scan<'_> { if present(b"TR2").is_some_and(|f| f.as_name() != Some(b"Default")) { self.findings.transfer2 = true; } + if present(b"HTP").is_some() { + self.findings.phase = true; + } if let Some(ht) = present(b"HT") && let Some(ht) = ht.as_dict() { diff --git a/crates/preflight/src/lib.rs b/crates/preflight/src/lib.rs index 10bbfca8a9..3886a5181a 100644 --- a/crates/preflight/src/lib.rs +++ b/crates/preflight/src/lib.rs @@ -124,6 +124,7 @@ pub const WORDINGS: &[&str] = &[ "The document has document-level JavaScript", "A graphics state has a transfer function (TR)", "A graphics state has a transfer function (TR2) other than Default", + "A graphics state has a halftone phase (HTP)", "A halftone has type {}: only types 1 and 5 are allowed", "A halftone has a HalftoneName", "A graphics state has the rendering intent {}, which isn't a standard one", @@ -529,6 +530,9 @@ pub fn verify(doc: &Document, level: Level) -> Vec { if gs.transfer2 { issue("6.2.5", "A graphics state has a transfer function (TR2) other than Default", None, None, false); } + if gs.phase { + issue("6.2.5", "A graphics state has a halftone phase (HTP)", None, None, false); + } for kind in gs.halftone_types { issue("6.2.5", "A halftone has type {}: only types 1 and 5 are allowed", Some(kind.to_string()), None, false); } diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index 3285ebc35f..b35f490157 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -521,6 +521,7 @@ fn extended_graphics_states_are_checked() { assert_eq!(gs("/A 6 0 R"), [tr]); assert_eq!(gs("/A << /TR2 4 0 R >>"), [tr2]); assert_eq!(gs("/A << /TR2 /Identity >>"), [tr2]); + assert_eq!(gs("/A << /HTP [0 1] >>"), ["A graphics state has a halftone phase (HTP)"]); // Halftones: the type, also of a type 5 halftone's colorants and of a stream, and the name. assert_eq!(gs("/A << /HT << /HalftoneType 6 >> >>"), ["A halftone has type 6: only types 1 and 5 are allowed"]); assert_eq!(gs("/A << /HT 7 0 R >>"), ["A halftone has type 6: only types 1 and 5 are allowed"]); From 869df9f2a3b4e98e05ed59e428131e6d28bfb5eb Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:12:11 +0800 Subject: [PATCH 04/12] M11: parity: PDF/A graphics state notes name what 6.2.5 covers Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- parity/acrobat-features.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 0acb1cba0b..c76ebeeae4 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -7944,7 +7944,7 @@ status = "partial" commands = ["standards.pdfa"] tools = ["pdfa_verify"] evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/preflight/src/tests.rs::extended_graphics_states_are_checked", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] -notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: transfer functions, halftones, rendering intents), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." +notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: TR, TR2, HTP, halftone types and names, rendering intents; the TransferFunction of type 5 halftone components is not yet checked), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." [[feature]] id = "optimize.pdfa-convert" From cdc27e538c8e05b31bbc6749d591d6ed69f804b9 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:33:05 +0800 Subject: [PATCH 05/12] M11: PDF/A verify reads graphics states from resources only and checks halftone transfer functions (6.2.5) Graphics states come from /Resources and /DR entries and from shading patterns, never from private /PieceInfo data, and maps shared by reference are read once. A halftone without a /HalftoneType, a rendering intent that isn't a name, and a halftone /TransferFunction where it isn't allowed or is missing (non-primary colorants of a type 5 halftone need one; ISO 32000-1 Table 130) are reported. A null entry counts as absent. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/gstate.rs | 158 +++++++++++++++++++++++---------- crates/preflight/src/lib.rs | 16 ++++ crates/preflight/src/tests.rs | 18 +++- 3 files changed, 144 insertions(+), 48 deletions(-) diff --git a/crates/preflight/src/gstate.rs b/crates/preflight/src/gstate.rs index ea0f9e569f..fe26bbc830 100644 --- a/crates/preflight/src/gstate.rs +++ b/crates/preflight/src/gstate.rs @@ -5,13 +5,18 @@ //! - no `/HTP` (halftone phase) entry, a PDF 1.2 key ISO 32000-1 no longer defines; //! - halftones of type 1 or 5 only, without a `/HalftoneName` (ISO 32000-1 10.5.5); the halftones //! a type 5 halftone holds for its colorants are checked the same way; +//! - a halftone's `/TransferFunction` only where one is needed: a type 5 halftone's component for +//! a non-primary colorant has one, and no other halftone does. The primary colorants are those +//! of DeviceCMYK; the `Default` component is left as it is (ISO 32000-1 10.5.5.6, Table 130); //! - a rendering intent (`/RI`) that is one of the four of ISO 32000-1 8.6.5.8, Table 70. //! -//! Graphics state dictionaries are found as the entries of every `/ExtGState` resource -//! dictionary, and as the `/ExtGState` of a shading pattern (ISO 32000-1 8.7.4.3, Table 76), -//! direct or by reference. +//! Graphics state dictionaries are found as the `/ExtGState` entries of resource dictionaries +//! (`/Resources` of pages, forms, Type 3 fonts, patterns and annotation appearances, and an +//! interactive form's `/DR`), and as the `/ExtGState` of a shading pattern (ISO 32000-1 8.7.4.3, +//! Table 76). Private application data (`/PieceInfo`) isn't read. A map shared by reference is +//! read once. -use std::collections::BTreeSet; +use std::collections::{BTreeSet, HashSet}; use pdfcraft_cos::{Dict, Document, ObjRef, Object}; @@ -21,6 +26,10 @@ const MAX_DEPTH: u8 = 128; const INTENTS: [&[u8]; 4] = [b"AbsoluteColorimetric", b"RelativeColorimetric", b"Saturation", b"Perceptual"]; /// The entries of a type 5 halftone that aren't colorant halftones. const HALFTONE_KEYS: [&[u8]; 3] = [b"Type", b"HalftoneType", b"HalftoneName"]; +/// The primary colorants, whose halftones take the graphics state's transfer function. +const PRIMARY: [&[u8]; 4] = [b"Cyan", b"Magenta", b"Yellow", b"Black"]; +/// The entries that hold resource dictionaries. +const RESOURCES: [&[u8]; 2] = [b"Resources", b"DR"]; /// What the graphics states of a document break of 6.2.5. #[derive(Debug, Default, PartialEq, Eq)] @@ -33,15 +42,23 @@ pub(crate) struct Findings { pub(crate) phase: bool, /// Halftone types other than 1 and 5, in order. pub(crate) halftone_types: BTreeSet, + /// A halftone has no `/HalftoneType` integer. + pub(crate) untyped: bool, /// A halftone has a `/HalftoneName`. pub(crate) halftone_name: bool, + /// A halftone that may not have a `/TransferFunction` has one. + pub(crate) halftone_transfer: bool, + /// Non-primary colorants whose halftone has no `/TransferFunction`, in name order. + pub(crate) missing_transfer: BTreeSet, /// Rendering intents outside Table 70, in name order. pub(crate) intents: BTreeSet, + /// A rendering intent isn't a name. + pub(crate) intent_not_name: bool, } /// The 6.2.5 findings over the indirect objects `objs`. pub(crate) fn check(doc: &Document, objs: &[(ObjRef, std::sync::Arc)]) -> Findings { - let mut scan = Scan { doc, findings: Findings::default() }; + let mut scan = Scan { doc, read: HashSet::new(), findings: Findings::default() }; for (_, o) in objs { scan.walk(o, 0); } @@ -50,6 +67,8 @@ pub(crate) fn check(doc: &Document, objs: &[(ObjRef, std::sync::Arc)]) - struct Scan<'a> { doc: &'a Document, + /// Resource dictionaries, `/ExtGState` maps and graphics states read so far, by reference. + read: HashSet, findings: Findings, } @@ -58,83 +77,128 @@ impl Scan<'_> { if depth > MAX_DEPTH { return; } - let entries: Box> = match o { - Object::Array(a) => Box::new(a.iter()), - Object::Dict(d) => { - self.dict(d); - Box::new(d.iter().map(|(_, v)| v)) - } - Object::Stream(s) => { - self.dict(&s.dict); - Box::new(s.dict.iter().map(|(_, v)| v)) + let d = match o { + Object::Array(a) => { + for v in a { + self.walk(v, depth.saturating_add(1)); + } + return; } + Object::Dict(d) => d, + Object::Stream(s) => &s.dict, _ => return, }; - for v in entries { - self.walk(v, depth.saturating_add(1)); + self.holder(d); + for (k, v) in d.iter() { + if k.as_slice() != b"PieceInfo" { + self.walk(v, depth.saturating_add(1)); + } } } - /// A dictionary that holds graphics states: a shading pattern its one, resources by name. - fn dict(&mut self, d: &Dict) { - let Some(states) = d.get(b"ExtGState").map(|s| self.doc.resolve(s)) else { return }; - let Some(states) = states.as_dict() else { return }; - if d.get(b"PatternType").is_some() { - self.gstate(states); + /// Whether `o` is a reference read before; marks it read. + fn read_before(&mut self, o: &Object) -> bool { + matches!(o, Object::Ref(r) if !self.read.insert(*r)) + } + + /// A dictionary that holds graphics states: through its resources, or as a shading pattern. + fn holder(&mut self, d: &Dict) { + for key in RESOURCES { + if let Some(resources) = d.get(key) { + self.resources(resources); + } + } + if d.get(b"PatternType").is_some() + && let Some(gs) = d.get(b"ExtGState") + && !self.read_before(gs) + && let Some(gs) = self.doc.resolve(gs).as_dict() + { + self.gstate(gs); + } + } + + fn resources(&mut self, resources: &Object) { + if self.read_before(resources) { return; } + let resources = self.doc.resolve(resources); + let Some(states) = resources.as_dict().and_then(|r| r.get(b"ExtGState")) else { return }; + if self.read_before(states) { + return; + } + let states = self.doc.resolve(states); + let Some(states) = states.as_dict() else { return }; for (_, gs) in states.iter() { - if let Some(gs) = self.doc.resolve(gs).as_dict() { + if !self.read_before(gs) + && let Some(gs) = self.doc.resolve(gs).as_dict() + { self.gstate(gs); } } } + /// `key` of `d`, resolved, unless it is missing or null (ISO 32000-1 7.3.9). + fn present(&self, d: &Dict, key: &[u8]) -> Option> { + d.get(key).map(|v| self.doc.resolve(v)).filter(|v| !matches!(**v, Object::Null)) + } + fn gstate(&mut self, gs: &Dict) { - let doc = self.doc; - let present = |k: &[u8]| gs.get(k).map(|v| doc.resolve(v)).filter(|v| !matches!(**v, Object::Null)); - if present(b"TR").is_some() { + if self.present(gs, b"TR").is_some() { self.findings.transfer = true; } - if present(b"TR2").is_some_and(|f| f.as_name() != Some(b"Default")) { + if self.present(gs, b"TR2").is_some_and(|f| f.as_name() != Some(b"Default")) { self.findings.transfer2 = true; } - if present(b"HTP").is_some() { + if self.present(gs, b"HTP").is_some() { self.findings.phase = true; } - if let Some(ht) = present(b"HT") + if let Some(ht) = self.present(gs, b"HT") && let Some(ht) = ht.as_dict() { - self.halftone(ht, true); + self.halftone(ht, None); } - if let Some(ri) = present(b"RI") - && let Some(ri) = ri.as_name() - && !INTENTS.contains(&ri) - { - self.findings.intents.insert(String::from_utf8_lossy(ri).into_owned()); + if let Some(ri) = self.present(gs, b"RI") { + match ri.as_name() { + Some(ri) if !INTENTS.contains(&ri) => { + self.findings.intents.insert(String::from_utf8_lossy(ri).into_owned()); + } + Some(_) => {} + None => self.findings.intent_not_name = true, + } } } - /// A halftone dictionary or stream; `top` when it isn't one a type 5 halftone holds, whose - /// own entries are halftones in turn. - fn halftone(&mut self, ht: &Dict, top: bool) { - let kind = ht.get(b"HalftoneType").and_then(|t| self.doc.resolve(t).as_int()); - if let Some(kind) = kind - && kind != 1 - && kind != 5 - { - self.findings.halftone_types.insert(kind); + /// A halftone dictionary or stream: the graphics state's own (`colorant` is `None`), or the + /// one a type 5 halftone holds for `colorant`. + fn halftone(&mut self, ht: &Dict, colorant: Option<&[u8]>) { + let kind = self.present(ht, b"HalftoneType").and_then(|t| t.as_int()); + match kind { + None => self.findings.untyped = true, + Some(1 | 5) => {} + Some(kind) => { + self.findings.halftone_types.insert(kind); + } } - if ht.get(b"HalftoneName").is_some() { + if self.present(ht, b"HalftoneName").is_some() { self.findings.halftone_name = true; } - if top && kind == Some(5) { + let transfer = self.present(ht, b"TransferFunction").is_some(); + match colorant { + Some(b"Default") => {} + Some(c) if !PRIMARY.contains(&c) => { + if !transfer { + self.findings.missing_transfer.insert(String::from_utf8_lossy(c).into_owned()); + } + } + _ => self.findings.halftone_transfer |= transfer, + } + if colorant.is_none() && kind == Some(5) { for (k, v) in ht.iter() { if HALFTONE_KEYS.contains(&k.as_slice()) { continue; } if let Some(component) = self.doc.resolve(v).as_dict() { - self.halftone(component, false); + self.halftone(component, Some(k)); } } } diff --git a/crates/preflight/src/lib.rs b/crates/preflight/src/lib.rs index 3886a5181a..667896c2e7 100644 --- a/crates/preflight/src/lib.rs +++ b/crates/preflight/src/lib.rs @@ -126,8 +126,12 @@ pub const WORDINGS: &[&str] = &[ "A graphics state has a transfer function (TR2) other than Default", "A graphics state has a halftone phase (HTP)", "A halftone has type {}: only types 1 and 5 are allowed", + "A halftone has no HalftoneType", "A halftone has a HalftoneName", + "A halftone has a transfer function, which only a non-primary colorant's halftone may have", + "The halftone for the colorant {} has no transfer function", "A graphics state has the rendering intent {}, which isn't a standard one", + "A graphics state has a rendering intent that isn't a name", "The form asks viewers to make appearances (NeedAppearances)", // Pages, actions, annotations and fields. "Page {} has additional actions", @@ -536,12 +540,24 @@ pub fn verify(doc: &Document, level: Level) -> Vec { for kind in gs.halftone_types { issue("6.2.5", "A halftone has type {}: only types 1 and 5 are allowed", Some(kind.to_string()), None, false); } + if gs.untyped { + issue("6.2.5", "A halftone has no HalftoneType", None, None, false); + } if gs.halftone_name { issue("6.2.5", "A halftone has a HalftoneName", None, None, false); } + if gs.halftone_transfer { + issue("6.2.5", "A halftone has a transfer function, which only a non-primary colorant's halftone may have", None, None, false); + } + for colorant in gs.missing_transfer { + issue("6.2.5", "The halftone for the colorant {} has no transfer function", Some(colorant), None, false); + } for intent in gs.intents { issue("6.2.5", "A graphics state has the rendering intent {}, which isn't a standard one", Some(intent), None, false); } + if gs.intent_not_name { + issue("6.2.5", "A graphics state has a rendering intent that isn't a name", None, None, false); + } // One message per kind of problem is enough for repeated ones (as preflight summaries do). let mut seen = std::collections::HashSet::new(); out.retain(|i| seen.insert((i.clause, i.message.clone(), i.page))); diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index b35f490157..9590054184 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -507,7 +507,8 @@ fn extended_graphics_states_are_checked() { ], "", ); - verify(&doc, Level::A2b).into_iter().filter(|i| i.clause == "6.2.5").map(|i| i.message).collect() + let issues = verify(&doc, Level::A2b).into_iter().filter(|i| i.clause == "6.2.5"); + issues.inspect(|i| assert!(!i.fixable, "{}", i.message)).map(|i| i.message).collect() }; let tr = "A graphics state has a transfer function (TR)"; let tr2 = "A graphics state has a transfer function (TR2) other than Default"; @@ -533,6 +534,21 @@ fn extended_graphics_states_are_checked() { assert_eq!(gs("/A << /HT << /HalftoneType 5 /Default << /HalftoneType 1 /HalftoneName (S) >> >> >>"), [name]); // Rendering intents. assert_eq!(gs("/A << /RI /Custom >>"), ["A graphics state has the rendering intent Custom, which isn't a standard one"]); + assert_eq!(gs("/A << /RI (Perceptual) >>"), ["A graphics state has a rendering intent that isn't a name"]); + // A halftone's type is required; a null name is no name. + assert_eq!(gs("/A << /HT << /Frequency 60 >> >>"), ["A halftone has no HalftoneType"]); + assert!(gs("/A << /HT << /HalftoneType 1 /HalftoneName null >> >>").is_empty()); + // Transfer functions in halftones: only, and always, for a non-primary colorant. + let in_halftone = "A halftone has a transfer function, which only a non-primary colorant's halftone may have"; + assert_eq!(gs("/A << /HT << /HalftoneType 1 /TransferFunction 4 0 R >> >>"), [in_halftone]); + assert_eq!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Cyan << /HalftoneType 1 /TransferFunction /Identity >> >> >>"), [in_halftone]); + assert_eq!( + gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Spot 5 0 R /Red 5 0 R >> >>"), + ["The halftone for the colorant Red has no transfer function", "The halftone for the colorant Spot has no transfer function"] + ); + assert!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Black 5 0 R /Spot << /HalftoneType 1 /TransferFunction 4 0 R >> >> >>").is_empty()); + // Private application data isn't graphics resources. + assert!(gs("/A << /RI /Perceptual >> >> /PieceInfo << /App << /Private << /ExtGState << /X << /TR 4 0 R >> >> >> >> >>").is_empty()); // A shading pattern holds one graphics state, not a dictionary of them. let pattern = |gs: &str| format!("/A << /RI /Perceptual >> >> /Pattern << /P << /PatternType 2 /Shading << /ShadingType 2 >> /ExtGState {gs} >>"); assert_eq!(gs(&pattern("<< /TR 4 0 R >>")), [tr]); From ace9358b5876a7607425a00635bacb543b78bb80 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:34:14 +0800 Subject: [PATCH 06/12] M11: tests: private /PieceInfo data holding resources isn't read for 6.2.5 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index 9590054184..5ec513fac8 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -548,7 +548,9 @@ fn extended_graphics_states_are_checked() { ); assert!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Black 5 0 R /Spot << /HalftoneType 1 /TransferFunction 4 0 R >> >> >>").is_empty()); // Private application data isn't graphics resources. - assert!(gs("/A << /RI /Perceptual >> >> /PieceInfo << /App << /Private << /ExtGState << /X << /TR 4 0 R >> >> >> >> >>").is_empty()); + assert!( + gs("/A << /RI /Perceptual >> >> /PieceInfo << /App << /Private << /Resources << /ExtGState << /X << /TR 4 0 R >> >> >> >> >>").is_empty() + ); // A shading pattern holds one graphics state, not a dictionary of them. let pattern = |gs: &str| format!("/A << /RI /Perceptual >> >> /Pattern << /P << /PatternType 2 /Shading << /ShadingType 2 >> /ExtGState {gs} >>"); assert_eq!(gs(&pattern("<< /TR 4 0 R >>")), [tr]); From 7e16d792841de79e67dbae1a102e39aa15264071 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:35:47 +0800 Subject: [PATCH 07/12] M11: parity: PDF/A graphics state notes cover halftone transfer functions (6.2.5) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- parity/acrobat-features.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index c76ebeeae4..a7ee1876de 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -7944,7 +7944,7 @@ status = "partial" commands = ["standards.pdfa"] tools = ["pdfa_verify"] evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/preflight/src/tests.rs::extended_graphics_states_are_checked", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] -notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: TR, TR2, HTP, halftone types and names, rendering intents; the TransferFunction of type 5 halftone components is not yet checked), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." +notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: TR, TR2, HTP, halftone types, names and transfer functions, rendering intents), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." [[feature]] id = "optimize.pdfa-convert" From c6b5e612707be28f8ae0f32559d2f22e2983cb99 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 08:46:59 +0800 Subject: [PATCH 08/12] M11: PDF/A verify reads graphics states from what the trailer reaches, and needs an integer HalftoneType (6.2.5) Objects are followed from the trailer through a queue of references, never into /PieceInfo, so an object only private data refers to is not read as a graphics state holder. /HalftoneType must be an integer (ISO 32000-1 Table 128); a real of the same value is reported. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/gstate.rs | 35 ++++++++++++++++++++++++---------- crates/preflight/src/lib.rs | 6 +++--- crates/preflight/src/tests.rs | 8 +++++++- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/crates/preflight/src/gstate.rs b/crates/preflight/src/gstate.rs index fe26bbc830..551b627db0 100644 --- a/crates/preflight/src/gstate.rs +++ b/crates/preflight/src/gstate.rs @@ -13,10 +13,11 @@ //! Graphics state dictionaries are found as the `/ExtGState` entries of resource dictionaries //! (`/Resources` of pages, forms, Type 3 fonts, patterns and annotation appearances, and an //! interactive form's `/DR`), and as the `/ExtGState` of a shading pattern (ISO 32000-1 8.7.4.3, -//! Table 76). Private application data (`/PieceInfo`) isn't read. A map shared by reference is -//! read once. +//! Table 76). They are looked for in what the document reaches from its trailer, following +//! references, but not into private application data (`/PieceInfo`), so an object only that data +//! refers to isn't read. A map shared by reference is read once. -use std::collections::{BTreeSet, HashSet}; +use std::collections::{BTreeSet, HashSet, VecDeque}; use pdfcraft_cos::{Dict, Document, ObjRef, Object}; @@ -42,7 +43,7 @@ pub(crate) struct Findings { pub(crate) phase: bool, /// Halftone types other than 1 and 5, in order. pub(crate) halftone_types: BTreeSet, - /// A halftone has no `/HalftoneType` integer. + /// A halftone's `/HalftoneType` is missing or isn't an integer. pub(crate) untyped: bool, /// A halftone has a `/HalftoneName`. pub(crate) halftone_name: bool, @@ -56,11 +57,15 @@ pub(crate) struct Findings { pub(crate) intent_not_name: bool, } -/// The 6.2.5 findings over the indirect objects `objs`. -pub(crate) fn check(doc: &Document, objs: &[(ObjRef, std::sync::Arc)]) -> Findings { - let mut scan = Scan { doc, read: HashSet::new(), findings: Findings::default() }; - for (_, o) in objs { - scan.walk(o, 0); +/// The 6.2.5 findings over what `doc` reaches from its trailer. +pub(crate) fn check(doc: &Document) -> Findings { + let mut scan = Scan { doc, read: HashSet::new(), reached: HashSet::new(), queue: VecDeque::new(), findings: Findings::default() }; + scan.walk(&Object::Dict(doc.trailer().clone()), 0); + // References are followed from a queue, not by recursion: a chain of them can be as long as + // the file. + while let Some(r) = scan.queue.pop_front() { + let o = doc.get(r); + scan.walk(&o, 0); } scan.findings } @@ -69,6 +74,9 @@ struct Scan<'a> { doc: &'a Document, /// Resource dictionaries, `/ExtGState` maps and graphics states read so far, by reference. read: HashSet, + /// Objects reached so far, queued or walked. + reached: HashSet, + queue: VecDeque, findings: Findings, } @@ -78,6 +86,12 @@ impl Scan<'_> { return; } let d = match o { + Object::Ref(r) => { + if self.reached.insert(*r) { + self.queue.push_back(*r); + } + return; + } Object::Array(a) => { for v in a { self.walk(v, depth.saturating_add(1)); @@ -171,7 +185,8 @@ impl Scan<'_> { /// A halftone dictionary or stream: the graphics state's own (`colorant` is `None`), or the /// one a type 5 halftone holds for `colorant`. fn halftone(&mut self, ht: &Dict, colorant: Option<&[u8]>) { - let kind = self.present(ht, b"HalftoneType").and_then(|t| t.as_int()); + // An integer (ISO 32000-1 Table 128), not a real of the same value. + let kind = self.present(ht, b"HalftoneType").and_then(|t| if let Object::Int(t) = *t { Some(t) } else { None }); match kind { None => self.findings.untyped = true, Some(1 | 5) => {} diff --git a/crates/preflight/src/lib.rs b/crates/preflight/src/lib.rs index 667896c2e7..518cd2579d 100644 --- a/crates/preflight/src/lib.rs +++ b/crates/preflight/src/lib.rs @@ -126,7 +126,7 @@ pub const WORDINGS: &[&str] = &[ "A graphics state has a transfer function (TR2) other than Default", "A graphics state has a halftone phase (HTP)", "A halftone has type {}: only types 1 and 5 are allowed", - "A halftone has no HalftoneType", + "A halftone's HalftoneType is missing or isn't an integer", "A halftone has a HalftoneName", "A halftone has a transfer function, which only a non-primary colorant's halftone may have", "The halftone for the colorant {} has no transfer function", @@ -527,7 +527,7 @@ pub fn verify(doc: &Document, level: Level) -> Vec { } check_objects(doc, level, &objs, &page_of, &mut issue); // 6.2.5: the extended graphics state. - let gs = gstate::check(doc, &objs); + let gs = gstate::check(doc); if gs.transfer { issue("6.2.5", "A graphics state has a transfer function (TR)", None, None, false); } @@ -541,7 +541,7 @@ pub fn verify(doc: &Document, level: Level) -> Vec { issue("6.2.5", "A halftone has type {}: only types 1 and 5 are allowed", Some(kind.to_string()), None, false); } if gs.untyped { - issue("6.2.5", "A halftone has no HalftoneType", None, None, false); + issue("6.2.5", "A halftone's HalftoneType is missing or isn't an integer", None, None, false); } if gs.halftone_name { issue("6.2.5", "A halftone has a HalftoneName", None, None, false); diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index 5ec513fac8..c5a6cc5816 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -504,6 +504,7 @@ fn extended_graphics_states_are_checked() { "<< /HalftoneType 1 /Frequency 60 /Angle 45 /SpotFunction /Round >>", "<< /TR 4 0 R >>", "<< /Type /Halftone /HalftoneType 6 /Width 2 /Height 2 /Length 4 >>\nstream\nabcd\nendstream", + "<< /Resources << /ExtGState << /X << /TR 4 0 R >> >> >> >>", ], "", ); @@ -536,7 +537,9 @@ fn extended_graphics_states_are_checked() { assert_eq!(gs("/A << /RI /Custom >>"), ["A graphics state has the rendering intent Custom, which isn't a standard one"]); assert_eq!(gs("/A << /RI (Perceptual) >>"), ["A graphics state has a rendering intent that isn't a name"]); // A halftone's type is required; a null name is no name. - assert_eq!(gs("/A << /HT << /Frequency 60 >> >>"), ["A halftone has no HalftoneType"]); + let untyped = ["A halftone's HalftoneType is missing or isn't an integer"]; + assert_eq!(gs("/A << /HT << /Frequency 60 >> >>"), untyped); + assert_eq!(gs("/A << /HT << /HalftoneType 1.0 >> >>"), untyped); assert!(gs("/A << /HT << /HalftoneType 1 /HalftoneName null >> >>").is_empty()); // Transfer functions in halftones: only, and always, for a non-primary colorant. let in_halftone = "A halftone has a transfer function, which only a non-primary colorant's halftone may have"; @@ -551,6 +554,9 @@ fn extended_graphics_states_are_checked() { assert!( gs("/A << /RI /Perceptual >> >> /PieceInfo << /App << /Private << /Resources << /ExtGState << /X << /TR 4 0 R >> >> >> >> >>").is_empty() ); + // Nor is an object (8) only private data refers to; one the page refers to is read. + assert!(gs("/A << /RI /Perceptual >> >> /PieceInfo << /App << /Private 8 0 R >> >> /Z <<").is_empty()); + assert_eq!(gs("/A << /RI /Perceptual >> >> /Other 8 0 R /Z <<"), [tr]); // A shading pattern holds one graphics state, not a dictionary of them. let pattern = |gs: &str| format!("/A << /RI /Perceptual >> >> /Pattern << /P << /PatternType 2 /Shading << /ShadingType 2 >> /ExtGState {gs} >>"); assert_eq!(gs(&pattern("<< /TR 4 0 R >>")), [tr]); From 1928500350cea1dc45e974d4ed9198e76f0f04fe Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 09:07:37 +0800 Subject: [PATCH 09/12] M11: PDF/A verify's graphics state scan reads each object once, whatever the generation (6.2.5) Document::get fetches by object number, so references that differ only in generation reach the same object; the reached and read sets now go by number, and each object is walked once. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/gstate.rs | 25 ++++++++++++++++++------- crates/preflight/src/tests.rs | 12 ++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/preflight/src/gstate.rs b/crates/preflight/src/gstate.rs index 551b627db0..a84d303c04 100644 --- a/crates/preflight/src/gstate.rs +++ b/crates/preflight/src/gstate.rs @@ -59,6 +59,16 @@ pub(crate) struct Findings { /// The 6.2.5 findings over what `doc` reaches from its trailer. pub(crate) fn check(doc: &Document) -> Findings { + scan(doc).findings +} + +/// How many objects [`check`] reads. +#[cfg(test)] +pub(crate) fn reached(doc: &Document) -> usize { + scan(doc).reached.len() +} + +fn scan(doc: &Document) -> Scan<'_> { let mut scan = Scan { doc, read: HashSet::new(), reached: HashSet::new(), queue: VecDeque::new(), findings: Findings::default() }; scan.walk(&Object::Dict(doc.trailer().clone()), 0); // References are followed from a queue, not by recursion: a chain of them can be as long as @@ -67,15 +77,16 @@ pub(crate) fn check(doc: &Document) -> Findings { let o = doc.get(r); scan.walk(&o, 0); } - scan.findings + scan } struct Scan<'a> { doc: &'a Document, - /// Resource dictionaries, `/ExtGState` maps and graphics states read so far, by reference. - read: HashSet, - /// Objects reached so far, queued or walked. - reached: HashSet, + /// Resource dictionaries, `/ExtGState` maps and graphics states read so far, by object number. + read: HashSet, + /// Object numbers reached so far, queued or walked. Both sets go by number, as + /// [`Document::get`] does: references differing only in generation reach the same object. + reached: HashSet, queue: VecDeque, findings: Findings, } @@ -87,7 +98,7 @@ impl Scan<'_> { } let d = match o { Object::Ref(r) => { - if self.reached.insert(*r) { + if self.reached.insert(r.num) { self.queue.push_back(*r); } return; @@ -112,7 +123,7 @@ impl Scan<'_> { /// Whether `o` is a reference read before; marks it read. fn read_before(&mut self, o: &Object) -> bool { - matches!(o, Object::Ref(r) if !self.read.insert(*r)) + matches!(o, Object::Ref(r) if !self.read.insert(r.num)) } /// A dictionary that holds graphics states: through its resources, or as a shading pattern. diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index c5a6cc5816..3280ce8e51 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -562,3 +562,15 @@ fn extended_graphics_states_are_checked() { assert_eq!(gs(&pattern("<< /TR 4 0 R >>")), [tr]); assert!(gs(&pattern("<< /HT << /HalftoneType 1 >> >>")).is_empty()); } + +/// From the review of the 6.2.5 check: references that differ only in generation reach the same +/// object, which is read once. +#[test] +fn graphics_state_scan_reads_each_object_once_whatever_the_generation() { + let gens: String = (0..10).map(|g| format!("4 {g} R ")).collect(); + let page = format!("<< /Type /Page /Parent 2 0 R /Same [{gens}] >>"); + let doc = + build(&["<< /Type /Catalog /Pages 2 0 R >>", "<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 200 200] >>", &page, "[1 2 3]"], ""); + // The catalog, the page tree, the page and object 4. + assert_eq!(gstate::reached(&doc), 4); +} From 4c5fd46af7b8f53c013bf84660af15c922742ac7 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 09:07:53 +0800 Subject: [PATCH 10/12] M11: parity: cite the 6.2.5 scan test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- parity/acrobat-features.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index a7ee1876de..400f9be08b 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -7943,7 +7943,7 @@ milestone = "M11" status = "partial" commands = ["standards.pdfa"] tools = ["pdfa_verify"] -evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/preflight/src/tests.rs::extended_graphics_states_are_checked", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] +evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/preflight/src/tests.rs::extended_graphics_states_are_checked", "crates/preflight/src/tests.rs::graphics_state_scan_reads_each_object_once_whatever_the_generation", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: TR, TR2, HTP, halftone types, names and transfer functions, rendering intents), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." [[feature]] From b4e99b6229e16a69027c13e0540d4e3cdf3bf74f Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 09:21:14 +0800 Subject: [PATCH 11/12] M11: PDF/A verify takes the primary colour components of all three device spaces (6.2.5) Gray, Red, Green and Blue are primary colour components as well as Cyan, Magenta, Yellow and Black (ISO 32000-1 10.5.5.6, ISO 32000-2 10.6.5.6): their halftones need no transfer function and may not have one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- crates/preflight/src/gstate.rs | 11 +++++++---- crates/preflight/src/tests.rs | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/preflight/src/gstate.rs b/crates/preflight/src/gstate.rs index a84d303c04..64c19de116 100644 --- a/crates/preflight/src/gstate.rs +++ b/crates/preflight/src/gstate.rs @@ -6,8 +6,10 @@ //! - halftones of type 1 or 5 only, without a `/HalftoneName` (ISO 32000-1 10.5.5); the halftones //! a type 5 halftone holds for its colorants are checked the same way; //! - a halftone's `/TransferFunction` only where one is needed: a type 5 halftone's component for -//! a non-primary colorant has one, and no other halftone does. The primary colorants are those -//! of DeviceCMYK; the `Default` component is left as it is (ISO 32000-1 10.5.5.6, Table 130); +//! a non-primary colorant has one, and no other halftone does. The primary colour components +//! are those of the standard device spaces: Gray; Red, Green and Blue; Cyan, Magenta, Yellow +//! and Black (ISO 32000-1 10.5.5.6; ISO 32000-2 10.6.5.6). The `Default` component is left as +//! it is (ISO 32000-1 Table 130); //! - a rendering intent (`/RI`) that is one of the four of ISO 32000-1 8.6.5.8, Table 70. //! //! Graphics state dictionaries are found as the `/ExtGState` entries of resource dictionaries @@ -27,8 +29,9 @@ const MAX_DEPTH: u8 = 128; const INTENTS: [&[u8]; 4] = [b"AbsoluteColorimetric", b"RelativeColorimetric", b"Saturation", b"Perceptual"]; /// The entries of a type 5 halftone that aren't colorant halftones. const HALFTONE_KEYS: [&[u8]; 3] = [b"Type", b"HalftoneType", b"HalftoneName"]; -/// The primary colorants, whose halftones take the graphics state's transfer function. -const PRIMARY: [&[u8]; 4] = [b"Cyan", b"Magenta", b"Yellow", b"Black"]; +/// The primary colour components of DeviceGray, DeviceRGB and DeviceCMYK, whose halftones take +/// the graphics state's transfer function. +const PRIMARY: [&[u8]; 8] = [b"Gray", b"Red", b"Green", b"Blue", b"Cyan", b"Magenta", b"Yellow", b"Black"]; /// The entries that hold resource dictionaries. const RESOURCES: [&[u8]; 2] = [b"Resources", b"DR"]; diff --git a/crates/preflight/src/tests.rs b/crates/preflight/src/tests.rs index 3280ce8e51..94ec2c0055 100644 --- a/crates/preflight/src/tests.rs +++ b/crates/preflight/src/tests.rs @@ -545,9 +545,11 @@ fn extended_graphics_states_are_checked() { let in_halftone = "A halftone has a transfer function, which only a non-primary colorant's halftone may have"; assert_eq!(gs("/A << /HT << /HalftoneType 1 /TransferFunction 4 0 R >> >>"), [in_halftone]); assert_eq!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Cyan << /HalftoneType 1 /TransferFunction /Identity >> >> >>"), [in_halftone]); + // The primary components are those of DeviceGray, DeviceRGB and DeviceCMYK (ISO 32000-1 10.5.5.6). + assert_eq!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Gray << /HalftoneType 1 /TransferFunction /Identity >> >> >>"), [in_halftone]); assert_eq!( - gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Spot 5 0 R /Red 5 0 R >> >>"), - ["The halftone for the colorant Red has no transfer function", "The halftone for the colorant Spot has no transfer function"] + gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Spot 5 0 R /Red 5 0 R /Gray 5 0 R >> >>"), + ["The halftone for the colorant Spot has no transfer function"] ); assert!(gs("/A << /HT << /HalftoneType 5 /Default 5 0 R /Black 5 0 R /Spot << /HalftoneType 1 /TransferFunction 4 0 R >> >> >>").is_empty()); // Private application data isn't graphics resources. From 3d2134fa006afe3e426bad35c533b0a4e9d6d1f3 Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 5 Nov 2026 09:22:40 +0800 Subject: [PATCH 12/12] M11: parity: 6.2.5 notes cite the primary colour components Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn --- parity/acrobat-features.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 400f9be08b..3906cfb5ae 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -7944,7 +7944,7 @@ status = "partial" commands = ["standards.pdfa"] tools = ["pdfa_verify"] evidence = ["crates/preflight/src/tests.rs::verify_reports_what_breaks_pdfa", "crates/preflight/src/tests.rs::standards_identification_uses_namespace_not_prefix", "crates/preflight/src/tests.rs::convert_fixes_all_but_fonts", "crates/preflight/src/tests.rs::verify_reports_an_output_intent_that_does_not_match_device_colour", "crates/preflight/src/tests.rs::extended_graphics_states_are_checked", "crates/preflight/src/tests.rs::graphics_state_scan_reads_each_object_once_whatever_the_generation", "crates/automation/tests/it/automation.rs::pdfa_through_tools", "crates/ui-egui/tests/it/compare.rs::pdfa_dialog_verifies_and_converts"] -notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: TR, TR2, HTP, halftone types, names and transfer functions, rendering intents), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." +notes = "PDF/A-2b/3b structural rules: identification, encryption, output intent (present, and RGB/CMYK to match DeviceRGB/DeviceCMYK use), fonts embedded, graphics states (6.2.5: TR, TR2, HTP, halftone types, names and transfer functions with the primary components of ISO 32000-1 10.5.5.6, rendering intents), annotations, actions, images, embedded files. Not yet: content-stream operator checks, transparency details, PDF/A-1 and -4, a veraPDF comparison." [[feature]] id = "optimize.pdfa-convert"