diff --git a/crates/cdr/src/build.rs b/crates/cdr/src/build.rs index 923c9155cd..758c8886b6 100644 --- a/crates/cdr/src/build.rs +++ b/crates/cdr/src/build.rs @@ -693,8 +693,11 @@ impl<'a, 'b> Ctx<'a, 'b> { if let Some(f) = self.fills.get(&id) { return f.clone(); } - // A record that is there but can't be read is damage; a missing one leaves the shape - // without a fill. + // A record that is missing or can't be read is damage, and the shape is drawn without a + // fill; id 0 without a record is no fill. + if id != 0 && !self.fill_chunks.contains_key(&id) { + push(self.warn, Warning::Damaged); + } let read = self.fill_chunks.get(&id).and_then(|b| { let read = records::fill(b, &self.p, self.warn); if read.is_none() { @@ -710,6 +713,11 @@ impl<'a, 'b> Ctx<'a, 'b> { /// uses it; past them the shape's outline is solid. fn outline(&mut self, id: u32) -> Option { if !self.outlines.contains_key(&id) { + // A record that is missing is damage, as one that can't be read is; id 0 without a + // record is no outline. + if id != 0 && !self.outline_chunks.contains_key(&id) { + push(self.warn, Warning::Damaged); + } let read = self.outline_chunks.get(&id).and_then(|b| { let read = records::outline(b, &self.p, self.warn); if read.is_none() { diff --git a/crates/cdr/tests/it/read.rs b/crates/cdr/tests/it/read.rs index 3a32cc0d8a..5c944a6c16 100644 --- a/crates/cdr/tests/it/read.rs +++ b/crates/cdr/tests/it/read.rs @@ -1396,6 +1396,25 @@ fn an_id_argument_cut_short_is_damage() { } } +/// A fill or outline id that no record has is damage: the shape comes in without that paint. Id 0 +/// without a record is no paint. +#[test] +fn a_fill_or_outline_without_its_record_is_damage() { + for version in [700, 1100, 1600] { + let v = V(version); + for kind in [20, 10] { + for (id, want) in [(9u32, vec![Warning::Damaged]), (0, vec![])] { + let object = synth::object(v, 1, &[(kind, id.to_le_bytes().to_vec()), (30, v.rect(10.0, 10.0, 0.0))], None); + let d = + read(&clip_drawing(version, vec![], vec![object]), Limits::default()).unwrap_or_else(|e| panic!("{version} {kind} {id}: {e}")); + let s = shapes(&d.pages[0].layers[0].objects); + assert!(s.len() == 1 && s[0].fill.is_none() && s[0].outline.is_none(), "{version} {kind} {id}"); + assert_eq!(d.warnings, want, "{version} {kind} {id}"); + } + } + } +} + /// An object with a lens or transparency (argument 8000) comes in opaque, with the lenses /// warning; one without the argument gives no warning. #[test]