mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-24 10:56:51 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70a7171b35 |
+11
-11
@@ -2349,7 +2349,7 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec<Tag> {
|
||||
// ---------------- 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<Item = &Entity>, paper: bool| {
|
||||
let block = |w: &mut W, (name, desc): (&str, &str), brh: &str, base: Vec3, flags: i64, ents: &mut dyn Iterator<Item = &Entity>, paper: bool| {
|
||||
let bh = w.h();
|
||||
w.s(0, "BLOCK");
|
||||
w.s(5, bh);
|
||||
@@ -2382,16 +2382,16 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec<Tag> {
|
||||
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()) {
|
||||
@@ -2401,13 +2401,13 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec<Tag> {
|
||||
}
|
||||
}
|
||||
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");
|
||||
|
||||
@@ -2588,7 +2588,7 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec<Tag> {
|
||||
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 };
|
||||
@@ -2673,10 +2673,10 @@ fn tags_for(d: &Drawing, version: Version, target: Version) -> Vec<Tag> {
|
||||
// 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));
|
||||
|
||||
+12
-12
@@ -157,7 +157,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,
|
||||
@@ -229,7 +229,7 @@ fn font_file(pdf: &str, bytes_of: &[u8]) -> Vec<u8> {
|
||||
#[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 p = pdf(&d, &Space::Model, json!({}));
|
||||
// A Type0 font over a CIDFontType2 subset with a ToUnicode map.
|
||||
assert!(p.contains("/Subtype /Type0") && p.contains("/Encoding /Identity-H") && p.contains("/Subtype /CIDFontType2"), "{p}");
|
||||
@@ -257,7 +257,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 bytes = plot(&d, &Space::Model, &json!({"compress": false})).unwrap();
|
||||
let p: String = bytes.iter().map(|b| if b.is_ascii() { char::from(*b) } else { '?' }).collect();
|
||||
let file = font_file(&p, &bytes);
|
||||
@@ -279,9 +279,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);
|
||||
// Rotated a quarter turn: the baseline points up, "up" points left.
|
||||
@@ -300,16 +300,16 @@ fn rotation_width_factor_and_obliquing_go_into_the_text_matrix() {
|
||||
#[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!(!p.contains("/FontFile2") && !p.contains("BT\n") && p.contains("h\nf\n"), "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!(!p.contains("/FontFile2") && !p.contains("BT\n") && p.contains("h\nf\n"), "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!(!p.contains("BT\n") && p.contains(" S\n") || p.contains("\nS\n"));
|
||||
}
|
||||
@@ -319,8 +319,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,
|
||||
@@ -335,7 +335,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!({}));
|
||||
let tj = p.lines().filter(|l| l.ends_with(" Tj")).count();
|
||||
// "AB" inside, the paper-space "B", and the glyph of "BA" left of the edge: real text. The
|
||||
|
||||
Reference in New Issue
Block a user