fix(style): spacing directly represents blank lines between paragraphs (1 or 2)
This commit is contained in:
13
src/style.rs
13
src/style.rs
@@ -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: 1.0,
|
paragraph_spacing: 2.0,
|
||||||
first_line_indent: 2.0,
|
first_line_indent: 2.0,
|
||||||
font_size: 26.0,
|
font_size: 26.0,
|
||||||
},
|
},
|
||||||
@@ -67,12 +67,13 @@ impl StyleProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_para_spacing(text: &str, spacing: f32) -> String {
|
fn apply_para_spacing(text: &str, spacing: f32) -> String {
|
||||||
if spacing <= 0.0 {
|
let blank_lines = spacing.round().max(0.0) as usize;
|
||||||
return text.to_string();
|
if blank_lines == 0 {
|
||||||
|
return text.to_string(); // 保留 strip_html 输出的 \n\n,即 1 行空白
|
||||||
}
|
}
|
||||||
// spacing 表示额外空白行数:基础换行 \n\n 已有1行空白,再加 spacing 行
|
// spacing 直接表示段落间空白行数(1行=1空行,2行=2空行)
|
||||||
let newlines = 2 + spacing.round().max(0.0) as usize;
|
let total_nl = blank_lines + 1;
|
||||||
let sep = "\n".repeat(newlines);
|
let sep = "\n".repeat(total_nl);
|
||||||
text.replace("\n\n", &sep)
|
text.replace("\n\n", &sep)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user