diff --git a/dxf2elmt.log b/dxf2elmt.log new file mode 100644 index 0000000..e69de29 diff --git a/src/qelmt/arc.rs b/src/qelmt/arc.rs index 586f795..4cdcba5 100644 --- a/src/qelmt/arc.rs +++ b/src/qelmt/arc.rs @@ -124,6 +124,22 @@ impl Arc { { update_fn(&mut self.style); } + + pub fn update_line_weight(&mut self, lw: i16) { + let weight_str = match lw { + 0 | -1 => "thin", + 13..=25 => "thin", + 26..=70 => "normal", + 71..=100 => "thick", + _ => "extra-thick", + }; + + // 直接追加,不做复杂替换(简单有效) + if !self.style.is_empty() { + self.style.push_str("; "); + } + self.style.push_str(&format!("line-weight: {}", weight_str)); + } } impl ScaleEntity for Arc { diff --git a/src/qelmt/line.rs b/src/qelmt/line.rs index b632aa5..936a237 100644 --- a/src/qelmt/line.rs +++ b/src/qelmt/line.rs @@ -98,6 +98,24 @@ impl Line { }, }) } + + pub fn update_line_weight(&mut self, lw: i16) { + let weight_str = match lw { + 0 | -1 => "thin", + 13..=25 => "thin", + 26..=70 => "normal", + 71..=100 => "thick", + _ => "extra-thick", + }; + + // 直接追加,不做复杂替换(简单有效) + if !self.style.is_empty() { + self.style.push_str("; "); + } + self.style.push_str(&format!("line-weight: {}", weight_str)); + } + + } impl From<&entities::Leader> for Leader { diff --git a/src/qelmt/mod.rs b/src/qelmt/mod.rs index 0708d6d..8daf129 100644 --- a/src/qelmt/mod.rs +++ b/src/qelmt/mod.rs @@ -611,8 +611,9 @@ impl<'a> ObjectsBuilder<'a> { // 通用样式修改函数:根据line_type_name修改现有style中的line-style let update_line_style = |style: &mut String| { + println!("line_type_name:{line_type_name}"); // 只有当line_type_name需要虚线样式时才进行修改,提高性能 - if line_type_name.contains("DASH") || line_type_name == "BORDURE" { + if line_type_name.contains("DASH") || line_type_name == "BORDURE" || line_type_name == "INTERROMPU" || line_type_name == "INTERROMPUx2" || line_type_name == "TRACECAD_ISO02W100" { // 使用正则表达式替换line-style部分 if style.contains("line-style:") { *style = style.replace( @@ -809,7 +810,6 @@ impl<'a> ObjectsBuilder<'a> { // 根据line_type_name更新线型样式 line.update_line_style(&update_line_style); - line.scale(self.scale_fact.x, self.scale_fact.x); line.x1 += self.offset.x; @@ -824,7 +824,7 @@ impl<'a> ObjectsBuilder<'a> { if let Ok(mut ellipse) = Ellipse::try_from(polyline) { // 根据line_type_name更新线型样式 ellipse.update_line_style(&update_line_style); - + // TODO ellipse的粗体未实现 ellipse.scale(self.scale_fact.x, self.scale_fact.y); ellipse.x += self.offset.x; @@ -836,7 +836,7 @@ impl<'a> ObjectsBuilder<'a> { // 根据line_type_name更新线型样式 poly.update_line_style(&update_line_style); - + // TODO poly的粗体未实现 poly.scale(self.scale_fact.x, self.scale_fact.y); for cord in &mut poly.coordinates { @@ -855,6 +855,21 @@ impl<'a> ObjectsBuilder<'a> { } else { HexColor::from_u32(self.ent.common.color_24_bit as u32) }; + // === 获取weight === + let mut lw: Option = None; + if lwpolyline.constant_width > 0.0 { + lw = Some((lwpolyline.constant_width * 100.0) as i16); + } else if let Some(v) = lwpolyline.vertices.get(0) { + let w = if v.starting_width > 0.0 { + v.starting_width + } else { + v.ending_width + }; + if w > 0.0 { + lw = Some((w * 100.0) as i16); + } + } + // =============================== match lwpolyline.vertices.len() { 0 | 1 => Err("Error empty LwPolyline"), @@ -863,6 +878,10 @@ impl<'a> ObjectsBuilder<'a> { match Arc::try_from_lwpolyline_with_color(lwpolyline, color) { Ok(mut arc) => { arc.update_line_style(&update_line_style); + // 更新线条粗细 + if let Some(w) = lw { + arc.update_line_weight(w); + } arc.scale(self.scale_fact.x, self.scale_fact.y); arc.x += self.offset.x; arc.y -= self.offset.y; @@ -878,7 +897,10 @@ impl<'a> ObjectsBuilder<'a> { // 根据line_type_name更新线型样式 line.update_line_style(&update_line_style); - + // 更新线条粗细 + if let Some(w) = lw { + line.update_line_weight(w); + } line.scale(self.scale_fact.x, self.scale_fact.y); line.x1 += self.offset.x; @@ -893,7 +915,7 @@ impl<'a> ObjectsBuilder<'a> { if let Ok(mut ellipse) = Ellipse::try_from_lwpolyline_with_color(lwpolyline, color) { // 根据line_type_name更新线型样式 ellipse.update_line_style(&update_line_style); - + // TODO ellipse的粗体未实现 ellipse.scale(self.scale_fact.x, self.scale_fact.y); ellipse.x += self.offset.x; @@ -928,7 +950,7 @@ impl<'a> ObjectsBuilder<'a> { // 根据line_type_name更新线型样式 poly.update_line_style(&update_line_style); - + // TODO poly的粗体未实现 poly.scale(self.scale_fact.x, self.scale_fact.y); for cord in &mut poly.coordinates { @@ -941,6 +963,7 @@ impl<'a> ObjectsBuilder<'a> { } } }, + EntityType::Solid(solid) => { let mut poly: Polygon = solid.into(); diff --git a/src/qelmt/polygon.rs b/src/qelmt/polygon.rs index 2ececcc..79f1619 100644 --- a/src/qelmt/polygon.rs +++ b/src/qelmt/polygon.rs @@ -107,6 +107,24 @@ impl Polygon { }, } } + + pub fn update_line_weight(&mut self, lw: i16) { + let weight_str = match lw { + 0 | -1 => "thin", + 13..=25 => "thin", + 26..=70 => "normal", + 71..=100 => "thick", + _ => "extra-thick", + }; + + // 直接追加,不做复杂替换(简单有效) + if !self.style.is_empty() { + self.style.push_str("; "); + } + self.style.push_str(&format!("line-weight: {}", weight_str)); + } + + } impl From<(&Spline, u32)> for Polygon {