fix(style): spacing directly represents blank lines between paragraphs (1 or 2)

This commit is contained in:
Developer
2026-05-15 21:43:30 +08:00
parent 362acfddbf
commit 93f529e700

View File

@@ -40,7 +40,7 @@ impl StyleProfile {
name: "宽松".into(),
alignment: TextAlignment::Left,
line_spacing: 1.0,
paragraph_spacing: 1.0,
paragraph_spacing: 2.0,
first_line_indent: 2.0,
font_size: 26.0,
},
@@ -67,12 +67,13 @@ impl StyleProfile {
}
fn apply_para_spacing(text: &str, spacing: f32) -> String {
if spacing <= 0.0 {
return text.to_string();
let blank_lines = spacing.round().max(0.0) as usize;
if blank_lines == 0 {
return text.to_string(); // 保留 strip_html 输出的 \n\n即 1 行空白
}
// spacing 表示额外空白行数:基础换行 \n\n 已有1行空白再加 spacing 行
let newlines = 2 + spacing.round().max(0.0) as usize;
let sep = "\n".repeat(newlines);
// spacing 直接表示段落间空白行数1行=1空行2行=2空行
let total_nl = blank_lines + 1;
let sep = "\n".repeat(total_nl);
text.replace("\n\n", &sep)
}