From b0ea2374082347fc5ec782d6ac6b1f1f8c5af549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=BE=B7=E4=BD=B3?= <798951257@qq.com> Date: Thu, 9 Oct 2025 17:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E9=97=B4=E8=B7=9D=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/qelmt/dynamictext.rs | 23 +++++++++-------------- src/qelmt/mod.rs | 22 ++++++++++++++++++---- src/qelmt/text.rs | 16 ++++++++-------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/qelmt/dynamictext.rs b/src/qelmt/dynamictext.rs index b3aa9b0..a1d407f 100644 --- a/src/qelmt/dynamictext.rs +++ b/src/qelmt/dynamictext.rs @@ -184,8 +184,7 @@ impl ScaleEntity for DynamicText { self.y *= fact_y; self.align_x *= fact_x; self.align_y *= fact_y; - //self.font.pixel_size *= fact; - self.font.point_size *= fact_x; + self.font.scale(fact_y); } fn left_bound(&self) -> f64 { @@ -386,19 +385,15 @@ impl<'a> DTextBuilder<'a> { 0.0 }, uuid: Uuid::new_v4(), - font: if style_name == "STANDARD" { - FontInfo { - point_size: text_height, - ..Default::default() - } - } else { - //clearly right now this is exactly the same as the main body of the if block - //I'm jus putting this in for now, to compile while I get the font handling - //working correctly - FontInfo { - point_size: text_height, + font: { + let mut font = FontInfo { ..Default::default() + }; + font.apply_height(text_height); + if style_name != "STANDARD" && !style_name.is_empty() { + font.style_name = Some(style_name.to_string()); } + font }, reference_rectangle_width, //liest aus der dxf-Datei!!! h_alignment, @@ -499,4 +494,4 @@ pub fn adjust_mtext_coordinates( } (adjusted_x, adjusted_y) -} \ No newline at end of file +} diff --git a/src/qelmt/mod.rs b/src/qelmt/mod.rs index 6ef93dd..51d77de 100644 --- a/src/qelmt/mod.rs +++ b/src/qelmt/mod.rs @@ -1692,7 +1692,7 @@ impl From<&FontStyle> for i32 { struct FontInfo { family: String, point_size: f64, - pixel_size: i32, + pixel_size: f64, style_hint: FontStyleHint, weight: i32, style: FontStyle, @@ -1710,7 +1710,7 @@ impl Default for FontInfo { family: "宋体".into(), // 字号12? point_size: 12.0, - pixel_size: i32::default(), + pixel_size: 0.0, style_hint: FontStyleHint::Helvetica, weight: i32::default(), style: FontStyle::Normal, @@ -1729,7 +1729,7 @@ impl Display for FontInfo { "{},{},{},{},{},{},{},{},{},0{}", self.family, self.point_size.round(), - self.pixel_size, + self.pixel_size.round() as i32, Into::::into(&self.style_hint), self.weight, Into::::into(&self.style), @@ -1745,6 +1745,20 @@ impl Display for FontInfo { } } +impl FontInfo { + fn apply_height(&mut self, height: f64) { + self.point_size = height; + self.pixel_size = height; + } + + fn scale(&mut self, fact: f64) { + self.point_size *= fact; + if self.pixel_size > 0.0 { + self.pixel_size *= fact; + } + } +} + #[derive(Debug)] enum TextEntity<'a> { Text(&'a dxf::entities::Text), @@ -1959,4 +1973,4 @@ pub(crate) fn strip_mtext_control_sequences(input: &str) -> String { } result -} \ No newline at end of file +} diff --git a/src/qelmt/text.rs b/src/qelmt/text.rs index 4e15f03..1aa2d7b 100644 --- a/src/qelmt/text.rs +++ b/src/qelmt/text.rs @@ -15,6 +15,12 @@ pub struct Text { impl From<(&entities::Text, HexColor)> for Text { fn from((txt, color): (&entities::Text, HexColor)) -> Self { + let mut font = FontInfo::default(); + font.apply_height(txt.text_height); + if !txt.text_style_name.is_empty() && txt.text_style_name != "STANDARD" { + font.style_name = Some(txt.text_style_name.clone()); + } + Text { x: txt.location.x, y: -txt.location.y, @@ -24,12 +30,7 @@ impl From<(&entities::Text, HexColor)> for Text { 0.0 }, color, - font: if &txt.text_style_name == "STANDARD" { - FontInfo::default() - } else { - //txt.text_style_name.clone() - FontInfo::default() - }, + font, value: txt.value.clone(), } } @@ -52,8 +53,7 @@ impl ScaleEntity for Text { fn scale(&mut self, fact_x: f64, fact_y: f64) { self.x *= fact_x; self.y *= fact_y; - //self.font.pixel_size *= fact; - self.font.point_size *= fact_x; + self.font.scale(fact_y); } fn left_bound(&self) -> f64 {