CDR import: a fill or outline whose record is missing is damage

A shape that names a fill or outline id no record has comes in without that paint and with the damage warning, so the open counts as lossy. Id 0 without a record stays no paint.
This commit is contained in:
dotCooCoo
2026-11-14 17:40:04 -08:00
parent 0c730007b1
commit 5c28beca75
2 changed files with 29 additions and 2 deletions
+10 -2
View File
@@ -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<Outline> {
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() {
+19
View File
@@ -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]