fix(style): fix paragraph spacing formula, reduce from 2x to linear extra lines
This commit is contained in:
@@ -40,7 +40,7 @@ impl StyleProfile {
|
|||||||
name: "宽松".into(),
|
name: "宽松".into(),
|
||||||
alignment: TextAlignment::Left,
|
alignment: TextAlignment::Left,
|
||||||
line_spacing: 1.0,
|
line_spacing: 1.0,
|
||||||
paragraph_spacing: 3.0,
|
paragraph_spacing: 1.0,
|
||||||
first_line_indent: 2.0,
|
first_line_indent: 2.0,
|
||||||
font_size: 26.0,
|
font_size: 26.0,
|
||||||
},
|
},
|
||||||
@@ -70,9 +70,9 @@ fn apply_para_spacing(text: &str, spacing: f32) -> String {
|
|||||||
if spacing <= 0.0 {
|
if spacing <= 0.0 {
|
||||||
return text.to_string();
|
return text.to_string();
|
||||||
}
|
}
|
||||||
// Each unit of spacing adds one empty line between paragraphs
|
// spacing 表示额外空白行数:基础换行 \n\n 已有1行空白,再加 spacing 行
|
||||||
let extra_nls = (spacing * 2.0).round() as usize + 2; // minimum 2 newlines (1 empty line)
|
let newlines = 2 + spacing.round().max(0.0) as usize;
|
||||||
let sep = "\n".repeat(extra_nls);
|
let sep = "\n".repeat(newlines);
|
||||||
text.replace("\n\n", &sep)
|
text.replace("\n\n", &sep)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user