Model TeX interline glue and parskip
This commit is contained in:
1 parent
8cb09ea5a8
commit
49bd9b63e6
8 files changed
+200
-32
No files matched your search
@@ -597,6 +597,9 @@ pub struct Document {
|
||||
/// the body flow. Defaults to 12pt.
|
||||
#[serde(default = "default_in_text_sep")]
|
||||
pub in_text_sep: i64,
|
||||
/// TeX `\parskip`: vertical glue inserted between paragraphs.
|
||||
#[serde(default)]
|
||||
pub par_skip: i64,
|
||||
}
|
||||
|
||||
fn default_text_fraction() -> u8 {
|
||||
@@ -653,6 +656,7 @@ impl Document {
|
||||
float_sep: default_float_sep(),
|
||||
text_float_sep: default_text_float_sep(),
|
||||
in_text_sep: default_in_text_sep(),
|
||||
par_skip: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,9 +1003,14 @@ impl Engine {
|
||||
used = document.top_skip;
|
||||
insertion_height = 0;
|
||||
}
|
||||
let par_skip = if current.items.is_empty() {
|
||||
0
|
||||
} else {
|
||||
document.par_skip.max(0)
|
||||
};
|
||||
if current.items.is_empty() && !page_has_top_float_material(¤t) {
|
||||
used = document.top_skip.max(paragraph.height);
|
||||
} else if used + paragraph.height
|
||||
} else if used + par_skip + paragraph.height
|
||||
> document.page_goal
|
||||
- insertion_height
|
||||
- bottom_float_area(¤t, document.text_float_sep)
|
||||
@@ -1010,7 +1019,10 @@ impl Engine {
|
||||
used = document.top_skip.max(paragraph.height);
|
||||
insertion_height = 0;
|
||||
} else {
|
||||
used += paragraph.height;
|
||||
if par_skip > 0 {
|
||||
current.items.push(VerticalItem::Glue(par_skip));
|
||||
}
|
||||
used += par_skip + paragraph.height;
|
||||
}
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
@@ -1520,9 +1532,14 @@ impl Engine {
|
||||
used = next.top_skip;
|
||||
insertion_height = 0;
|
||||
}
|
||||
let par_skip = if current.items.is_empty() {
|
||||
0
|
||||
} else {
|
||||
next.par_skip.max(0)
|
||||
};
|
||||
if current.items.is_empty() && !page_has_top_float_material(¤t) {
|
||||
used = next.top_skip.max(paragraph.height);
|
||||
} else if used + paragraph.height
|
||||
} else if used + par_skip + paragraph.height
|
||||
> next.page_goal
|
||||
- insertion_height
|
||||
- bottom_float_area(¤t, next.text_float_sep)
|
||||
@@ -1531,7 +1548,10 @@ impl Engine {
|
||||
used = next.top_skip.max(paragraph.height);
|
||||
insertion_height = 0;
|
||||
} else {
|
||||
used += paragraph.height;
|
||||
if par_skip > 0 {
|
||||
current.items.push(VerticalItem::Glue(par_skip));
|
||||
}
|
||||
used += par_skip + paragraph.height;
|
||||
}
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
@@ -3602,6 +3622,21 @@ mod tests {
|
||||
assert!(svg.contains("<rect"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_skip_separates_paragraph_units() {
|
||||
let mut document = Document::new(
|
||||
1,
|
||||
vec![Unit::paragraph(1, "alpha"), Unit::paragraph(2, "beta")],
|
||||
);
|
||||
let first = item_height(&document.units[0].items[0]);
|
||||
let second = item_height(&document.units[1].items[0]);
|
||||
document.par_skip = 10;
|
||||
document.page_goal = first + second + 10;
|
||||
assert_eq!(Engine::layout(&document).pages().len(), 1);
|
||||
document.page_goal = first + second + 9;
|
||||
assert_eq!(Engine::layout(&document).pages().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn floatsep_separates_stacked_top_floats() {
|
||||
let mut document = Document::new(
|
||||
|
||||
Reference in new issue
Block a user