Repository navigation
fix(dwg): custom table cell styles survive a DWG save (#3132) #3148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| //! A table style's custom cell styles survive a DWG save as they do a DXF one (#3132). | ||
| #![cfg(not(target_arch = "wasm32"))] | ||
| // FreeBSD ARM64 has no native DWG bridge (#2526). | ||
| #![cfg(not(all(target_os = "freebsd", target_arch = "aarch64")))] | ||
|
|
||
| use cadcraft_doc::{CellStyle, Common, Drawing, EntityKind, Space, Table, TableCell, TableStyle}; | ||
| use cadcraft_io::{SaveOptions, Version}; | ||
|
|
||
| fn drawing() -> Drawing { | ||
| let mut d = Drawing::new_imperial(); | ||
| let mut st = TableStyle { name: "Costs".into(), text_height: 0.2, ..TableStyle::default() }; | ||
| let mut mine = st.cell_style(CellStyle::DATA); | ||
| mine.name = "MINE".into(); | ||
| mine.text_height = 0.05; | ||
| mine.align = 4; | ||
| st.set_cell_style(mine); | ||
| d.table_styles.push(st); | ||
| let cell = |t: &str| TableCell { text: t.into(), ..TableCell::default() }; | ||
| let mut cells = vec![vec![cell("a"), cell("b")], vec![cell("c"), cell("d")]]; | ||
| cells[1][0].style = "MINE".into(); | ||
| let t = Table { | ||
| style: "Costs".into(), | ||
| text_height: 0.2, | ||
| title: false, | ||
| header: false, | ||
| row_heights: vec![0.4, 0.4], | ||
| col_widths: vec![2.0, 2.0], | ||
| cells, | ||
| ..Table::default() | ||
| }; | ||
| d.add(&Space::Model, Common::default(), EntityKind::Table(t)).unwrap(); | ||
| d | ||
| } | ||
|
|
||
| fn save(d: &Drawing, v: Version) -> Drawing { | ||
| let bytes = cadcraft_io::write_with(d, "t.dwg", &SaveOptions { version: Some(v), binary: false }).unwrap(); | ||
| cadcraft_io::read(&bytes, "t.dwg").unwrap() | ||
| } | ||
|
|
||
| /// A style whose name is too long for one pre-R2007 EED string once its characters are escaped. | ||
| #[test] | ||
| fn long_non_latin_style_name_roundtrips_through_dwg() { | ||
| let mut d = drawing(); | ||
| let long = "中".repeat(80); | ||
| if let Some(st) = d.table_styles.iter_mut().find(|s| s.name == "Costs") { | ||
| let mut other = st.cell_style(CellStyle::DATA); | ||
| other.name = long.clone(); | ||
| other.align = 5; | ||
| st.set_cell_style(other); | ||
| } | ||
| let want = d.table_styles.iter().find(|s| s.name == "Costs").unwrap().clone(); | ||
| for v in [Version::R2004, Version::R2007, Version::R2018] { | ||
| let back = save(&d, v); | ||
| let st = back.table_styles.iter().find(|s| s.name == "Costs").unwrap(); | ||
| assert!(st.has_cell_style(&long), "{v:?}: cell styles after DWG: {:?}", st.cell_styles); | ||
| assert_eq!(st.cell_styles, want.cell_styles, "{v:?}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn custom_cell_styles_roundtrip_through_dwg() { | ||
| let d = drawing(); | ||
| let want = d.table_styles.iter().find(|s| s.name == "Costs").unwrap().clone(); | ||
| for v in [Version::R2004, Version::R2007, Version::R2010, Version::R2013, Version::R2018] { | ||
| let back = save(&d, v); | ||
| let st = back.table_styles.iter().find(|s| s.name == "Costs").expect("table style kept"); | ||
| assert!(st.has_cell_style("MINE"), "{v:?}: cell styles after DWG: {:?}", st.cell_styles); | ||
| assert_eq!(st.cell_styles, want.cell_styles, "{v:?}"); | ||
| // And a second save keeps them. | ||
| let again = save(&back, v); | ||
| let st = again.table_styles.iter().find(|s| s.name == "Costs").unwrap(); | ||
| assert_eq!(st.cell_styles, want.cell_styles, "{v:?}: second save"); | ||
| // Plain styles stay plain. | ||
| let std = again.table_styles.iter().find(|s| s.name == "Standard").unwrap(); | ||
| assert!(std.cell_styles.is_empty(), "{v:?}"); | ||
| // The table's cell still names the style. | ||
| let t = again.model.iter().find_map(|e| if let EntityKind::Table(t) = &e.kind { Some(t) } else { None }).unwrap(); | ||
| assert_eq!(t.cells[1][0].style, "MINE", "{v:?}"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.