Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions crates/dwg/src/compose/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub struct Parts<'a> {
pub app_version: &'a str,
/// The font file of each text style, with the style's handle.
pub fonts: &'a [(String, u64)],
/// The data store section (2013 and later: the modeler descriptions of solids, regions and
/// bodies, laid out by [`crate::datastore::write`]), when the drawing has any.
pub data_store: Option<&'a [u8]>,
}

/// The maintenance release each version's file records, as AutoCAD writes it today.
Expand Down Expand Up @@ -354,12 +357,20 @@ fn paged(p: &Parts<'_>) -> Result<Vec<u8>> {
let history = app_info_history(p);
let history_page = round_up(history.len(), 0x80);
let compressed = |name, data| Section { name, data, compressed: true, page_size: MAX_PAGE };
let stream = vec![
let mut stream = vec![
Section { name: "AcDb:SummaryInfo", data: summary, compressed: false, page_size: summary_page },
Section { name: "AcDb:Preview", data: preview, compressed: false, page_size: preview_page },
Section { name: "AcDb:AppInfo", data: app_info, compressed: false, page_size: app_info_page },
Section { name: "AcDb:AppInfoHistory", data: history, compressed: false, page_size: history_page },
compressed("AcDb:XrefManifest", xref_manifest(p)),
];
// AutoCAD files the data store after the xref manifest, in the stream and in the map.
let mut map_order: Vec<&str> = MAP_ORDER.to_vec();
if let Some(ds) = p.data_store.filter(|_| ver >= V::R2013) {
stream.push(compressed("AcDb:AcDsPrototype_1b", ds.to_vec()));
map_order.insert(1, "AcDb:AcDsPrototype_1b");
}
stream.extend([
compressed("AcDb:RevHistory", shared::rev_history()),
compressed("AcDb:AcDbObjects", objects),
compressed("AcDb:ObjFreeSpace", obj_free_space(p)),
Expand All @@ -368,7 +379,7 @@ fn paged(p: &Parts<'_>) -> Result<Vec<u8>> {
compressed("AcDb:Classes", classes_section(ver, p.codepage, p.text, p.classes)),
compressed("AcDb:AuxHeader", aux_header(p)),
compressed("AcDb:Header", header(p)),
];
]);
let mut code = [0u8; 6];
code.copy_from_slice(ver.magic().as_bytes().get(..6).unwrap_or(b"AC1032"));
let info = FileInfo {
Expand All @@ -379,7 +390,7 @@ fn paged(p: &Parts<'_>) -> Result<Vec<u8>> {
codepage: p.codepage,
acad_maintenance: if ver >= V::R2018 { shared::ACAD_MAINTENANCE } else { 0 },
};
container::pack(&info, &stream, &MAP_ORDER)
container::pack(&info, &stream, &map_order)
}

/// AutoCAD 2007: named sections in pages of Reed-Solomon codewords.
Expand Down
6 changes: 5 additions & 1 deletion crates/dwg/src/compose/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub struct EntityStart<'a> {
/// entity names its neighbours): `None` when they are the objects with the handles just
/// below and above this one's.
pub links: Option<(u64, u64)>,
/// The entity keeps data in the file's data store section (AutoCAD 2013 on): a solid's,
/// region's or body's modeler description. AutoCAD looks for a record only when this is set.
pub data_store: bool,
}

impl Default for EntityStart<'_> {
Expand All @@ -92,6 +95,7 @@ impl Default for EntityStart<'_> {
invisible: false,
lineweight: 29,
links: None,
data_store: false,
}
}
}
Expand Down Expand Up @@ -248,7 +252,7 @@ impl ObjectWriter {
self.dat.b(e.xdictionary == 0);
}
if ver >= V::R2013 {
self.dat.b(false);
self.dat.b(e.data_store);
}
if ver <= V::R2000 {
self.dat.b(e.links.is_none());
Expand Down
1 change: 1 addition & 0 deletions crates/dwg/src/compose/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ fn autocads_files_compose_again() {
app_name: "DraftCraft",
app_version: "3.0.0",
fonts: &[("txt".into(), 0xF)],
data_store: None,
};
let out = compose(&parts).unwrap_or_else(|e| panic!("{name}: {e}"));
let again = crate::file::DwgFile::open(&out).unwrap_or_else(|e| panic!("{name}: {e}"));
Expand Down
Loading
Loading