mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-25 16:44:12 +00:00
Merge branch 'fix/pdfa-xmp-exif-types' into fix/pdfa-xmp-extension-schemas
Brings in #6220's written-name wording for 6.6.2.3.1 alongside the extension schema findings; the duplicated type-name test keeps the version that covers both the base and the EXIF types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn
This commit is contained in:
+22
-10
@@ -153,6 +153,7 @@ pub const WORDINGS: &[&str] = &[
|
||||
"The metadata doesn't identify the file as {}",
|
||||
"The title in the metadata and the document information differ",
|
||||
"The XMP property {property} in metadata stream {object} should have the value type {type}",
|
||||
"The XMP property {property} in metadata stream {object}, written {written}, should have the value type {type}",
|
||||
"The XMP extension schema {schema} in metadata stream {object} has no {entry} entry",
|
||||
"The XMP extension schema {schema} in metadata stream {object} describes {item} without a {entry} entry",
|
||||
"The XMP extension schema {schema} in metadata stream {object} has an empty {entry} entry",
|
||||
@@ -521,18 +522,29 @@ pub fn verify(doc: &Document, level: Level) -> Vec<Issue> {
|
||||
// every metadata stream.
|
||||
let (mut mistyped, mut extension) = (Vec::new(), xmp_extension::Findings::default());
|
||||
xmp_types::for_each_packet(&objs, |object, packet| {
|
||||
mistyped.extend(xmp_types::mistyped(packet).into_iter().map(|(name, ty)| (object, name, ty)));
|
||||
mistyped.extend(xmp_types::mistyped(packet).into_iter().map(|((name, written), ty)| (object, name, written, ty)));
|
||||
extension.add(object, packet);
|
||||
});
|
||||
for (object, name, ty) in mistyped {
|
||||
let values = vec![("{property}", name), ("{object}", object.to_string()), ("{type}", ty)];
|
||||
located_issue(
|
||||
"6.6.2.3.1",
|
||||
"The XMP property {property} in metadata stream {object} should have the value type {type}",
|
||||
values,
|
||||
object,
|
||||
false,
|
||||
);
|
||||
for (object, name, written, ty) in mistyped {
|
||||
let mut values = vec![("{property}", name.clone()), ("{object}", object.to_string()), ("{type}", ty)];
|
||||
if written == name {
|
||||
located_issue(
|
||||
"6.6.2.3.1",
|
||||
"The XMP property {property} in metadata stream {object} should have the value type {type}",
|
||||
values,
|
||||
object,
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
values.push(("{written}", written));
|
||||
located_issue(
|
||||
"6.6.2.3.1",
|
||||
"The XMP property {property} in metadata stream {object}, written {written}, should have the value type {type}",
|
||||
values,
|
||||
object,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
for m in extension.missing {
|
||||
let mut values = vec![("{schema}", m.schema), ("{object}", m.object.to_string()), ("{entry}", m.entry)];
|
||||
|
||||
@@ -507,7 +507,7 @@ fn mistyped(body: &str) -> Vec<String> {
|
||||
r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF {XMP_NS}><rdf:Description rdf:about="" {body}</rdf:Description></rdf:RDF></x:xmpmeta>"#
|
||||
);
|
||||
let parsed = xmp::parse(&xmp).expect("parses");
|
||||
xmp_types::mistyped(&parsed).into_keys().collect()
|
||||
xmp_types::mistyped(&parsed).into_keys().map(|(name, _)| name).collect()
|
||||
}
|
||||
|
||||
/// [`mistyped`] for the property `p` written as an element holding `v`.
|
||||
@@ -1094,32 +1094,6 @@ fn xmp_extension_findings_say_where_they_are() {
|
||||
);
|
||||
}
|
||||
|
||||
/// PDF/A-2 6.6.2.3.1: a mistyped property is reported with the type the XMP Specification gives it,
|
||||
/// as the specification writes it.
|
||||
#[test]
|
||||
fn xmp_mistyped_properties_name_their_type() {
|
||||
let types = |body: &str| -> Vec<(String, String)> {
|
||||
let xmp = format!(
|
||||
r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF {XMP_NS}><rdf:Description rdf:about="" {body}</rdf:Description></rdf:RDF></x:xmpmeta>"#
|
||||
);
|
||||
xmp_types::mistyped(&xmp::parse(&xmp).expect("parses")).into_iter().collect()
|
||||
};
|
||||
let t = |name: &str, ty: &str| (name.to_owned(), ty.to_owned());
|
||||
assert_eq!(
|
||||
types(r#"tiff:XResolution="0.5" exif:GPSLatitude="N" xmp:CreateDate="never">"#),
|
||||
[t("exif:GPSLatitude", "GPSCoordinate"), t("tiff:XResolution", "Rational"), t("xmp:CreateDate", "Date"),]
|
||||
);
|
||||
assert_eq!(
|
||||
types("><tiff:BitsPerSample>8</tiff:BitsPerSample><dc:title>T</dc:title>"),
|
||||
[t("dc:title", "Lang Alt"), t("tiff:BitsPerSample", "seq Integer")]
|
||||
);
|
||||
assert_eq!(
|
||||
types("><exif:Flash>fired</exif:Flash><xmpMM:History>h</xmpMM:History>"),
|
||||
[t("exif:Flash", "Flash"), t("xmpMM:History", "seq ResourceEvent")]
|
||||
);
|
||||
assert_eq!(types("><xmpMM:Pantry>p</xmpMM:Pantry>"), [t("xmpMM:Pantry", "bag struct")]);
|
||||
}
|
||||
|
||||
/// PDF/A-2 6.6.2.3.1 for the TIFF, EXIF and Additional EXIF schemas: a property is known by its
|
||||
/// namespace URI, whatever prefix the packet binds to it, and is named by the namespace's
|
||||
/// preferred prefix.
|
||||
@@ -1152,6 +1126,90 @@ fn wordings_fill_their_holes_once() {
|
||||
assert_eq!(fill("é{}ü", Some("v"), &[]), "évü");
|
||||
}
|
||||
|
||||
/// PDF/A-2 6.6.2.3.1: a mistyped property is reported with the type the XMP Specification gives it,
|
||||
/// as the specification writes it.
|
||||
#[test]
|
||||
fn xmp_mistyped_properties_name_their_type() {
|
||||
let types = |body: &str| -> Vec<(String, String)> {
|
||||
let xmp = format!(
|
||||
r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF {XMP_NS}><rdf:Description rdf:about="" {body}</rdf:Description></rdf:RDF></x:xmpmeta>"#
|
||||
);
|
||||
xmp_types::mistyped(&xmp::parse(&xmp).expect("parses")).into_iter().map(|((name, _), ty)| (name, ty)).collect()
|
||||
};
|
||||
let t = |name: &str, ty: &str| (name.to_owned(), ty.to_owned());
|
||||
assert_eq!(
|
||||
types(r#"crs:Contrast="high" crs:Exposure="bright" xmp:CreateDate="never">"#),
|
||||
[t("crs:Contrast", "Integer"), t("crs:Exposure", "Real"), t("xmp:CreateDate", "Date")]
|
||||
);
|
||||
assert_eq!(
|
||||
types("><xmpTPg:PlateNames>Cyan</xmpTPg:PlateNames><dc:title>T</dc:title>"),
|
||||
[t("dc:title", "Lang Alt"), t("xmpTPg:PlateNames", "seq Text")]
|
||||
);
|
||||
assert_eq!(
|
||||
types("><xmpTPg:MaxPageSize>A4</xmpTPg:MaxPageSize><xmpMM:History>h</xmpMM:History>"),
|
||||
[t("xmpMM:History", "seq ResourceEvent"), t("xmpTPg:MaxPageSize", "Dimensions")]
|
||||
);
|
||||
assert_eq!(types("><xmpMM:Pantry>p</xmpMM:Pantry>"), [t("xmpMM:Pantry", "bag struct")]);
|
||||
// The TIFF and EXIF types, as the 2005 edition writes them.
|
||||
assert_eq!(types(r#"tiff:XResolution="0.5" exif:GPSLatitude="N">"#), [t("exif:GPSLatitude", "GPSCoordinate"), t("tiff:XResolution", "Rational")]);
|
||||
assert_eq!(
|
||||
types("><tiff:BitsPerSample>8</tiff:BitsPerSample><exif:Flash>fired</exif:Flash><exif:OECF>o</exif:OECF>"),
|
||||
[t("exif:Flash", "Flash"), t("exif:OECF", "OECF/SFR"), t("tiff:BitsPerSample", "seq Integer")]
|
||||
);
|
||||
}
|
||||
|
||||
/// PDF/A-2 6.6.2.3.1: a property is known by its namespace URI, whatever prefix the packet binds
|
||||
/// to it, and is named by the namespace's preferred prefix and as the packet writes it. A property
|
||||
/// a predefined namespace doesn't define, and a namespace that isn't predefined, are left to the
|
||||
/// clauses about them.
|
||||
#[test]
|
||||
fn xmp_properties_are_known_by_namespace_uri_and_named_as_written() {
|
||||
let crs = "http://ns.adobe.com/camera-raw-settings/1.0/";
|
||||
let found = |body: &str| -> Vec<(String, String)> {
|
||||
let xmp = format!(
|
||||
r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF {XMP_NS}><rdf:Description rdf:about="" {body}</rdf:Description></rdf:RDF></x:xmpmeta>"#
|
||||
);
|
||||
xmp_types::mistyped(&xmp::parse(&xmp).expect("parses")).into_keys().collect()
|
||||
};
|
||||
let n = |name: &str, written: &str| (name.to_owned(), written.to_owned());
|
||||
// Another prefix for the namespace, as an attribute and as an element, and no prefix at all.
|
||||
assert_eq!(found(&format!(r#"xmlns:c="{crs}" c:Contrast="high">"#)), [n("crs:Contrast", "c:Contrast")]);
|
||||
assert_eq!(found(&format!(r#"><c:Exposure xmlns:c="{crs}">bright</c:Exposure>"#)), [n("crs:Exposure", "c:Exposure")]);
|
||||
assert_eq!(found(&format!(r#"><Exposure xmlns="{crs}">bright</Exposure>"#)), [n("crs:Exposure", "Exposure")]);
|
||||
assert!(found(&format!(r#"xmlns:c="{crs}" c:Contrast="5">"#)).is_empty());
|
||||
// The preferred prefix is written as it is.
|
||||
assert_eq!(found(r#"crs:Contrast="high">"#), [n("crs:Contrast", "crs:Contrast")]);
|
||||
// A long prefix is repeated only so far.
|
||||
let long = "p".repeat(100);
|
||||
let said = found(&format!(r#"xmlns:{long}="{crs}" {long}:Contrast="high">"#));
|
||||
assert_eq!(said.len(), 1);
|
||||
assert_eq!(said[0].1, format!("{}…:Contrast", "p".repeat(64)));
|
||||
// The preferred prefix bound to another namespace is not that namespace.
|
||||
assert!(found(r#"><crs:Contrast xmlns:crs="http://example.com/not-crs/">high</crs:Contrast>"#).is_empty());
|
||||
assert!(found(r#"xmlns:dc="http://example.com/not-dc/" dc:title="T">"#).is_empty());
|
||||
// A property a predefined namespace doesn't define, with any value.
|
||||
assert!(found(r#"crs:NotAProperty="high" dc:notAProperty="T">"#).is_empty());
|
||||
assert!(found("><xmp:NotAProperty><rdf:Seq><rdf:li>x</rdf:li></rdf:Seq></xmp:NotAProperty>").is_empty());
|
||||
// A namespace that isn't predefined, with a predefined property's local name.
|
||||
assert!(found(r#"xmlns:ex="http://example.com/ns/" ex:Contrast="high">"#).is_empty());
|
||||
assert!(found(r#"><ex:title xmlns:ex="http://example.com/ns/">T</ex:title>"#).is_empty());
|
||||
|
||||
// Through verify, the written name is said when it differs.
|
||||
let xmp = format!(
|
||||
r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF {XMP_NS}><rdf:Description rdf:about="" xmlns:c="{crs}" c:Contrast="high" crs:Exposure="bright"/></rdf:RDF></x:xmpmeta>"#
|
||||
);
|
||||
let stream = format!("<< /Type /Metadata /Subtype /XML /Length {} >>\nstream\n{xmp}\nendstream", xmp.len());
|
||||
let doc = build(&["<< /Type /Catalog /Pages 2 0 R /Metadata 3 0 R >>", "<< /Type /Pages /Kids [] /Count 0 >>", &stream], "");
|
||||
let messages: Vec<String> = verify(&doc, Level::A2b).into_iter().filter(|i| i.clause == "6.6.2.3.1").map(|i| i.message).collect();
|
||||
assert_eq!(
|
||||
messages,
|
||||
[
|
||||
"The XMP property crs:Contrast in metadata stream 3 0 R, written c:Contrast, should have the value type Integer",
|
||||
"The XMP property crs:Exposure in metadata stream 3 0 R should have the value type Real",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// PDF/A-2 6.6.2.3.1, the RDF/XML value forms XMP allows (ISO 16684-1 7.9.2.5): one `rdf:value`
|
||||
/// in a qualified value, no parse type but `Resource`, and an `rdf:resource` element left empty.
|
||||
#[test]
|
||||
|
||||
@@ -629,17 +629,20 @@ fn unicode(bytes: &[u8]) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// The properties of predefined schemas in the packet `doc` whose values don't have their type,
|
||||
/// as `prefix:name` in name order, each with the type it should have as [`named`] gives it.
|
||||
pub(crate) fn mistyped(doc: &roxmltree::Document<'_>) -> BTreeMap<String, String> {
|
||||
/// The properties of predefined schemas in the packet `doc` whose values don't have their type, in
|
||||
/// name order: each by its name with the namespace's preferred prefix and by its name as the packet
|
||||
/// writes it (see [`written`]), with the type it should have as [`named`] gives it.
|
||||
pub(crate) fn mistyped(doc: &roxmltree::Document<'_>) -> BTreeMap<(String, String), String> {
|
||||
let mut out = BTreeMap::new();
|
||||
let text = doc.input_text();
|
||||
let descriptions = doc.descendants().filter(|n| is(n, RDF, "Description") && n.parent_element().is_some_and(|p| is(&p, RDF, "RDF")));
|
||||
for d in descriptions {
|
||||
for a in d.attributes() {
|
||||
if let Some((schema, ty)) = a.namespace().and_then(|ns| property(ns, a.name()))
|
||||
&& !simple(ty, a.value())
|
||||
{
|
||||
out.insert(format!("{}:{}", schema.prefix, a.name()), named(ty));
|
||||
let qname = text.get(a.range_qname()).unwrap_or_default();
|
||||
out.insert((format!("{}:{}", schema.prefix, a.name()), written(qname, a.name())), named(ty));
|
||||
}
|
||||
}
|
||||
for p in d.children().filter(Node::is_element) {
|
||||
@@ -647,13 +650,30 @@ pub(crate) fn mistyped(doc: &roxmltree::Document<'_>) -> BTreeMap<String, String
|
||||
if let Some((schema, ty)) = name.namespace().and_then(|ns| property(ns, name.name()))
|
||||
&& !fits(ty, &p, 0)
|
||||
{
|
||||
out.insert(format!("{}:{}", schema.prefix, name.name()), named(ty));
|
||||
let qname = text.get(p.range()).unwrap_or_default().strip_prefix('<').unwrap_or_default();
|
||||
out.insert((format!("{}:{}", schema.prefix, name.name()), written(qname, name.name())), named(ty));
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// How long a prefix the packet writes is repeated.
|
||||
const MAX_PREFIX_CHARS: usize = 64;
|
||||
|
||||
/// The property `local` as the packet writes it, from the text its qualified name begins
|
||||
/// (`qname`): `prefix:local`, or `local` alone in the default namespace. A prefix past
|
||||
/// [`MAX_PREFIX_CHARS`] is cut, with `…`.
|
||||
fn written(qname: &str, local: &str) -> String {
|
||||
let qname = qname.split(|c: char| c.is_whitespace() || matches!(c, '>' | '/' | '=')).next().unwrap_or_default();
|
||||
let Some((prefix, _)) = qname.split_once(':') else { return local.to_owned() };
|
||||
let mut out: String = prefix.chars().take(MAX_PREFIX_CHARS).collect();
|
||||
if out.len() < prefix.len() {
|
||||
out.push('…');
|
||||
}
|
||||
format!("{out}:{local}")
|
||||
}
|
||||
|
||||
/// `ty` as the XMP Specification writes value types: `Integer`, `GPSCoordinate`, `Lang Alt`,
|
||||
/// `seq Rational`, a structure by its type's name, such as `Flash`.
|
||||
fn named(ty: Ty) -> String {
|
||||
|
||||
@@ -8003,7 +8003,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::xmp_simple_values_have_their_lexical_forms", "crates/preflight/src/tests.rs::xmp_arrays_have_their_kind_and_item_types", "crates/preflight/src/tests.rs::xmp_structures_have_their_field_types", "crates/preflight/src/tests.rs::xmp_value_types_are_reported_by_verify", "crates/preflight/src/tests.rs::xmp_exif_schemas_have_their_value_types", "crates/preflight/src/tests.rs::xmp_exif_properties_are_known_by_namespace_uri", "crates/preflight/src/tests.rs::xmp_extension_schema_descriptions_are_complete", "crates/preflight/src/tests.rs::xmp_extension_findings_say_where_they_are", "crates/preflight/src/tests.rs::xmp_mistyped_properties_name_their_type", "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::xmp_simple_values_have_their_lexical_forms", "crates/preflight/src/tests.rs::xmp_arrays_have_their_kind_and_item_types", "crates/preflight/src/tests.rs::xmp_structures_have_their_field_types", "crates/preflight/src/tests.rs::xmp_value_types_are_reported_by_verify", "crates/preflight/src/tests.rs::xmp_exif_schemas_have_their_value_types", "crates/preflight/src/tests.rs::xmp_exif_properties_are_known_by_namespace_uri", "crates/preflight/src/tests.rs::xmp_extension_schema_descriptions_are_complete", "crates/preflight/src/tests.rs::xmp_extension_findings_say_where_they_are", "crates/preflight/src/tests.rs::xmp_extension_naming_entries_are_not_empty", "crates/preflight/src/tests.rs::xmp_mistyped_properties_name_their_type", "crates/preflight/src/tests.rs::xmp_properties_are_known_by_namespace_uri_and_named_as_written", "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, the value types of the predefined XMP schemas (6.6.2.3.1: dc, xmp, xmpRights, xmpMM, xmpBJ, xmpTPg, xmpDM, pdf, photoshop, crs, and tiff, exif and aux from the September 2005 XMP Specification, with their structures), XMP extension schema descriptions (6.6.2.3.3, after PDF Association TechNote 0009 section 4: required entries of the schema, property, value type and field descriptions, none of the naming entries empty, and the five required prefixes; that a property's custom value type has its own pdfaSchema:valueType description is not yet checked), 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."
|
||||
|
||||
[[feature]]
|
||||
|
||||
Reference in New Issue
Block a user