diff --git a/crates/io/src/dxf_write.rs b/crates/io/src/dxf_write.rs index 06c8b648f..385e07580 100644 --- a/crates/io/src/dxf_write.rs +++ b/crates/io/src/dxf_write.rs @@ -2373,7 +2373,7 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec { // ---------------- BLOCKS ---------------- w.s(0, "SECTION"); w.s(2, "BLOCKS"); - let block = |w: &mut W, name: &str, desc: &str, brh: &str, base: Vec3, flags: i64, ents: &mut dyn Iterator, paper: bool| { + let block = |w: &mut W, (name, desc): (&str, &str), brh: &str, base: Vec3, flags: i64, ents: &mut dyn Iterator, paper: bool| { let bh = w.h(); w.s(0, "BLOCK"); w.s(5, bh); @@ -2406,16 +2406,16 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec { w.s(8, "0"); w.s(100, "AcDbBlockEnd"); }; - block(&mut w, "*Model_Space", "", &ms_br, Vec3::ZERO, 0, &mut std::iter::empty(), false); + block(&mut w, ("*Model_Space", ""), &ms_br, Vec3::ZERO, 0, &mut std::iter::empty(), false); for (i, (n, h, l)) in ps_brs.iter().enumerate() { if i == 0 { - block(&mut w, n, "", h, Vec3::ZERO, 0, &mut std::iter::empty(), true); + block(&mut w, (n, ""), h, Vec3::ZERO, 0, &mut std::iter::empty(), true); } else { - block(&mut w, n, "", h, Vec3::ZERO, 0, &mut sheet_first(l).into_iter(), true); + block(&mut w, (n, ""), h, Vec3::ZERO, 0, &mut sheet_first(l).into_iter(), true); } } for (n, h, b) in &user_blocks { - block(&mut w, n, &b.description, h, b.base, if b.anonymous { 1 } else { 0 }, &mut b.entities.iter().map(|e| e.as_ref()), false); + block(&mut w, (n, &b.description), h, b.base, if b.anonymous { 1 } else { 0 }, &mut b.entities.iter().map(|e| e.as_ref()), false); } // Generated geometry entities (dimension, arrowhead and table blocks) need handles. for (_, _, ents) in dim_defs.iter_mut().chain(arrow_defs.iter_mut()).chain(table_defs.iter_mut()) { @@ -2425,13 +2425,13 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec { } } for (n, h, ents) in &dim_defs { - block(&mut w, n, "", h, Vec3::ZERO, 1, &mut ents.iter(), false); + block(&mut w, (n, ""), h, Vec3::ZERO, 1, &mut ents.iter(), false); } for (n, h, ents) in &arrow_defs { - block(&mut w, n, "", h, Vec3::ZERO, 0, &mut ents.iter(), false); + block(&mut w, (n, ""), h, Vec3::ZERO, 0, &mut ents.iter(), false); } for (n, h, ents) in &table_defs { - block(&mut w, n, "", h, Vec3::ZERO, 1, &mut ents.iter(), false); + block(&mut w, (n, ""), h, Vec3::ZERO, 1, &mut ents.iter(), false); } w.s(0, "ENDSEC"); @@ -2612,7 +2612,7 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec { w.s(3, &l.name); w.s(350, layout_handles.get(i).cloned().unwrap_or_default()); } - let layout_obj = |w: &mut W, h: &str, name: &str, tab: i64, brh: &str, flags: i64, page: &PageSetup, view: Option<(Vec2, f64)>| { + let layout_obj = |w: &mut W, h: &str, (name, tab): (&str, i64), brh: &str, flags: i64, page: &PageSetup, view: Option<(Vec2, f64)>| { // Plot scale: a standard scale when fitting or 1:1, otherwise custom (142 paper units // per 143 drawing units). let scale = if page.scale.is_finite() && page.scale > 0.0 { page.scale } else { 1.0 }; @@ -2697,10 +2697,10 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec { // plot type 5, "Layout information" (DXF Reference, PLOTSETTINGS group 74), which means // nothing for model space: another program's Plot dialog then shows no plot area or scale. let model_page = PageSetup { plot_area: "extents".into(), scale_to_fit: true, ..PageSetup::default() }; - layout_obj(&mut w, &model_layout, "Model", 0, &ms_br, 1, &model_page, None); + layout_obj(&mut w, &model_layout, ("Model", 0), &ms_br, 1, &model_page, None); for (i, (_, brh, l)) in ps_brs.iter().enumerate() { let h = layout_handles.get(i).cloned().unwrap_or_default(); - layout_obj(&mut w, &h, &l.name, i64::from(l.tab_order.max(1)), brh, 1, &l.page, l.view); + layout_obj(&mut w, &h, (&l.name, i64::from(l.tab_order.max(1))), brh, 1, &l.page, l.view); } // Raster image definitions. w.t.extend(crate::dxf_image::objects(&cx.images, &root_dict)); diff --git a/crates/io/tests/pdf_text.rs b/crates/io/tests/pdf_text.rs index c238b2013..baba82f9d 100644 --- a/crates/io/tests/pdf_text.rs +++ b/crates/io/tests/pdf_text.rs @@ -165,7 +165,7 @@ fn style(d: &mut Drawing, name: &str, font: &str) { d.text_styles.push(TextStyle { name: name.into(), font: font.into(), ..TextStyle::default() }); } -fn text(d: &mut Drawing, space: &Space, style: &str, at: (f64, f64), value: &str, rotation: f64, width_factor: f64, oblique: f64) { +fn text(d: &mut Drawing, space: &Space, style: &str, at: (f64, f64), value: &str, (rotation, width_factor, oblique): (f64, f64, f64)) { let t = Text { insert: Vec3::new(at.0, at.1, 0.0), align_pt: None, @@ -225,7 +225,7 @@ fn font_files(doc: &Doc) -> usize { #[test] fn truetype_text_is_embedded_as_text() { let mut d = drawing(); - text(&mut d, &Space::Model, "Real", (0.0, 0.0), "ABBA", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Real", (0.0, 0.0), "ABBA", (0.0, 1.0, 0.0)); let doc = pdf(&d, &Space::Model, json!({})); let page = &doc.pages[0]; // A Type0 font over a CIDFontType2 subset with a ToUnicode map. @@ -260,7 +260,7 @@ fn truetype_text_is_embedded_as_text() { #[test] fn the_subset_is_a_valid_truetype_font() { let mut d = drawing(); - text(&mut d, &Space::Model, "Real", (0.0, 0.0), "A", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Real", (0.0, 0.0), "A", (0.0, 1.0, 0.0)); let doc = pdf(&d, &Space::Model, json!({})); let file = doc.pages[0].fonts[0].font_file.clone().expect("an embedded font file"); let face = cadcraft_fonts::ttf::Face::new(std::sync::Arc::new(file.clone()), 0).expect("the subset parses"); @@ -273,9 +273,9 @@ fn the_subset_is_a_valid_truetype_font() { fn rotation_width_factor_and_obliquing_go_into_the_text_matrix() { let mut d = drawing(); let quarter = std::f64::consts::FRAC_PI_2; - text(&mut d, &Space::Model, "Real", (0.0, 0.0), "A", quarter, 1.0, 0.0); - text(&mut d, &Space::Model, "Real", (0.0, 50.0), "A", 0.0, 2.0, 0.0); - text(&mut d, &Space::Model, "Real", (0.0, 100.0), "A", 0.0, 1.0, 15f64.to_radians()); + text(&mut d, &Space::Model, "Real", (0.0, 0.0), "A", (quarter, 1.0, 0.0)); + text(&mut d, &Space::Model, "Real", (0.0, 50.0), "A", (0.0, 2.0, 0.0)); + text(&mut d, &Space::Model, "Real", (0.0, 100.0), "A", (0.0, 1.0, 15f64.to_radians())); let m = matrices(&pdf(&d, &Space::Model, json!({}))); assert_eq!(m.len(), 3, "{m:?}"); // Rotated a quarter turn: the baseline points up, "up" points left. @@ -294,7 +294,7 @@ fn rotation_width_factor_and_obliquing_go_into_the_text_matrix() { #[test] fn a_font_the_writer_cannot_subset_plots_as_outlines() { let mut d = drawing(); - text(&mut d, &Space::Model, "Short", (0.0, 0.0), "AB", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Short", (0.0, 0.0), "AB", (0.0, 1.0, 0.0)); let p = pdf(&d, &Space::Model, json!({})); assert!(font_files(&p) == 0 && pdf_read::count(p.content(), "BT") == 0 && fills(&p) > 0, "outlines: {}", p.content()); } @@ -302,16 +302,16 @@ fn a_font_the_writer_cannot_subset_plots_as_outlines() { #[test] fn fonts_that_forbid_embedding_and_the_geometry_option_draw_outlines() { let mut d = drawing(); - text(&mut d, &Space::Model, "Locked", (0.0, 0.0), "AB", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Locked", (0.0, 0.0), "AB", (0.0, 1.0, 0.0)); let p = pdf(&d, &Space::Model, json!({})); assert!(font_files(&p) == 0 && pdf_read::count(p.content(), "BT") == 0 && fills(&p) > 0, "restricted licence: outlines"); let mut d = drawing(); - text(&mut d, &Space::Model, "Real", (0.0, 0.0), "AB", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Real", (0.0, 0.0), "AB", (0.0, 1.0, 0.0)); let p = pdf(&d, &Space::Model, json!({"text": "geometry"})); assert!(font_files(&p) == 0 && pdf_read::count(p.content(), "BT") == 0 && fills(&p) > 0, "text as geometry"); // The stroke font is always geometry. let mut d = drawing(); - text(&mut d, &Space::Model, "Standard", (0.0, 0.0), "AB", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Standard", (0.0, 0.0), "AB", (0.0, 1.0, 0.0)); let p = pdf(&d, &Space::Model, json!({})); assert!(pdf_read::count(p.content(), "BT") == 0 && pdf_read::count(p.content(), "S") > 0); } @@ -321,8 +321,8 @@ fn text_seen_through_a_viewport_and_on_layers() { let mut d = drawing(); let paper = Space::Paper("Layout1".into()); // Model: one word well inside the viewport, one cut by its right edge. - text(&mut d, &Space::Model, "Real", (0.0, 0.0), "AB", 0.0, 1.0, 0.0); - text(&mut d, &Space::Model, "Real", (88.0, 0.0), "BA", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Real", (0.0, 0.0), "AB", (0.0, 1.0, 0.0)); + text(&mut d, &Space::Model, "Real", (88.0, 0.0), "BA", (0.0, 1.0, 0.0)); let vp = Viewport { center: Vec3::new(150.0, 100.0, 0.0), width: 100.0, @@ -337,7 +337,7 @@ fn text_seen_through_a_viewport_and_on_layers() { on: true, }; d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap(); - text(&mut d, &paper, "Real", (20.0, 20.0), "B", 0.0, 1.0, 0.0); + text(&mut d, &paper, "Real", (20.0, 20.0), "B", (0.0, 1.0, 0.0)); let p = pdf(&d, &paper, json!({})); // "AB" inside, the paper-space "B", and the glyph of "BA" left of the edge: real text. The // glyph the edge cuts stays a (clipped) outline. @@ -353,7 +353,7 @@ fn text_seen_through_a_viewport_and_on_layers() { #[test] fn text_sits_in_its_layers_marked_content() { let mut d = drawing(); - text(&mut d, &Space::Model, "Real", (0.0, 0.0), "AB", 0.0, 1.0, 0.0); + text(&mut d, &Space::Model, "Real", (0.0, 0.0), "AB", (0.0, 1.0, 0.0)); let p = pdf(&d, &Space::Model, json!({})); let ops = pdf_read::ops(p.content()); let first_bt = ops.iter().position(|o| o.op == "BT").unwrap();