mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-06 05:53:08 -05:00
Merge main into feat/cgm-open-place
This commit is contained in:
commit
3bf25bbf76
282 files changed
+16266
-1245
No files matched your search
@@ -3712,12 +3712,20 @@ fn arb_dxf_entity() -> impl Strategy<Value = Vec<(i32, String)>> {
|
||||
"ATTRIB",
|
||||
"DIMENSION",
|
||||
"VIEWPORT",
|
||||
"REGION",
|
||||
]);
|
||||
let code = prop::sample::select(vec![
|
||||
2, 6, 7, 8, 10, 11, 12, 13, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 48, 50, 51, 60, 62, 66, 67, 70, 71, 72, 73, 74, 75, 76, 90, 91, 92, 93,
|
||||
94, 95, 96, 97, 210, 220, 230, 370, 420, 440, 450,
|
||||
1, 2, 3, 6, 7, 8, 10, 11, 12, 13, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 48, 50, 51, 60, 62, 66, 67, 70, 71, 72, 73, 74, 75, 76, 90, 91, 92,
|
||||
93, 94, 95, 96, 97, 210, 220, 230, 370, 420, 440, 450,
|
||||
]);
|
||||
let value = prop_oneof![arb_num(), Just("B".to_string()), Just("*U1".to_string()), Just(r"{\fA;x}\P%%c^".to_string())];
|
||||
let value = prop_oneof![
|
||||
arb_num(),
|
||||
Just("B".to_string()),
|
||||
Just("*U1".to_string()),
|
||||
Just(r"{\fA;x}\P%%c^".to_string()),
|
||||
Just("700 0 1 0".to_string()),
|
||||
Just("body $-1 -1 $-1 $0 $-1 $-1 #".to_string()),
|
||||
];
|
||||
(kind, prop::collection::vec((code, value), 0..24)).prop_map(|(k, g)| std::iter::once((0, k.to_string())).chain(g).collect())
|
||||
}
|
||||
|
||||
@@ -3731,6 +3739,107 @@ fn hostile_dxf(block: &[Vec<(i32, String)>], body: &[Vec<(i32, String)>]) -> Vec
|
||||
dxf_text(&all).into_bytes()
|
||||
}
|
||||
|
||||
/// A region's solid-modeler text data: one face whose loop is two lines and a quarter circle,
|
||||
/// (0, 0) to (100, 0), round to (0, 100) and back.
|
||||
const REGION_SAT: &str = "700 0 1 0
|
||||
4 Fuzz 3 ASM 4 none
|
||||
1 9.9999999999999995e-07 1e-10
|
||||
body $-1 -1 $-1 $1 $-1 $-1 #
|
||||
lump $-1 -1 $-1 $-1 $2 $0 #
|
||||
shell $-1 -1 $-1 $-1 $-1 $3 $-1 $1 #
|
||||
face $-1 -1 $-1 $-1 $4 $2 $-1 $-1 forward single #
|
||||
loop $-1 -1 $-1 $-1 $5 $3 #
|
||||
coedge $-1 -1 $-1 $6 $7 $-1 $8 forward $4 $-1 #
|
||||
coedge $-1 -1 $-1 $7 $5 $-1 $9 forward $4 $-1 #
|
||||
coedge $-1 -1 $-1 $5 $6 $-1 $10 forward $4 $-1 #
|
||||
edge $-1 -1 $-1 $11 0 $12 1 $5 $-1 forward @7 unknown #
|
||||
edge $-1 -1 $-1 $12 0 $13 1 $6 $17 forward @7 unknown #
|
||||
edge $-1 -1 $-1 $13 0 $11 1 $7 $-1 forward @7 unknown #
|
||||
vertex $-1 -1 $-1 $8 $14 #
|
||||
vertex $-1 -1 $-1 $9 $15 #
|
||||
vertex $-1 -1 $-1 $10 $16 #
|
||||
point $-1 -1 $-1 0 0 0 #
|
||||
point $-1 -1 $-1 100 0 0 #
|
||||
point $-1 -1 $-1 0 100 0 #
|
||||
ellipse-curve $-1 -1 $-1 0 0 0 0 0 1 100 0 0 1 I I #
|
||||
End-of-ACIS-data
|
||||
";
|
||||
|
||||
/// [`REGION_SAT`]'s records as binary data: tagged values, type names in parts.
|
||||
fn region_sab() -> Vec<u8> {
|
||||
let mut b = b"ACIS BinaryFile".to_vec();
|
||||
for v in [700u32, 0, 1, 0] {
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
let string = |b: &mut Vec<u8>, tag: u8, s: &str| {
|
||||
b.push(tag);
|
||||
b.push(u8::try_from(s.len()).unwrap_or(0));
|
||||
b.extend(s.as_bytes());
|
||||
};
|
||||
for line in REGION_SAT.lines().skip(3).take_while(|l| !l.starts_with("End-of")) {
|
||||
let mut words = line.split_whitespace();
|
||||
let parts: Vec<&str> = words.next().unwrap_or_default().split('-').collect();
|
||||
for (i, p) in parts.iter().enumerate() {
|
||||
string(&mut b, if i + 1 == parts.len() { 0x0D } else { 0x0E }, p);
|
||||
}
|
||||
while let Some(w) = words.next() {
|
||||
match w {
|
||||
"#" => {}
|
||||
"forward" => b.push(0x0B),
|
||||
"reversed" => b.push(0x0A),
|
||||
w if w.starts_with('$') => {
|
||||
b.push(0x0C);
|
||||
b.extend(w[1..].parse::<i32>().unwrap_or(-1).to_le_bytes());
|
||||
}
|
||||
w if w.starts_with('@') => string(&mut b, 0x07, words.next().unwrap_or_default()),
|
||||
w => match w.parse::<f64>() {
|
||||
Ok(v) => {
|
||||
b.push(0x06);
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
Err(_) => string(&mut b, 0x07, w),
|
||||
},
|
||||
}
|
||||
}
|
||||
b.push(0x11);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
/// A drawing with one REGION: `text` as its data in groups 1 (DXF 2000), or `binary` in the
|
||||
/// ACDSDATA section (DXF 2013).
|
||||
fn region_dxf(text: &str, binary: Option<&[u8]>) -> Vec<u8> {
|
||||
let version = if binary.is_some() { "AC1027" } else { "AC1015" };
|
||||
let mut p: Vec<(i32, String)> =
|
||||
[(0, "SECTION"), (2, "HEADER"), (9, "$ACADVER"), (1, version), (0, "ENDSEC"), (0, "SECTION"), (2, "ENTITIES"), (0, "REGION"), (5, "2A")]
|
||||
.iter()
|
||||
.map(|(c, v)| (*c, v.to_string()))
|
||||
.collect();
|
||||
p.extend([(8, "0".to_string()), (100, "AcDbEntity".into()), (100, "AcDbModelerGeometry".into()), (70, "1".into())]);
|
||||
p.extend(text.lines().map(|l| (1, l.to_string())));
|
||||
p.push((0, "ENDSEC".into()));
|
||||
if let Some(bytes) = binary {
|
||||
p.extend([(0, "SECTION"), (2, "ACDSDATA"), (0, "ACDSRECORD"), (320, "2A"), (2, "ASM_Data")].iter().map(|(c, v)| (*c, v.to_string())));
|
||||
p.push((94, bytes.len().to_string()));
|
||||
p.extend(bytes.chunks(127).map(|c| (310, c.iter().map(|b| format!("{b:02X}")).collect())));
|
||||
p.push((0, "ENDSEC".into()));
|
||||
}
|
||||
p.push((0, "EOF".into()));
|
||||
dxf_text(&p).into_bytes()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn region_seeds_open_as_a_filled_path() {
|
||||
let o = vectorcraft_cad::ImportOptions::default();
|
||||
for bytes in [region_dxf(REGION_SAT, None), region_dxf("", Some(®ion_sab()))] {
|
||||
let r = vectorcraft_cad::import(&bytes, &o).expect("opens");
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("REGION")), "{:?}", r.warnings);
|
||||
let mut paths = 0;
|
||||
r.document.walk(|n: &vectorcraft_doc::Node| paths += usize::from(matches!(n.kind, vectorcraft_doc::NodeKind::Path { .. })));
|
||||
assert_eq!(paths, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Import with every option at once, and place it; whatever comes back must render and export.
|
||||
fn survive_dxf(what: &str, bytes: &[u8], fit: bool) -> Result<(), TestCaseError> {
|
||||
let o = vectorcraft_cad::ImportOptions { fit, center: !fit, merge_layers: fit, ..Default::default() };
|
||||
@@ -3784,6 +3893,23 @@ proptest! {
|
||||
bytes.truncate(cut.max(8));
|
||||
survive_dxf("mutated dxf", &bytes, cut % 2 == 0)?;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dxf_mutated_regions_never_panic(
|
||||
binary in any::<bool>(),
|
||||
cut in 0usize..2_000,
|
||||
edits in prop::collection::vec((0usize..2_000, prop::sample::select(vec![b'0', b'1', b'9', b'-', b'.', b'e', b'$', b'#', b' ', b'@', 0xFF, 0x0C])), 0..12),
|
||||
) {
|
||||
let mut data = if binary { region_sab() } else { REGION_SAT.as_bytes().to_vec() };
|
||||
for &(at, b) in &edits {
|
||||
let n = data.len();
|
||||
// Text stays ASCII, as group values are.
|
||||
data[at % n] = if binary || (b' '..0x80).contains(&b) { b } else { b' ' };
|
||||
}
|
||||
data.truncate(cut.max(8));
|
||||
let bytes = if binary { region_dxf("", Some(&data)) } else { region_dxf(&String::from_utf8_lossy(&data), None) };
|
||||
survive_dxf("mutated region", &bytes, cut % 2 == 0)?;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Windows metafiles: opened, placed and pasted ----------
|
||||
|
||||
@@ -401,7 +401,7 @@ const INSIDE: &[(&str, &str)] = &[
|
||||
// The print option classes and the enumerations of printing.
|
||||
(
|
||||
"",
|
||||
"FontSubstitutionPolicy PageMarksTypes PostScriptImageCompressionType PrintArtworkDesignation PrintColorIntent \
|
||||
"FontSubstitutionPolicy PostScriptImageCompressionType PrintArtworkDesignation PrintColorIntent \
|
||||
PrintColorManagementOptions PrintColorProfile PrintColorSeparationMode PrintColorSeparationOptions \
|
||||
PrintCoordinateOptions PrintFlattenerOptions PrintFontDownloadMode PrintFontOptions PrintJobOptions PrintOptions \
|
||||
PrintOrientation PrintPageMarksOptions PrintPaperOptions PrintPosition PrintPostScriptOptions PrintTiling \
|
||||
@@ -464,7 +464,6 @@ const INSIDE: &[(&str, &str)] = &[
|
||||
postScriptLevel= shadingResolution shadingResolution= typename",
|
||||
),
|
||||
("FontSubstitutionPolicy.", "SUBSTITUTEDEVICE SUBSTITUTEOBLIQUE SUBSTITUTETINT"),
|
||||
("PageMarksTypes.", "Japanese Roman"),
|
||||
("PostScriptImageCompressionType.", "IMAGECOMPRESSIONNONE JPEG RLE"),
|
||||
("PrintArtworkDesignation.", "ALLLAYERS VISIBLELAYERS VISIBLEPRINTABLELAYERS"),
|
||||
("PrintColorIntent.", "ABSOLUTECOLORIMETRIC PERCEPTUALINTENT RELATIVECOLORIMETRIC SATURATIONINTENT"),
|
||||
|
||||
Reference in new issue
Block a user