Reserve space for bottom floats
This commit is contained in:
1 parent
d973b2d1a0
commit
336ca510c8
2 files changed
+82
-8
No files matched your search
@@ -155,6 +155,22 @@ fn source_hash(source: &str) -> u64 {
|
|||||||
hasher.finish()
|
hasher.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn top_float_height(page: &Page) -> i64 {
|
||||||
|
page.floats
|
||||||
|
.iter()
|
||||||
|
.filter(|float| float.placement == FloatPlacement::Top)
|
||||||
|
.map(|float| float.height)
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bottom_float_height(page: &Page) -> i64 {
|
||||||
|
page.floats
|
||||||
|
.iter()
|
||||||
|
.filter(|float| float.placement == FloatPlacement::Bottom)
|
||||||
|
.map(|float| float.height)
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Checkpoint {
|
pub struct Checkpoint {
|
||||||
/// Index of the next unit to execute.
|
/// Index of the next unit to execute.
|
||||||
@@ -238,9 +254,10 @@ impl Engine {
|
|||||||
for item in &unit.items {
|
for item in &unit.items {
|
||||||
match item {
|
match item {
|
||||||
VerticalItem::Box(vertical_box) => {
|
VerticalItem::Box(vertical_box) => {
|
||||||
if current.items.is_empty() && current.floats.is_empty() {
|
if current.items.is_empty() && top_float_height(¤t) == 0 {
|
||||||
used = document.top_skip.max(vertical_box.height);
|
used = document.top_skip.max(vertical_box.height);
|
||||||
} else if used + vertical_box.height > document.page_goal - insertion_height
|
} else if used + vertical_box.height
|
||||||
|
> document.page_goal - insertion_height - bottom_float_height(¤t)
|
||||||
{
|
{
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = document.top_skip.max(vertical_box.height);
|
used = document.top_skip.max(vertical_box.height);
|
||||||
@@ -277,6 +294,7 @@ impl Engine {
|
|||||||
current.marks.push(mark.clone());
|
current.marks.push(mark.clone());
|
||||||
}
|
}
|
||||||
VerticalItem::Float(float) => {
|
VerticalItem::Float(float) => {
|
||||||
|
if float.placement == FloatPlacement::Top {
|
||||||
if !current.items.is_empty() || !current.insertions.is_empty() {
|
if !current.items.is_empty() || !current.insertions.is_empty() {
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = 0;
|
used = 0;
|
||||||
@@ -284,6 +302,19 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
used += float.height;
|
used += float.height;
|
||||||
current.floats.push(float.clone());
|
current.floats.push(float.clone());
|
||||||
|
} else if !current.items.is_empty()
|
||||||
|
&& used + float.height
|
||||||
|
<= document.page_goal
|
||||||
|
- insertion_height
|
||||||
|
- bottom_float_height(¤t)
|
||||||
|
{
|
||||||
|
current.floats.push(float.clone());
|
||||||
|
} else {
|
||||||
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
|
used = 0;
|
||||||
|
insertion_height = 0;
|
||||||
|
current.floats.push(float.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,9 +425,11 @@ impl Engine {
|
|||||||
for item in &unit.items {
|
for item in &unit.items {
|
||||||
match item {
|
match item {
|
||||||
VerticalItem::Box(vertical_box) => {
|
VerticalItem::Box(vertical_box) => {
|
||||||
if current.items.is_empty() && current.floats.is_empty() {
|
if current.items.is_empty() && top_float_height(¤t) == 0 {
|
||||||
used = next.top_skip.max(vertical_box.height);
|
used = next.top_skip.max(vertical_box.height);
|
||||||
} else if used + vertical_box.height > next.page_goal - insertion_height {
|
} else if used + vertical_box.height
|
||||||
|
> next.page_goal - insertion_height - bottom_float_height(¤t)
|
||||||
|
{
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = next.top_skip.max(vertical_box.height);
|
used = next.top_skip.max(vertical_box.height);
|
||||||
insertion_height = 0;
|
insertion_height = 0;
|
||||||
@@ -432,6 +465,7 @@ impl Engine {
|
|||||||
current.marks.push(mark.clone());
|
current.marks.push(mark.clone());
|
||||||
}
|
}
|
||||||
VerticalItem::Float(float) => {
|
VerticalItem::Float(float) => {
|
||||||
|
if float.placement == FloatPlacement::Top {
|
||||||
if !current.items.is_empty() || !current.insertions.is_empty() {
|
if !current.items.is_empty() || !current.insertions.is_empty() {
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = 0;
|
used = 0;
|
||||||
@@ -439,6 +473,17 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
used += float.height;
|
used += float.height;
|
||||||
current.floats.push(float.clone());
|
current.floats.push(float.clone());
|
||||||
|
} else if !current.items.is_empty()
|
||||||
|
&& used + float.height
|
||||||
|
<= next.page_goal - insertion_height - bottom_float_height(¤t)
|
||||||
|
{
|
||||||
|
current.floats.push(float.clone());
|
||||||
|
} else {
|
||||||
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
|
used = 0;
|
||||||
|
insertion_height = 0;
|
||||||
|
current.floats.push(float.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,6 +732,34 @@ mod tests {
|
|||||||
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bottom_float_reserves_space_on_its_page() {
|
||||||
|
let unit = Unit {
|
||||||
|
id: 0,
|
||||||
|
source: "bottom float".to_owned(),
|
||||||
|
items: vec![
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 10,
|
||||||
|
height: 30,
|
||||||
|
}),
|
||||||
|
VerticalItem::Float(Float {
|
||||||
|
placement: FloatPlacement::Bottom,
|
||||||
|
width: 40,
|
||||||
|
height: 30,
|
||||||
|
}),
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 10,
|
||||||
|
height: 30,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
let engine = Engine::layout(&Document::new(60, vec![unit]));
|
||||||
|
assert_eq!(engine.layout.pages.len(), 2);
|
||||||
|
assert_eq!(engine.layout.pages[0].floats.len(), 1);
|
||||||
|
assert_eq!(engine.layout.pages[0].items.len(), 1);
|
||||||
|
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checkpoint_round_trips_through_serde() {
|
fn checkpoint_round_trips_through_serde() {
|
||||||
let engine = Engine::layout(&document());
|
let engine = Engine::layout(&document());
|
||||||
|
|||||||
+5
-4
@@ -71,7 +71,7 @@ next paragraph milestones.
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
|
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
|
||||||
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, pdfTeX fixture and minimum line fill; hyphenation next |
|
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, pdfTeX fixture and minimum line fill; hyphenation next |
|
||||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top `Float` queue; interpreted `\output`, bottom floats next |
|
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; interpreted `\output`, float pages next |
|
||||||
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
|
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
|
||||||
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap |
|
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap |
|
||||||
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
|
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
|
||||||
@@ -108,9 +108,10 @@ a single cost function.
|
|||||||
`VerticalItem::Mark` material is collected into `Page::marks` and included
|
`VerticalItem::Mark` material is collected into `Page::marks` and included
|
||||||
in the page hash. `OutputRoutine::shipout` runs before sealing and may
|
in the page hash. `OutputRoutine::shipout` runs before sealing and may
|
||||||
mutate each page; this models the `\output` stage in Rust rather than as
|
mutate each page; this models the `\output` stage in Rust rather than as
|
||||||
an interpreted token list, and cannot yet change page goals. `Float`
|
an interpreted token list, and cannot yet change page goals. Top `Float`
|
||||||
material is deferred to the top of the next page when it arrives late;
|
material is deferred to the next page when it arrives late; bottom
|
||||||
bottom placement and float-page policies are not implemented yet.
|
floats reserve height on the current page. Dedicated float pages and
|
||||||
|
`\textfraction`-style policies are not implemented yet.
|
||||||
- No macro state, output routine, math, fonts or PDF output in the new core yet.
|
- No macro state, output routine, math, fonts or PDF output in the new core yet.
|
||||||
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
|
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user