字符间距测试

qdj
邱德佳 4 months ago
parent acde03cf70
commit b0ea237408

@ -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)
}
}

@ -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::<i32>::into(&self.style_hint),
self.weight,
Into::<i32>::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
}
}

@ -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 {

Loading…
Cancel
Save