新增获取动态文本高度参数

qdj
邱德佳 4 months ago
parent ed10892e06
commit 1890d084a1

@ -28,7 +28,8 @@ pub struct DynamicText {
text_from: String,
v_alignment: VAlignment,
frame: bool,
text_width: i32,
text_height: f64,
text_width: f64,
keep_visual_rotation: bool,
color: HexColor,
reference_rectangle_width: f64,
@ -49,32 +50,15 @@ impl From<&DynamicText> for XMLElement {
// reversed and slightly modified after looking at the result in element-editor:
//
let pt_size: f64 = txt.font.point_size;
//
// we need the horizontal alignment and the text-width to move to right x-position:
// txt.reference_rectangle_width, // should be text-width (Group code 41)
// txt.attachment_point, // Group code 71
// // 1 = Top left; 2 = Top center; 3 = Top right
// // 4 = Middle left; 5 = Middle center; 6 = Middle right
// 使用对象自身保存的 text_widthbuilder 已经计算或直接从 DXF 读取)
// // 7 = Bottom left; 8 = Bottom center; 9 = Bottom right
//
//
// it's just annoying if the value for "reference_rectangle_width" in the dxf is “0.0”...
//
// o.k. ... as long as we do not know the real width:
// "guess" the width by number of characters and font-size:
//
let graphene_count = txt.text.graphemes(true).count();
let txt_width = if txt.reference_rectangle_width > 2.0 {
txt.reference_rectangle_width
} else {
// 不同的字母宽度与高度的比例并不相同0.75只是一个平均值
(graphene_count as f64) * pt_size * 0.75
};
println!("文本:{}", txt.text);
println!("对齐方式:{}, {}", txt.h_alignment, txt.v_alignment);
println!("文本宽度: {}", txt_width);
println!("文本宽度: {}", txt.text_width);
println!("文本高度:{}", pt_size);
println!("初始左下角位置: x={}, y={}", txt.x, txt.y);
println!("初始对齐位置: x={}, y={}", txt.align_x, txt.align_y);
@ -104,7 +88,7 @@ impl From<&DynamicText> for XMLElement {
VAlignment::Bottom => txt.align_y + 1.0
};
if(txt.h_alignment == HAlignment::Left && txt.v_alignment==VAlignment::Bottom) {
if txt.h_alignment == HAlignment::Left && txt.v_alignment==VAlignment::Bottom {
align_x = txt.x-0.5;
align_y = txt.y+1.0;
}
@ -146,6 +130,7 @@ impl From<&DynamicText> for XMLElement {
dtxt_xml.add_attribute("Valignment", &txt.v_alignment);
dtxt_xml.add_attribute("text_from", &txt.text_from);
dtxt_xml.add_attribute("frame", txt.frame);
dtxt_xml.add_attribute("text_height", txt.text_height);
dtxt_xml.add_attribute("text_width", txt.text_width);
dtxt_xml.add_attribute("color", txt.color.display_rgb());
dtxt_xml.add_attribute("align_x", two_dec(align_x));
@ -373,7 +358,8 @@ impl<'a> DTextBuilder<'a> {
dbg!(&y);
dbg!(&self.text);*/
let value = super::strip_mtext_control_sequences(&value);
// 将 DXF 中读取到的 text_height 放大 2 倍(用户要求)
let text_height = text_height * 2.0;
DynamicText {
//x: x - (calc_width as f64/2.0),
x,
@ -400,7 +386,8 @@ impl<'a> DTextBuilder<'a> {
v_alignment,
text_from: "UserText".into(),
frame: false,
text_width: -1,
text_height,
text_width: -1.0, // for now, until I figure out what this should be
color: self.color.unwrap_or(HexColor::BLACK),
text: value,

Loading…
Cancel
Save